From 33879963bc97c5d094afdd450584ec1a9648a7de Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 7 Jul 2023 18:50:22 +0000 Subject: [PATCH 1/2] Bump yaml from 2.2.1 to 2.3.1 Bumps [yaml](https://github.com/eemeli/yaml) from 2.2.1 to 2.3.1. - [Release notes](https://github.com/eemeli/yaml/releases) - [Commits](https://github.com/eemeli/yaml/compare/v2.2.1...v2.3.1) --- updated-dependencies: - dependency-name: yaml dependency-type: direct:development update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- package-lock.json | 14 +++++++------- package.json | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/package-lock.json b/package-lock.json index e63b548d..01ed2504 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.9.5", - "yaml": "^2.2.1", + "yaml": "^2.3.1", "yargs": "^17.7.2" }, "engines": { @@ -8783,9 +8783,9 @@ "dev": true }, "node_modules/yaml": { - "version": "2.2.1", - "resolved": "https://registry.npmjs.org/yaml/-/yaml-2.2.1.tgz", - "integrity": "sha512-e0WHiYql7+9wr4cWMx3TVQrNwejKaEe7/rHNmQmqRjazfOP5W8PB6Jpebb5o6fIapbz9o9+2ipcaTM2ZwDI6lw==", + "version": "2.3.1", + "resolved": "https://registry.npmjs.org/yaml/-/yaml-2.3.1.tgz", + "integrity": "sha512-2eHWfjaoXgTBC2jNM1LRef62VQa0umtvRiDSk6HSzW7RvS5YtkabJrwYLLEKWBc8a5U2PTSCs+dJjUTJdlHsWQ==", "dev": true, "engines": { "node": ">= 14" @@ -15613,9 +15613,9 @@ "dev": true }, "yaml": { - "version": "2.2.1", - "resolved": "https://registry.npmjs.org/yaml/-/yaml-2.2.1.tgz", - "integrity": "sha512-e0WHiYql7+9wr4cWMx3TVQrNwejKaEe7/rHNmQmqRjazfOP5W8PB6Jpebb5o6fIapbz9o9+2ipcaTM2ZwDI6lw==", + "version": "2.3.1", + "resolved": "https://registry.npmjs.org/yaml/-/yaml-2.3.1.tgz", + "integrity": "sha512-2eHWfjaoXgTBC2jNM1LRef62VQa0umtvRiDSk6HSzW7RvS5YtkabJrwYLLEKWBc8a5U2PTSCs+dJjUTJdlHsWQ==", "dev": true }, "yargs": { diff --git a/package.json b/package.json index 46fa68b5..f4428353 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,7 @@ "ts-jest": "^26.5.6", "ts-node": "^10.9.1", "typescript": "^4.9.5", - "yaml": "^2.2.1", + "yaml": "^2.3.1", "yargs": "^17.7.2" } } From a5c13b47b4530d0f8538cdc8794d96c890c19d54 Mon Sep 17 00:00:00 2001 From: Bryan Dragon <25506+bdragon@users.noreply.github.com> Date: Fri, 7 Jul 2023 14:25:34 -0600 Subject: [PATCH 2/2] Rebuild dist/ --- dist/index.js | 741 ++++++++++++++++++++++++++++---------------------- 1 file changed, 412 insertions(+), 329 deletions(-) diff --git a/dist/index.js b/dist/index.js index 5f93d612..0d894d51 100644 --- a/dist/index.js +++ b/dist/index.js @@ -10546,41 +10546,53 @@ module.exports = require("zlib"); "use strict"; -var Node = __nccwpck_require__(1399); +var identity = __nccwpck_require__(5589); var Scalar = __nccwpck_require__(9338); +var YAMLMap = __nccwpck_require__(6011); +var YAMLSeq = __nccwpck_require__(5161); var resolveBlockMap = __nccwpck_require__(2986); var resolveBlockSeq = __nccwpck_require__(2289); var resolveFlowCollection = __nccwpck_require__(45); -function composeCollection(CN, ctx, token, tagToken, onError) { - let coll; - switch (token.type) { - case 'block-map': { - coll = resolveBlockMap.resolveBlockMap(CN, ctx, token, onError); - break; - } - case 'block-seq': { - coll = resolveBlockSeq.resolveBlockSeq(CN, ctx, token, onError); - break; - } - case 'flow-collection': { - coll = resolveFlowCollection.resolveFlowCollection(CN, ctx, token, onError); - break; - } - } - if (!tagToken) - return coll; - const tagName = ctx.directives.tagName(tagToken.source, msg => onError(tagToken, 'TAG_RESOLVE_FAILED', msg)); - if (!tagName) - return coll; - // Cast needed due to: https://github.com/Microsoft/TypeScript/issues/3841 +function resolveCollection(CN, ctx, token, onError, tagName, tag) { + const coll = token.type === 'block-map' + ? resolveBlockMap.resolveBlockMap(CN, ctx, token, onError, tag) + : token.type === 'block-seq' + ? resolveBlockSeq.resolveBlockSeq(CN, ctx, token, onError, tag) + : resolveFlowCollection.resolveFlowCollection(CN, ctx, token, onError, tag); const Coll = coll.constructor; + // If we got a tagName matching the class, or the tag name is '!', + // then use the tagName from the node class used to create it. if (tagName === '!' || tagName === Coll.tagName) { coll.tag = Coll.tagName; return coll; } - const expType = Node.isMap(coll) ? 'map' : 'seq'; - let tag = ctx.schema.tags.find(t => t.collection === expType && t.tag === tagName); + if (tagName) + coll.tag = tagName; + return coll; +} +function composeCollection(CN, ctx, token, tagToken, onError) { + const tagName = !tagToken + ? null + : ctx.directives.tagName(tagToken.source, msg => onError(tagToken, 'TAG_RESOLVE_FAILED', msg)); + const expType = token.type === 'block-map' + ? 'map' + : token.type === 'block-seq' + ? 'seq' + : token.start.source === '{' + ? 'map' + : 'seq'; + // shortcut: check if it's a generic YAMLMap or YAMLSeq + // before jumping into the custom tag logic. + if (!tagToken || + !tagName || + tagName === '!' || + (tagName === YAMLMap.YAMLMap.tagName && expType === 'map') || + (tagName === YAMLSeq.YAMLSeq.tagName && expType === 'seq') || + !expType) { + return resolveCollection(CN, ctx, token, onError, tagName); + } + 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) { @@ -10588,13 +10600,18 @@ function composeCollection(CN, ctx, token, tagToken, onError) { tag = kt; } else { - onError(tagToken, 'TAG_RESOLVE_FAILED', `Unresolved tag: ${tagName}`, true); - coll.tag = tagName; - return coll; + if (kt?.collection) { + onError(tagToken, 'BAD_COLLECTION_TYPE', `${kt.tag} used for ${expType} collection, but expects ${kt.collection}`, true); + } + else { + onError(tagToken, 'TAG_RESOLVE_FAILED', `Unresolved tag: ${tagName}`, true); + } + return resolveCollection(CN, ctx, token, onError, tagName); } } - const res = tag.resolve(coll, msg => onError(tagToken, 'TAG_RESOLVE_FAILED', msg), ctx.options); - const node = Node.isNode(res) + const coll = resolveCollection(CN, ctx, token, onError, tagName, tag); + const res = tag.resolve?.(coll, msg => onError(tagToken, 'TAG_RESOLVE_FAILED', msg), ctx.options) ?? coll; + const node = identity.isNode(res) ? res : new Scalar.Scalar(res); node.range = coll.range; @@ -10643,6 +10660,7 @@ function composeDoc(options, directives, { offset, start, value, end }, onError) !props.hasNewline) onError(props.end, 'MISSING_CHAR', 'Block collection cannot start on same line with directives-end marker'); } + // @ts-expect-error If Contents is set, let's trust the user doc.contents = value ? composeNode.composeNode(ctx, value, props, onError) : composeNode.composeEmptyNode(ctx, props.end, start, null, props, onError); @@ -10768,7 +10786,7 @@ exports.composeNode = composeNode; "use strict"; -var Node = __nccwpck_require__(1399); +var identity = __nccwpck_require__(5589); var Scalar = __nccwpck_require__(9338); var resolveBlockScalar = __nccwpck_require__(9485); var resolveFlowScalar = __nccwpck_require__(7578); @@ -10784,11 +10802,11 @@ function composeScalar(ctx, token, tagToken, onError) { ? findScalarTagByName(ctx.schema, value, tagName, tagToken, onError) : token.type === 'scalar' ? findScalarTagByTest(ctx, value, token, onError) - : ctx.schema[Node.SCALAR]; + : ctx.schema[identity.SCALAR]; let scalar; try { const res = tag.resolve(value, msg => onError(tagToken ?? token, 'TAG_RESOLVE_FAILED', msg), ctx.options); - scalar = Node.isScalar(res) ? res : new Scalar.Scalar(res); + scalar = identity.isScalar(res) ? res : new Scalar.Scalar(res); } catch (error) { const msg = error instanceof Error ? error.message : String(error); @@ -10809,7 +10827,7 @@ function composeScalar(ctx, token, tagToken, onError) { } function findScalarTagByName(schema, value, tagName, tagToken, onError) { if (tagName === '!') - return schema[Node.SCALAR]; // non-specific tag + return schema[identity.SCALAR]; // non-specific tag const matchWithTest = []; for (const tag of schema.tags) { if (!tag.collection && tag.tag === tagName) { @@ -10830,13 +10848,13 @@ function findScalarTagByName(schema, value, tagName, tagToken, onError) { return kt; } onError(tagToken, 'TAG_RESOLVE_FAILED', `Unresolved tag: ${tagName}`, tagName !== 'tag:yaml.org,2002:str'); - return schema[Node.SCALAR]; + return schema[identity.SCALAR]; } function findScalarTagByTest({ directives, schema }, value, token, onError) { - const tag = schema.tags.find(tag => tag.default && tag.test?.test(value)) || schema[Node.SCALAR]; + const tag = schema.tags.find(tag => tag.default && tag.test?.test(value)) || schema[identity.SCALAR]; if (schema.compat) { const compat = schema.compat.find(tag => tag.default && tag.test?.test(value)) ?? - schema[Node.SCALAR]; + schema[identity.SCALAR]; if (tag.tag !== compat.tag) { const ts = directives.tagString(tag.tag); const cs = directives.tagString(compat.tag); @@ -10861,7 +10879,7 @@ exports.composeScalar = composeScalar; var directives = __nccwpck_require__(5400); var Document = __nccwpck_require__(42); var errors = __nccwpck_require__(4236); -var Node = __nccwpck_require__(1399); +var identity = __nccwpck_require__(5589); var composeDoc = __nccwpck_require__(5050); var resolveEnd = __nccwpck_require__(1250); @@ -10941,9 +10959,9 @@ class Composer { else if (afterEmptyLine || doc.directives.docStart || !dc) { doc.commentBefore = comment; } - else if (Node.isCollection(dc) && !dc.flow && dc.items.length > 0) { + else if (identity.isCollection(dc) && !dc.flow && dc.items.length > 0) { let it = dc.items[0]; - if (Node.isPair(it)) + if (identity.isPair(it)) it = it.key; const cb = it.commentBefore; it.commentBefore = cb ? `${comment}\n${cb}` : comment; @@ -11095,8 +11113,9 @@ var utilFlowIndentCheck = __nccwpck_require__(3669); var utilMapIncludes = __nccwpck_require__(6899); const startColMsg = 'All mapping items must start at the same column'; -function resolveBlockMap({ composeNode, composeEmptyNode }, ctx, bm, onError) { - const map = new YAMLMap.YAMLMap(ctx.schema); +function resolveBlockMap({ composeNode, composeEmptyNode }, ctx, bm, onError, tag) { + const NodeClass = tag?.nodeClass ?? YAMLMap.YAMLMap; + const map = new NodeClass(ctx.schema); if (ctx.atRoot) ctx.atRoot = false; let offset = bm.offset; @@ -11415,8 +11434,9 @@ var YAMLSeq = __nccwpck_require__(5161); var resolveProps = __nccwpck_require__(6985); var utilFlowIndentCheck = __nccwpck_require__(3669); -function resolveBlockSeq({ composeNode, composeEmptyNode }, ctx, bs, onError) { - const seq = new YAMLSeq.YAMLSeq(ctx.schema); +function resolveBlockSeq({ composeNode, composeEmptyNode }, ctx, bs, onError, tag) { + const NodeClass = tag?.nodeClass ?? YAMLSeq.YAMLSeq; + const seq = new NodeClass(ctx.schema); if (ctx.atRoot) ctx.atRoot = false; let offset = bs.offset; @@ -11513,7 +11533,7 @@ exports.resolveEnd = resolveEnd; "use strict"; -var Node = __nccwpck_require__(1399); +var identity = __nccwpck_require__(5589); var Pair = __nccwpck_require__(246); var YAMLMap = __nccwpck_require__(6011); var YAMLSeq = __nccwpck_require__(5161); @@ -11524,12 +11544,11 @@ var utilMapIncludes = __nccwpck_require__(6899); const blockMsg = 'Block collections are not allowed within flow collections'; const isBlock = (token) => token && (token.type === 'block-map' || token.type === 'block-seq'); -function resolveFlowCollection({ composeNode, composeEmptyNode }, ctx, fc, onError) { +function resolveFlowCollection({ composeNode, composeEmptyNode }, ctx, fc, onError, tag) { const isMap = fc.start.source === '{'; const fcName = isMap ? 'flow map' : 'flow sequence'; - const coll = isMap - ? new YAMLMap.YAMLMap(ctx.schema) - : new YAMLSeq.YAMLSeq(ctx.schema); + const NodeClass = (tag?.nodeClass ?? (isMap ? YAMLMap.YAMLMap : YAMLSeq.YAMLSeq)); + const coll = new NodeClass(ctx.schema); coll.flow = true; const atRoot = ctx.atRoot; if (atRoot) @@ -11588,7 +11607,7 @@ function resolveFlowCollection({ composeNode, composeEmptyNode }, ctx, fc, onErr } if (prevItemComment) { let prev = coll.items[coll.items.length - 1]; - if (Node.isPair(prev)) + if (identity.isPair(prev)) prev = prev.value ?? prev.key; if (prev.comment) prev.comment += '\n' + prevItemComment; @@ -12206,7 +12225,7 @@ exports.flowIndentCheck = flowIndentCheck; "use strict"; -var Node = __nccwpck_require__(1399); +var identity = __nccwpck_require__(5589); function mapIncludes(ctx, items, search) { const { uniqueKeys } = ctx.options; @@ -12215,8 +12234,8 @@ function mapIncludes(ctx, items, search) { const isEqual = typeof uniqueKeys === 'function' ? uniqueKeys : (a, b) => a === b || - (Node.isScalar(a) && - Node.isScalar(b) && + (identity.isScalar(a) && + identity.isScalar(b) && a.value === b.value && !(a.value === '<<' && ctx.schema.merge)); return items.some(pair => isEqual(pair.key, search)); @@ -12235,11 +12254,10 @@ exports.mapIncludes = mapIncludes; var Alias = __nccwpck_require__(5639); var Collection = __nccwpck_require__(3466); -var Node = __nccwpck_require__(1399); +var identity = __nccwpck_require__(5589); var Pair = __nccwpck_require__(246); var toJS = __nccwpck_require__(2463); var Schema = __nccwpck_require__(6831); -var stringify = __nccwpck_require__(8409); var stringifyDocument = __nccwpck_require__(5225); var anchors = __nccwpck_require__(8459); var applyReviver = __nccwpck_require__(3412); @@ -12256,7 +12274,7 @@ class Document { this.errors = []; /** Warnings encountered during parsing. */ this.warnings = []; - Object.defineProperty(this, Node.NODE_TYPE, { value: Node.DOC }); + Object.defineProperty(this, identity.NODE_TYPE, { value: identity.DOC }); let _replacer = null; if (typeof replacer === 'function' || Array.isArray(replacer)) { _replacer = replacer; @@ -12284,11 +12302,9 @@ class Document { else this.directives = new directives.Directives({ version }); this.setSchema(version, options); - if (value === undefined) - this.contents = null; - else { - this.contents = this.createNode(value, _replacer, options); - } + // @ts-expect-error We can't really know that this matches Contents. + this.contents = + value === undefined ? null : this.createNode(value, _replacer, options); } /** * Create a deep copy of this Document and its contents. @@ -12297,7 +12313,7 @@ class Document { */ clone() { const copy = Object.create(Document.prototype, { - [Node.NODE_TYPE]: { value: Node.DOC } + [identity.NODE_TYPE]: { value: identity.DOC } }); copy.commentBefore = this.commentBefore; copy.comment = this.comment; @@ -12307,7 +12323,8 @@ class Document { if (this.directives) copy.directives = this.directives.clone(); copy.schema = this.schema.clone(); - copy.contents = Node.isNode(this.contents) + // @ts-expect-error We can't really know that this matches Contents. + copy.contents = identity.isNode(this.contents) ? this.contents.clone(copy.schema) : this.contents; if (this.range) @@ -12373,7 +12390,7 @@ class Document { sourceObjects }; const node = createNode.createNode(value, tag, ctx); - if (flow && Node.isCollection(node)) + if (flow && identity.isCollection(node)) node.flow = true; setAnchors(); return node; @@ -12402,6 +12419,7 @@ class Document { if (Collection.isEmptyPath(path)) { if (this.contents == null) return false; + // @ts-expect-error Presumed impossible if Strict extends false this.contents = null; return true; } @@ -12415,7 +12433,7 @@ class Document { * `true` (collections are always returned intact). */ get(key, keepScalar) { - return Node.isCollection(this.contents) + return identity.isCollection(this.contents) ? this.contents.get(key, keepScalar) : undefined; } @@ -12426,10 +12444,10 @@ class Document { */ getIn(path, keepScalar) { if (Collection.isEmptyPath(path)) - return !keepScalar && Node.isScalar(this.contents) + return !keepScalar && identity.isScalar(this.contents) ? this.contents.value : this.contents; - return Node.isCollection(this.contents) + return identity.isCollection(this.contents) ? this.contents.getIn(path, keepScalar) : undefined; } @@ -12437,7 +12455,7 @@ class Document { * Checks if the document includes a value with the key `key`. */ has(key) { - return Node.isCollection(this.contents) ? this.contents.has(key) : false; + return identity.isCollection(this.contents) ? this.contents.has(key) : false; } /** * Checks if the document includes a value at `path`. @@ -12445,7 +12463,7 @@ class Document { hasIn(path) { if (Collection.isEmptyPath(path)) return this.contents !== undefined; - return Node.isCollection(this.contents) ? this.contents.hasIn(path) : false; + return identity.isCollection(this.contents) ? this.contents.hasIn(path) : false; } /** * Sets a value in this document. For `!!set`, `value` needs to be a @@ -12453,6 +12471,7 @@ class Document { */ set(key, value) { if (this.contents == null) { + // @ts-expect-error We can't really know that this matches Contents. this.contents = Collection.collectionFromPath(this.schema, [key], value); } else if (assertCollection(this.contents)) { @@ -12464,9 +12483,12 @@ class Document { * boolean to add/remove the item from the set. */ setIn(path, value) { - if (Collection.isEmptyPath(path)) + if (Collection.isEmptyPath(path)) { + // @ts-expect-error We can't really know that this matches Contents. this.contents = value; + } else if (this.contents == null) { + // @ts-expect-error We can't really know that this matches Contents. this.contents = Collection.collectionFromPath(this.schema, Array.from(path), value); } else if (assertCollection(this.contents)) { @@ -12526,8 +12548,7 @@ class Document { keep: !json, mapAsMap: mapAsMap === true, mapKeyWarned: false, - maxAliasCount: typeof maxAliasCount === 'number' ? maxAliasCount : 100, - stringify: stringify.stringify + maxAliasCount: typeof maxAliasCount === 'number' ? maxAliasCount : 100 }; const res = toJS.toJS(this.contents, jsonArg ?? '', ctx); if (typeof onAnchor === 'function') @@ -12559,7 +12580,7 @@ class Document { } } function assertCollection(contents) { - if (Node.isCollection(contents)) + if (identity.isCollection(contents)) return true; throw new Error('Expected a YAML collection as document contents'); } @@ -12575,7 +12596,7 @@ exports.Document = Document; "use strict"; -var Node = __nccwpck_require__(1399); +var identity = __nccwpck_require__(5589); var visit = __nccwpck_require__(6796); /** @@ -12632,7 +12653,7 @@ function createNodeAnchors(doc, prefix) { const ref = sourceObjects.get(source); if (typeof ref === 'object' && ref.anchor && - (Node.isScalar(ref.node) || Node.isCollection(ref.node))) { + (identity.isScalar(ref.node) || identity.isCollection(ref.node))) { ref.node.anchor = ref.anchor; } else { @@ -12725,7 +12746,7 @@ exports.applyReviver = applyReviver; var Alias = __nccwpck_require__(5639); -var Node = __nccwpck_require__(1399); +var identity = __nccwpck_require__(5589); var Scalar = __nccwpck_require__(9338); const defaultTagPrefix = 'tag:yaml.org,2002:'; @@ -12740,12 +12761,12 @@ function findTagObject(value, tagName, tags) { return tags.find(t => t.identify?.(value) && !t.format); } function createNode(value, tagName, ctx) { - if (Node.isDocument(value)) + if (identity.isDocument(value)) value = value.contents; - if (Node.isNode(value)) + if (identity.isNode(value)) return value; - if (Node.isPair(value)) { - const map = ctx.schema[Node.MAP].createNode?.(ctx.schema, null, ctx); + if (identity.isPair(value)) { + const map = ctx.schema[identity.MAP].createNode?.(ctx.schema, null, ctx); map.items.push(value); return map; } @@ -12789,10 +12810,10 @@ function createNode(value, tagName, ctx) { } tagObj = value instanceof Map - ? schema[Node.MAP] + ? schema[identity.MAP] : Symbol.iterator in Object(value) - ? schema[Node.SEQ] - : schema[Node.MAP]; + ? schema[identity.SEQ] + : schema[identity.MAP]; } if (onTagObj) { onTagObj(tagObj); @@ -12800,9 +12821,13 @@ function createNode(value, tagName, ctx) { } const node = tagObj?.createNode ? tagObj.createNode(ctx.schema, value, ctx) - : new Scalar.Scalar(value); + : typeof tagObj?.nodeClass?.from === 'function' + ? tagObj.nodeClass.from(ctx.schema, value, ctx) + : new Scalar.Scalar(value); if (tagName) node.tag = tagName; + else if (!tagObj.default) + node.tag = tagObj.tag; if (ref) ref.node = node; return node; @@ -12819,7 +12844,7 @@ exports.createNode = createNode; "use strict"; -var Node = __nccwpck_require__(1399); +var identity = __nccwpck_require__(5589); var visit = __nccwpck_require__(6796); const escapeChars = { @@ -12965,10 +12990,10 @@ class Directives { : []; const tagEntries = Object.entries(this.tags); let tagNames; - if (doc && tagEntries.length > 0 && Node.isNode(doc.contents)) { + if (doc && tagEntries.length > 0 && identity.isNode(doc.contents)) { const tags = {}; visit.visit(doc.contents, (_key, node) => { - if (Node.isNode(node) && node.tag) + if (identity.isNode(node) && node.tag) tags[node.tag] = true; }); tagNames = Object.keys(tags); @@ -13047,7 +13072,7 @@ const prettifyError = (src, lc) => (error) => { let count = 1; const end = error.linePos[1]; if (end && end.line === line && end.col > col) { - count = Math.min(end.col - col, 80 - ci); + count = Math.max(1, Math.min(end.col - col, 80 - ci)); } const pointer = ' '.repeat(ci) + '^'.repeat(count); error.message += `:\n\n${lineStr}\n${pointer}\n`; @@ -13073,7 +13098,7 @@ var Document = __nccwpck_require__(42); var Schema = __nccwpck_require__(6831); var errors = __nccwpck_require__(4236); var Alias = __nccwpck_require__(5639); -var Node = __nccwpck_require__(1399); +var identity = __nccwpck_require__(5589); var Pair = __nccwpck_require__(246); var Scalar = __nccwpck_require__(9338); var YAMLMap = __nccwpck_require__(6011); @@ -13094,14 +13119,14 @@ exports.YAMLError = errors.YAMLError; exports.YAMLParseError = errors.YAMLParseError; exports.YAMLWarning = errors.YAMLWarning; exports.Alias = Alias.Alias; -exports.isAlias = Node.isAlias; -exports.isCollection = Node.isCollection; -exports.isDocument = Node.isDocument; -exports.isMap = Node.isMap; -exports.isNode = Node.isNode; -exports.isPair = Node.isPair; -exports.isScalar = Node.isScalar; -exports.isSeq = Node.isSeq; +exports.isAlias = identity.isAlias; +exports.isCollection = identity.isCollection; +exports.isDocument = identity.isDocument; +exports.isMap = identity.isMap; +exports.isNode = identity.isNode; +exports.isPair = identity.isPair; +exports.isScalar = identity.isScalar; +exports.isSeq = identity.isSeq; exports.Pair = Pair.Pair; exports.Scalar = Scalar.Scalar; exports.YAMLMap = YAMLMap.YAMLMap; @@ -13153,11 +13178,13 @@ exports.warn = warn; var anchors = __nccwpck_require__(8459); var visit = __nccwpck_require__(6796); +var identity = __nccwpck_require__(5589); var Node = __nccwpck_require__(1399); +var toJS = __nccwpck_require__(2463); class Alias extends Node.NodeBase { constructor(source) { - super(Node.ALIAS); + super(identity.ALIAS); this.source = source; Object.defineProperty(this, 'tag', { set() { @@ -13190,7 +13217,12 @@ class Alias extends Node.NodeBase { const msg = `Unresolved alias (the anchor must be set before the alias): ${this.source}`; throw new ReferenceError(msg); } - const data = anchors.get(source); + let data = anchors.get(source); + if (!data) { + // Resolve anchors for Node.prototype.toJS() + toJS.toJS(source, null, ctx); + data = anchors.get(source); + } /* istanbul ignore if */ if (!data || data.res === undefined) { const msg = 'This should not happen: Alias anchor was not resolved?'; @@ -13222,12 +13254,12 @@ class Alias extends Node.NodeBase { } } function getAliasCount(doc, node, anchors) { - if (Node.isAlias(node)) { + if (identity.isAlias(node)) { const source = node.resolve(doc); const anchor = anchors && source && anchors.get(source); return anchor ? anchor.count * anchor.aliasCount : 0; } - else if (Node.isCollection(node)) { + else if (identity.isCollection(node)) { let count = 0; for (const item of node.items) { const c = getAliasCount(doc, item, anchors); @@ -13236,7 +13268,7 @@ function getAliasCount(doc, node, anchors) { } return count; } - else if (Node.isPair(node)) { + else if (identity.isPair(node)) { const kc = getAliasCount(doc, node.key, anchors); const vc = getAliasCount(doc, node.value, anchors); return Math.max(kc, vc); @@ -13256,6 +13288,7 @@ exports.Alias = Alias; var createNode = __nccwpck_require__(9652); +var identity = __nccwpck_require__(5589); var Node = __nccwpck_require__(1399); function collectionFromPath(schema, path, value) { @@ -13304,7 +13337,7 @@ class Collection extends Node.NodeBase { const copy = Object.create(Object.getPrototypeOf(this), Object.getOwnPropertyDescriptors(this)); if (schema) copy.schema = schema; - copy.items = copy.items.map(it => Node.isNode(it) || Node.isPair(it) ? it.clone(schema) : it); + copy.items = copy.items.map(it => identity.isNode(it) || identity.isPair(it) ? it.clone(schema) : it); if (this.range) copy.range = this.range.slice(); return copy; @@ -13320,7 +13353,7 @@ class Collection extends Node.NodeBase { else { const [key, ...rest] = path; const node = this.get(key, true); - if (Node.isCollection(node)) + if (identity.isCollection(node)) node.addIn(rest, value); else if (node === undefined && this.schema) this.set(key, collectionFromPath(this.schema, rest, value)); @@ -13337,7 +13370,7 @@ class Collection extends Node.NodeBase { if (rest.length === 0) return this.delete(key); const node = this.get(key, true); - if (Node.isCollection(node)) + if (identity.isCollection(node)) return node.deleteIn(rest); else throw new Error(`Expected YAML collection at ${key}. Remaining path: ${rest}`); @@ -13351,18 +13384,18 @@ class Collection extends Node.NodeBase { const [key, ...rest] = path; const node = this.get(key, true); if (rest.length === 0) - return !keepScalar && Node.isScalar(node) ? node.value : node; + return !keepScalar && identity.isScalar(node) ? node.value : node; else - return Node.isCollection(node) ? node.getIn(rest, keepScalar) : undefined; + return identity.isCollection(node) ? node.getIn(rest, keepScalar) : undefined; } hasAllNullValues(allowScalar) { return this.items.every(node => { - if (!Node.isPair(node)) + if (!identity.isPair(node)) return false; const n = node.value; return (n == null || (allowScalar && - Node.isScalar(n) && + identity.isScalar(n) && n.value == null && !n.commentBefore && !n.comment && @@ -13377,7 +13410,7 @@ class Collection extends Node.NodeBase { if (rest.length === 0) return this.has(key); const node = this.get(key, true); - return Node.isCollection(node) ? node.hasIn(rest) : false; + return identity.isCollection(node) ? node.hasIn(rest) : false; } /** * Sets a value in this collection. For `!!set`, `value` needs to be a @@ -13390,7 +13423,7 @@ class Collection extends Node.NodeBase { } else { const node = this.get(key, true); - if (Node.isCollection(node)) + if (identity.isCollection(node)) node.setIn(rest, value); else if (node === undefined && this.schema) this.set(key, collectionFromPath(this.schema, rest, value)); @@ -13409,48 +13442,18 @@ exports.isEmptyPath = isEmptyPath; /***/ }), /***/ 1399: -/***/ ((__unused_webpack_module, exports) => { +/***/ ((__unused_webpack_module, exports, __nccwpck_require__) => { "use strict"; -const ALIAS = Symbol.for('yaml.alias'); -const DOC = Symbol.for('yaml.document'); -const MAP = Symbol.for('yaml.map'); -const PAIR = Symbol.for('yaml.pair'); -const SCALAR = Symbol.for('yaml.scalar'); -const SEQ = Symbol.for('yaml.seq'); -const NODE_TYPE = Symbol.for('yaml.node.type'); -const isAlias = (node) => !!node && typeof node === 'object' && node[NODE_TYPE] === ALIAS; -const isDocument = (node) => !!node && typeof node === 'object' && node[NODE_TYPE] === DOC; -const isMap = (node) => !!node && typeof node === 'object' && node[NODE_TYPE] === MAP; -const isPair = (node) => !!node && typeof node === 'object' && node[NODE_TYPE] === PAIR; -const isScalar = (node) => !!node && typeof node === 'object' && node[NODE_TYPE] === SCALAR; -const isSeq = (node) => !!node && typeof node === 'object' && node[NODE_TYPE] === SEQ; -function isCollection(node) { - if (node && typeof node === 'object') - switch (node[NODE_TYPE]) { - case MAP: - case SEQ: - return true; - } - return false; -} -function isNode(node) { - if (node && typeof node === 'object') - switch (node[NODE_TYPE]) { - case ALIAS: - case MAP: - case SCALAR: - case SEQ: - return true; - } - return false; -} -const hasAnchor = (node) => (isScalar(node) || isCollection(node)) && !!node.anchor; +var applyReviver = __nccwpck_require__(3412); +var identity = __nccwpck_require__(5589); +var toJS = __nccwpck_require__(2463); + class NodeBase { constructor(type) { - Object.defineProperty(this, NODE_TYPE, { value: type }); + Object.defineProperty(this, identity.NODE_TYPE, { value: type }); } /** Create a copy of this node. */ clone() { @@ -13459,25 +13462,29 @@ class NodeBase { copy.range = this.range.slice(); return copy; } + /** A plain JavaScript representation of this node. */ + toJS(doc, { mapAsMap, maxAliasCount, onAnchor, reviver } = {}) { + if (!identity.isDocument(doc)) + throw new TypeError('A document argument is required'); + const ctx = { + anchors: new Map(), + doc, + keep: true, + mapAsMap: mapAsMap === true, + mapKeyWarned: false, + maxAliasCount: typeof maxAliasCount === 'number' ? maxAliasCount : 100 + }; + const res = toJS.toJS(this, '', ctx); + if (typeof onAnchor === 'function') + for (const { count, res } of ctx.anchors.values()) + onAnchor(res, count); + return typeof reviver === 'function' + ? applyReviver.applyReviver(reviver, { '': res }, '', res) + : res; + } } -exports.ALIAS = ALIAS; -exports.DOC = DOC; -exports.MAP = MAP; -exports.NODE_TYPE = NODE_TYPE; exports.NodeBase = NodeBase; -exports.PAIR = PAIR; -exports.SCALAR = SCALAR; -exports.SEQ = SEQ; -exports.hasAnchor = hasAnchor; -exports.isAlias = isAlias; -exports.isCollection = isCollection; -exports.isDocument = isDocument; -exports.isMap = isMap; -exports.isNode = isNode; -exports.isPair = isPair; -exports.isScalar = isScalar; -exports.isSeq = isSeq; /***/ }), @@ -13491,7 +13498,7 @@ exports.isSeq = isSeq; var createNode = __nccwpck_require__(9652); var stringifyPair = __nccwpck_require__(4875); var addPairToJSMap = __nccwpck_require__(4676); -var Node = __nccwpck_require__(1399); +var identity = __nccwpck_require__(5589); function createPair(key, value, ctx) { const k = createNode.createNode(key, undefined, ctx); @@ -13500,15 +13507,15 @@ function createPair(key, value, ctx) { } class Pair { constructor(key, value = null) { - Object.defineProperty(this, Node.NODE_TYPE, { value: Node.PAIR }); + Object.defineProperty(this, identity.NODE_TYPE, { value: identity.PAIR }); this.key = key; this.value = value; } clone(schema) { let { key, value } = this; - if (Node.isNode(key)) + if (identity.isNode(key)) key = key.clone(schema); - if (Node.isNode(value)) + if (identity.isNode(value)) value = value.clone(schema); return new Pair(key, value); } @@ -13535,13 +13542,14 @@ exports.createPair = createPair; "use strict"; +var identity = __nccwpck_require__(5589); var Node = __nccwpck_require__(1399); var toJS = __nccwpck_require__(2463); const isScalarValue = (value) => !value || (typeof value !== 'function' && typeof value !== 'object'); class Scalar extends Node.NodeBase { constructor(value) { - super(Node.SCALAR); + super(identity.SCALAR); this.value = value; } toJSON(arg, ctx) { @@ -13572,17 +13580,17 @@ exports.isScalarValue = isScalarValue; var stringifyCollection = __nccwpck_require__(2466); var addPairToJSMap = __nccwpck_require__(4676); var Collection = __nccwpck_require__(3466); -var Node = __nccwpck_require__(1399); +var identity = __nccwpck_require__(5589); var Pair = __nccwpck_require__(246); var Scalar = __nccwpck_require__(9338); function findPair(items, key) { - const k = Node.isScalar(key) ? key.value : key; + const k = identity.isScalar(key) ? key.value : key; for (const it of items) { - if (Node.isPair(it)) { + if (identity.isPair(it)) { if (it.key === key || it.key === k) return it; - if (Node.isScalar(it.key) && it.key.value === k) + if (identity.isScalar(it.key) && it.key.value === k) return it; } } @@ -13593,9 +13601,37 @@ class YAMLMap extends Collection.Collection { return 'tag:yaml.org,2002:map'; } constructor(schema) { - super(Node.MAP, schema); + super(identity.MAP, schema); this.items = []; } + /** + * A generic collection parsing method that can be extended + * to other node classes that inherit from YAMLMap + */ + static from(schema, obj, ctx) { + const { keepUndefined, replacer } = ctx; + const map = new this(schema); + const add = (key, value) => { + if (typeof replacer === 'function') + value = replacer.call(obj, key, value); + else if (Array.isArray(replacer) && !replacer.includes(key)) + return; + if (value !== undefined || keepUndefined) + map.items.push(Pair.createPair(key, value, ctx)); + }; + if (obj instanceof Map) { + for (const [key, value] of obj) + add(key, value); + } + else if (obj && typeof obj === 'object') { + for (const key of Object.keys(obj)) + add(key, obj[key]); + } + if (typeof schema.sortMapEntries === 'function') { + map.items.sort(schema.sortMapEntries); + } + return map; + } /** * Adds a value to the collection. * @@ -13604,7 +13640,7 @@ class YAMLMap extends Collection.Collection { */ add(pair, overwrite) { let _pair; - if (Node.isPair(pair)) + if (identity.isPair(pair)) _pair = pair; else if (!pair || typeof pair !== 'object' || !('key' in pair)) { // In TypeScript, this never happens. @@ -13618,7 +13654,7 @@ class YAMLMap extends Collection.Collection { if (!overwrite) throw new Error(`Key ${_pair.key} already set`); // For scalars, keep the old node & its comments and anchors - if (Node.isScalar(prev.value) && Scalar.isScalarValue(_pair.value)) + if (identity.isScalar(prev.value) && Scalar.isScalarValue(_pair.value)) prev.value.value = _pair.value; else prev.value = _pair.value; @@ -13644,7 +13680,7 @@ class YAMLMap extends Collection.Collection { get(key, keepScalar) { const it = findPair(this.items, key); const node = it?.value; - return (!keepScalar && Node.isScalar(node) ? node.value : node) ?? undefined; + return (!keepScalar && identity.isScalar(node) ? node.value : node) ?? undefined; } has(key) { return !!findPair(this.items, key); @@ -13669,7 +13705,7 @@ class YAMLMap extends Collection.Collection { if (!ctx) return JSON.stringify(this); for (const item of this.items) { - if (!Node.isPair(item)) + if (!identity.isPair(item)) throw new Error(`Map items must all be pairs; found ${JSON.stringify(item)} instead`); } if (!ctx.allNullValues && this.hasAllNullValues(false)) @@ -13696,9 +13732,10 @@ exports.findPair = findPair; "use strict"; +var createNode = __nccwpck_require__(9652); var stringifyCollection = __nccwpck_require__(2466); var Collection = __nccwpck_require__(3466); -var Node = __nccwpck_require__(1399); +var identity = __nccwpck_require__(5589); var Scalar = __nccwpck_require__(9338); var toJS = __nccwpck_require__(2463); @@ -13707,7 +13744,7 @@ class YAMLSeq extends Collection.Collection { return 'tag:yaml.org,2002:seq'; } constructor(schema) { - super(Node.SEQ, schema); + super(identity.SEQ, schema); this.items = []; } add(value) { @@ -13733,7 +13770,7 @@ class YAMLSeq extends Collection.Collection { if (typeof idx !== 'number') return undefined; const it = this.items[idx]; - return !keepScalar && Node.isScalar(it) ? it.value : it; + return !keepScalar && identity.isScalar(it) ? it.value : it; } /** * Checks if the collection includes a value with the key `key`. @@ -13757,7 +13794,7 @@ class YAMLSeq extends Collection.Collection { if (typeof idx !== 'number') throw new Error(`Expected a valid index, not ${key}.`); const prev = this.items[idx]; - if (Node.isScalar(prev) && Scalar.isScalarValue(value)) + if (identity.isScalar(prev) && Scalar.isScalarValue(value)) prev.value = value; else this.items[idx] = value; @@ -13782,9 +13819,24 @@ class YAMLSeq extends Collection.Collection { onComment }); } + static from(schema, obj, ctx) { + const { replacer } = ctx; + const seq = new this(schema); + if (obj && Symbol.iterator in Object(obj)) { + let i = 0; + for (let it of obj) { + if (typeof replacer === 'function') { + const key = obj instanceof Set ? it : String(i++); + it = replacer.call(obj, key, it); + } + seq.items.push(createNode.createNode(it, undefined, ctx)); + } + } + return seq; + } } function asItemIndex(key) { - let idx = Node.isScalar(key) ? key.value : key; + let idx = identity.isScalar(key) ? key.value : key; if (idx && typeof idx === 'string') idx = Number(idx); return typeof idx === 'number' && Number.isInteger(idx) && idx >= 0 @@ -13805,15 +13857,15 @@ exports.YAMLSeq = YAMLSeq; var log = __nccwpck_require__(6909); var stringify = __nccwpck_require__(8409); -var Node = __nccwpck_require__(1399); +var identity = __nccwpck_require__(5589); var Scalar = __nccwpck_require__(9338); var toJS = __nccwpck_require__(2463); const MERGE_KEY = '<<'; function addPairToJSMap(ctx, map, { key, value }) { if (ctx?.doc.schema.merge && isMergeKey(key)) { - value = Node.isAlias(value) ? value.resolve(ctx.doc) : value; - if (Node.isSeq(value)) + 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)) @@ -13847,7 +13899,7 @@ function addPairToJSMap(ctx, map, { key, value }) { return map; } const isMergeKey = (key) => key === MERGE_KEY || - (Node.isScalar(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 @@ -13858,8 +13910,8 @@ const isMergeKey = (key) => key === MERGE_KEY || // 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 && Node.isAlias(value) ? value.resolve(ctx.doc) : value; - if (!Node.isMap(source)) + 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) { @@ -13886,7 +13938,7 @@ function stringifyKey(key, jsKey, ctx) { return ''; if (typeof jsKey !== 'object') return String(jsKey); - if (Node.isNode(key) && ctx && ctx.doc) { + if (identity.isNode(key) && ctx && ctx.doc) { const strCtx = stringify.createStringifyContext(ctx.doc, {}); strCtx.anchors = new Set(); for (const node of ctx.anchors.keys()) @@ -13909,6 +13961,67 @@ function stringifyKey(key, jsKey, ctx) { exports.addPairToJSMap = addPairToJSMap; +/***/ }), + +/***/ 5589: +/***/ ((__unused_webpack_module, exports) => { + +"use strict"; + + +const ALIAS = Symbol.for('yaml.alias'); +const DOC = Symbol.for('yaml.document'); +const MAP = Symbol.for('yaml.map'); +const PAIR = Symbol.for('yaml.pair'); +const SCALAR = Symbol.for('yaml.scalar'); +const SEQ = Symbol.for('yaml.seq'); +const NODE_TYPE = Symbol.for('yaml.node.type'); +const isAlias = (node) => !!node && typeof node === 'object' && node[NODE_TYPE] === ALIAS; +const isDocument = (node) => !!node && typeof node === 'object' && node[NODE_TYPE] === DOC; +const isMap = (node) => !!node && typeof node === 'object' && node[NODE_TYPE] === MAP; +const isPair = (node) => !!node && typeof node === 'object' && node[NODE_TYPE] === PAIR; +const isScalar = (node) => !!node && typeof node === 'object' && node[NODE_TYPE] === SCALAR; +const isSeq = (node) => !!node && typeof node === 'object' && node[NODE_TYPE] === SEQ; +function isCollection(node) { + if (node && typeof node === 'object') + switch (node[NODE_TYPE]) { + case MAP: + case SEQ: + return true; + } + return false; +} +function isNode(node) { + if (node && typeof node === 'object') + switch (node[NODE_TYPE]) { + case ALIAS: + case MAP: + case SCALAR: + case SEQ: + return true; + } + return false; +} +const hasAnchor = (node) => (isScalar(node) || isCollection(node)) && !!node.anchor; + +exports.ALIAS = ALIAS; +exports.DOC = DOC; +exports.MAP = MAP; +exports.NODE_TYPE = NODE_TYPE; +exports.PAIR = PAIR; +exports.SCALAR = SCALAR; +exports.SEQ = SEQ; +exports.hasAnchor = hasAnchor; +exports.isAlias = isAlias; +exports.isCollection = isCollection; +exports.isDocument = isDocument; +exports.isMap = isMap; +exports.isNode = isNode; +exports.isPair = isPair; +exports.isScalar = isScalar; +exports.isSeq = isSeq; + + /***/ }), /***/ 2463: @@ -13917,7 +14030,7 @@ exports.addPairToJSMap = addPairToJSMap; "use strict"; -var Node = __nccwpck_require__(1399); +var identity = __nccwpck_require__(5589); /** * Recursively convert any node or its contents to native JavaScript @@ -13935,7 +14048,7 @@ function toJS(value, arg, ctx) { return value.map((v, i) => toJS(v, String(i), ctx)); if (value && typeof value.toJSON === 'function') { // eslint-disable-next-line @typescript-eslint/no-unsafe-call - if (!ctx || !Node.hasAnchor(value)) + if (!ctx || !identity.hasAnchor(value)) return value.toJSON(arg, ctx); const data = { aliasCount: 0, count: 1, res: undefined }; ctx.anchors.set(value, data); @@ -16322,7 +16435,7 @@ exports.stringify = stringify; "use strict"; -var Node = __nccwpck_require__(1399); +var identity = __nccwpck_require__(5589); var map = __nccwpck_require__(83); var seq = __nccwpck_require__(1693); var string = __nccwpck_require__(2201); @@ -16341,9 +16454,9 @@ class Schema { this.knownTags = resolveKnownTags ? tags.coreKnownTags : {}; this.tags = tags.getTags(customTags, this.name); this.toStringOptions = toStringDefaults ?? null; - Object.defineProperty(this, Node.MAP, { value: map.map }); - Object.defineProperty(this, Node.SCALAR, { value: string.string }); - Object.defineProperty(this, Node.SEQ, { value: seq.seq }); + Object.defineProperty(this, identity.MAP, { value: map.map }); + Object.defineProperty(this, identity.SCALAR, { value: string.string }); + Object.defineProperty(this, identity.SEQ, { value: seq.seq }); // Used by createMap() this.sortMapEntries = typeof sortMapEntries === 'function' @@ -16370,45 +16483,20 @@ exports.Schema = Schema; "use strict"; -var Node = __nccwpck_require__(1399); -var Pair = __nccwpck_require__(246); +var identity = __nccwpck_require__(5589); var YAMLMap = __nccwpck_require__(6011); -function createMap(schema, obj, ctx) { - const { keepUndefined, replacer } = ctx; - const map = new YAMLMap.YAMLMap(schema); - const add = (key, value) => { - if (typeof replacer === 'function') - value = replacer.call(obj, key, value); - else if (Array.isArray(replacer) && !replacer.includes(key)) - return; - if (value !== undefined || keepUndefined) - map.items.push(Pair.createPair(key, value, ctx)); - }; - if (obj instanceof Map) { - for (const [key, value] of obj) - add(key, value); - } - else if (obj && typeof obj === 'object') { - for (const key of Object.keys(obj)) - add(key, obj[key]); - } - if (typeof schema.sortMapEntries === 'function') { - map.items.sort(schema.sortMapEntries); - } - return map; -} const map = { collection: 'map', - createNode: createMap, default: true, nodeClass: YAMLMap.YAMLMap, tag: 'tag:yaml.org,2002:map', resolve(map, onError) { - if (!Node.isMap(map)) + if (!identity.isMap(map)) onError('Expected a mapping for this tag'); return map; - } + }, + createNode: (schema, obj, ctx) => YAMLMap.YAMLMap.from(schema, obj, ctx) }; exports.map = map; @@ -16447,36 +16535,20 @@ exports.nullTag = nullTag; "use strict"; -var createNode = __nccwpck_require__(9652); -var Node = __nccwpck_require__(1399); +var identity = __nccwpck_require__(5589); var YAMLSeq = __nccwpck_require__(5161); -function createSeq(schema, obj, ctx) { - const { replacer } = ctx; - const seq = new YAMLSeq.YAMLSeq(schema); - if (obj && Symbol.iterator in Object(obj)) { - let i = 0; - for (let it of obj) { - if (typeof replacer === 'function') { - const key = obj instanceof Set ? it : String(i++); - it = replacer.call(obj, key, it); - } - seq.items.push(createNode.createNode(it, undefined, ctx)); - } - } - return seq; -} const seq = { collection: 'seq', - createNode: createSeq, default: true, nodeClass: YAMLSeq.YAMLSeq, tag: 'tag:yaml.org,2002:seq', resolve(seq, onError) { - if (!Node.isSeq(seq)) + if (!identity.isSeq(seq)) onError('Expected a sequence for this tag'); return seq; - } + }, + createNode: (schema, obj, ctx) => YAMLSeq.YAMLSeq.from(schema, obj, ctx) }; exports.seq = seq; @@ -17102,10 +17174,10 @@ exports.intOct = intOct; "use strict"; -var YAMLSeq = __nccwpck_require__(5161); +var identity = __nccwpck_require__(5589); var toJS = __nccwpck_require__(2463); -var Node = __nccwpck_require__(1399); var YAMLMap = __nccwpck_require__(6011); +var YAMLSeq = __nccwpck_require__(5161); var pairs = __nccwpck_require__(9841); class YAMLOMap extends YAMLSeq.YAMLSeq { @@ -17130,7 +17202,7 @@ class YAMLOMap extends YAMLSeq.YAMLSeq { ctx.onCreate(map); for (const pair of this.items) { let key, value; - if (Node.isPair(pair)) { + if (identity.isPair(pair)) { key = toJS.toJS(pair.key, '', ctx); value = toJS.toJS(pair.value, key, ctx); } @@ -17143,6 +17215,12 @@ class YAMLOMap extends YAMLSeq.YAMLSeq { } return map; } + static from(schema, iterable, ctx) { + const pairs$1 = pairs.createPairs(schema, iterable, ctx); + const omap = new this(); + omap.items = pairs$1.items; + return omap; + } } YAMLOMap.tag = 'tag:yaml.org,2002:omap'; const omap = { @@ -17155,7 +17233,7 @@ const omap = { const pairs$1 = pairs.resolvePairs(seq, onError); const seenKeys = []; for (const { key } of pairs$1.items) { - if (Node.isScalar(key)) { + if (identity.isScalar(key)) { if (seenKeys.includes(key.value)) { onError(`Ordered maps must not include duplicate keys: ${key.value}`); } @@ -17166,12 +17244,7 @@ const omap = { } return Object.assign(new YAMLOMap(), pairs$1); }, - createNode(schema, iterable, ctx) { - const pairs$1 = pairs.createPairs(schema, iterable, ctx); - const omap = new YAMLOMap(); - omap.items = pairs$1.items; - return omap; - } + createNode: (schema, iterable, ctx) => YAMLOMap.from(schema, iterable, ctx) }; exports.YAMLOMap = YAMLOMap; @@ -17186,18 +17259,18 @@ exports.omap = omap; "use strict"; -var Node = __nccwpck_require__(1399); +var identity = __nccwpck_require__(5589); var Pair = __nccwpck_require__(246); var Scalar = __nccwpck_require__(9338); var YAMLSeq = __nccwpck_require__(5161); function resolvePairs(seq, onError) { - if (Node.isSeq(seq)) { + if (identity.isSeq(seq)) { for (let i = 0; i < seq.items.length; ++i) { let item = seq.items[i]; - if (Node.isPair(item)) + if (identity.isPair(item)) continue; - else if (Node.isMap(item)) { + else if (identity.isMap(item)) { if (item.items.length > 1) onError('Each pair must have its own sequence indicator'); const pair = item.items[0] || new Pair.Pair(new Scalar.Scalar(null)); @@ -17213,7 +17286,7 @@ function resolvePairs(seq, onError) { } item = pair; } - seq.items[i] = Node.isPair(item) ? item : new Pair.Pair(item); + seq.items[i] = identity.isPair(item) ? item : new Pair.Pair(item); } } else @@ -17322,7 +17395,7 @@ exports.schema = schema; "use strict"; -var Node = __nccwpck_require__(1399); +var identity = __nccwpck_require__(5589); var Pair = __nccwpck_require__(246); var YAMLMap = __nccwpck_require__(6011); @@ -17333,7 +17406,7 @@ class YAMLSet extends YAMLMap.YAMLMap { } add(key) { let pair; - if (Node.isPair(key)) + if (identity.isPair(key)) pair = key; else if (key && typeof key === 'object' && @@ -17353,8 +17426,8 @@ class YAMLSet extends YAMLMap.YAMLMap { */ get(key, keepPair) { const pair = YAMLMap.findPair(this.items, key); - return !keepPair && Node.isPair(pair) - ? Node.isScalar(pair.key) + return !keepPair && identity.isPair(pair) + ? identity.isScalar(pair.key) ? pair.key.value : pair.key : pair; @@ -17381,6 +17454,17 @@ class YAMLSet extends YAMLMap.YAMLMap { else throw new Error('Set items must all have null values'); } + static from(schema, iterable, ctx) { + const { replacer } = ctx; + const set = new this(schema); + if (iterable && Symbol.iterator in Object(iterable)) + for (let value of iterable) { + if (typeof replacer === 'function') + value = replacer.call(iterable, value, value); + set.items.push(Pair.createPair(value, null, ctx)); + } + return set; + } } YAMLSet.tag = 'tag:yaml.org,2002:set'; const set = { @@ -17389,8 +17473,9 @@ const set = { nodeClass: YAMLSet, default: false, tag: 'tag:yaml.org,2002:set', + createNode: (schema, iterable, ctx) => YAMLSet.from(schema, iterable, ctx), resolve(map, onError) { - if (Node.isMap(map)) { + if (identity.isMap(map)) { if (map.hasAllNullValues(true)) return Object.assign(new YAMLSet(), map); else @@ -17399,17 +17484,6 @@ const set = { else onError('Expected a mapping for this tag'); return map; - }, - createNode(schema, iterable, ctx) { - const { replacer } = ctx; - const set = new YAMLSet(schema); - if (iterable && Symbol.iterator in Object(iterable)) - for (let value of iterable) { - if (typeof replacer === 'function') - value = replacer.call(iterable, value, value); - set.items.push(Pair.createPair(value, null, ctx)); - } - return set; } }; @@ -17470,7 +17544,7 @@ function stringifySexagesimal(node) { } return (sign + parts - .map(n => (n < 10 ? '0' + String(n) : String(n))) + .map(n => String(n).padStart(2, '0')) .join(':') .replace(/000000\d*$/, '') // % 60 may introduce error ); @@ -17687,7 +17761,7 @@ exports.foldFlowLines = foldFlowLines; var anchors = __nccwpck_require__(8459); -var Node = __nccwpck_require__(1399); +var identity = __nccwpck_require__(5589); var stringifyComment = __nccwpck_require__(5182); var stringifyString = __nccwpck_require__(6226); @@ -17740,7 +17814,7 @@ function getTagObject(tags, item) { } let tagObj = undefined; let obj; - if (Node.isScalar(item)) { + if (identity.isScalar(item)) { obj = item.value; const match = tags.filter(t => t.identify?.(obj)); tagObj = @@ -17761,7 +17835,7 @@ function stringifyProps(node, tagObj, { anchors: anchors$1, doc }) { if (!doc.directives) return ''; const props = []; - const anchor = (Node.isScalar(node) || Node.isCollection(node)) && node.anchor; + const anchor = (identity.isScalar(node) || identity.isCollection(node)) && node.anchor; if (anchor && anchors.anchorIsValid(anchor)) { anchors$1.add(anchor); props.push(`&${anchor}`); @@ -17772,9 +17846,9 @@ function stringifyProps(node, tagObj, { anchors: anchors$1, doc }) { return props.join(' '); } function stringify(item, ctx, onComment, onChompKeep) { - if (Node.isPair(item)) + if (identity.isPair(item)) return item.toString(ctx, onComment, onChompKeep); - if (Node.isAlias(item)) { + if (identity.isAlias(item)) { if (ctx.doc.directives) return item.toString(ctx); if (ctx.resolvedAliases?.has(item)) { @@ -17789,7 +17863,7 @@ function stringify(item, ctx, onComment, onChompKeep) { } } let tagObj = undefined; - const node = Node.isNode(item) + const node = identity.isNode(item) ? item : ctx.doc.createNode(item, { onTagObj: o => (tagObj = o) }); if (!tagObj) @@ -17799,12 +17873,12 @@ function stringify(item, ctx, onComment, onChompKeep) { ctx.indentAtStart = (ctx.indentAtStart ?? 0) + props.length + 1; const str = typeof tagObj.stringify === 'function' ? tagObj.stringify(node, ctx, onComment, onChompKeep) - : Node.isScalar(node) + : identity.isScalar(node) ? stringifyString.stringifyString(node, ctx, onComment, onChompKeep) : node.toString(ctx, onComment, onChompKeep); if (!props) return str; - return Node.isScalar(node) || str[0] === '{' || str[0] === '[' + return identity.isScalar(node) || str[0] === '{' || str[0] === '[' ? `${props} ${str}` : `${props}\n${ctx.indent}${str}`; } @@ -17822,7 +17896,7 @@ exports.stringify = stringify; var Collection = __nccwpck_require__(3466); -var Node = __nccwpck_require__(1399); +var identity = __nccwpck_require__(5589); var stringify = __nccwpck_require__(8409); var stringifyComment = __nccwpck_require__(5182); @@ -17839,15 +17913,15 @@ function stringifyBlockCollection({ comment, items }, ctx, { blockItemPrefix, fl for (let i = 0; i < items.length; ++i) { const item = items[i]; let comment = null; - if (Node.isNode(item)) { + if (identity.isNode(item)) { if (!chompKeep && item.spaceBefore) lines.push(''); addCommentBefore(ctx, lines, item.commentBefore, chompKeep); if (item.comment) comment = item.comment; } - else if (Node.isPair(item)) { - const ik = Node.isNode(item.key) ? item.key : null; + else if (identity.isPair(item)) { + const ik = identity.isNode(item.key) ? item.key : null; if (ik) { if (!chompKeep && ik.spaceBefore) lines.push(''); @@ -17896,15 +17970,15 @@ function stringifyFlowCollection({ comment, items }, ctx, { flowChars, itemInden for (let i = 0; i < items.length; ++i) { const item = items[i]; let comment = null; - if (Node.isNode(item)) { + if (identity.isNode(item)) { if (item.spaceBefore) lines.push(''); addCommentBefore(ctx, lines, item.commentBefore, false); if (item.comment) comment = item.comment; } - else if (Node.isPair(item)) { - const ik = Node.isNode(item.key) ? item.key : null; + else if (identity.isPair(item)) { + const ik = identity.isNode(item.key) ? item.key : null; if (ik) { if (ik.spaceBefore) lines.push(''); @@ -17912,7 +17986,7 @@ function stringifyFlowCollection({ comment, items }, ctx, { flowChars, itemInden if (ik.comment) reqNewline = true; } - const iv = Node.isNode(item.value) ? item.value : null; + const iv = identity.isNode(item.value) ? item.value : null; if (iv) { if (iv.comment) comment = iv.comment; @@ -17956,7 +18030,7 @@ function stringifyFlowCollection({ comment, items }, ctx, { flowChars, itemInden } } if (comment) { - str += stringifyComment.lineComment(str, commentString(comment), indent); + str += stringifyComment.lineComment(str, indent, commentString(comment)); if (onComment) onComment(); } @@ -18014,7 +18088,7 @@ exports.stringifyComment = stringifyComment; "use strict"; -var Node = __nccwpck_require__(1399); +var identity = __nccwpck_require__(5589); var stringify = __nccwpck_require__(8409); var stringifyComment = __nccwpck_require__(5182); @@ -18043,7 +18117,7 @@ function stringifyDocument(doc, options) { let chompKeep = false; let contentComment = null; if (doc.contents) { - if (Node.isNode(doc.contents)) { + if (identity.isNode(doc.contents)) { if (doc.contents.spaceBefore && hasDirectives) lines.push(''); if (doc.contents.commentBefore) { @@ -18143,19 +18217,19 @@ exports.stringifyNumber = stringifyNumber; "use strict"; -var Node = __nccwpck_require__(1399); +var identity = __nccwpck_require__(5589); var Scalar = __nccwpck_require__(9338); var stringify = __nccwpck_require__(8409); var stringifyComment = __nccwpck_require__(5182); function stringifyPair({ key, value }, ctx, onComment, onChompKeep) { const { allNullValues, doc, indent, indentStep, options: { commentString, indentSeq, simpleKeys } } = ctx; - let keyComment = (Node.isNode(key) && key.comment) || null; + let keyComment = (identity.isNode(key) && key.comment) || null; if (simpleKeys) { if (keyComment) { throw new Error('With simple keys, key nodes cannot have comments'); } - if (Node.isCollection(key)) { + if (identity.isCollection(key)) { const msg = 'With simple keys, collection cannot be used as a key value'; throw new Error(msg); } @@ -18163,8 +18237,8 @@ function stringifyPair({ key, value }, ctx, onComment, onChompKeep) { let explicitKey = !simpleKeys && (!key || (keyComment && value == null && !ctx.inFlow) || - Node.isCollection(key) || - (Node.isScalar(key) + identity.isCollection(key) || + (identity.isScalar(key) ? key.type === Scalar.Scalar.BLOCK_FOLDED || key.type === Scalar.Scalar.BLOCK_LITERAL : typeof key === 'object')); ctx = Object.assign({}, ctx, { @@ -18209,7 +18283,7 @@ function stringifyPair({ key, value }, ctx, onComment, onChompKeep) { str += stringifyComment.lineComment(str, ctx.indent, commentString(keyComment)); } let vsb, vcb, valueComment; - if (Node.isNode(value)) { + if (identity.isNode(value)) { vsb = !!value.spaceBefore; vcb = value.commentBefore; valueComment = value.comment; @@ -18222,14 +18296,14 @@ function stringifyPair({ key, value }, ctx, onComment, onChompKeep) { value = doc.createNode(value); } ctx.implicitKey = false; - if (!explicitKey && !keyComment && Node.isScalar(value)) + if (!explicitKey && !keyComment && identity.isScalar(value)) ctx.indentAtStart = str.length + 1; chompKeep = false; if (!indentSeq && indentStep.length >= 2 && !ctx.inFlow && !explicitKey && - Node.isSeq(value) && + identity.isSeq(value) && !value.flow && !value.tag && !value.anchor) { @@ -18253,7 +18327,7 @@ function stringifyPair({ key, value }, ctx, onComment, onChompKeep) { ws += `\n${ctx.indent}`; } } - else if (!explicitKey && Node.isCollection(value)) { + else if (!explicitKey && identity.isCollection(value)) { const vs0 = valueStr[0]; const nl0 = valueStr.indexOf('\n'); const hasNewline = nl0 !== -1; @@ -18306,8 +18380,8 @@ exports.stringifyPair = stringifyPair; var Scalar = __nccwpck_require__(9338); var foldFlowLines = __nccwpck_require__(2889); -const getFoldOptions = (ctx) => ({ - indentAtStart: ctx.indentAtStart, +const getFoldOptions = (ctx, isBlock) => ({ + indentAtStart: isBlock ? ctx.indent.length : ctx.indentAtStart, lineWidth: ctx.options.lineWidth, minContentWidth: ctx.options.minContentWidth }); @@ -18420,7 +18494,7 @@ function doubleQuotedString(value, ctx) { str = start ? str + json.slice(start) : json; return implicitKey ? str - : foldFlowLines.foldFlowLines(str, indent, foldFlowLines.FOLD_QUOTED, getFoldOptions(ctx)); + : foldFlowLines.foldFlowLines(str, indent, foldFlowLines.FOLD_QUOTED, getFoldOptions(ctx, false)); } function singleQuotedString(value, ctx) { if (ctx.options.singleQuote === false || @@ -18432,7 +18506,7 @@ function singleQuotedString(value, ctx) { const res = "'" + value.replace(/'/g, "''").replace(/\n+/g, `$&\n${indent}`) + "'"; return ctx.implicitKey ? res - : foldFlowLines.foldFlowLines(res, indent, foldFlowLines.FOLD_FLOW, getFoldOptions(ctx)); + : foldFlowLines.foldFlowLines(res, indent, foldFlowLines.FOLD_FLOW, getFoldOptions(ctx, false)); } function quotedString(value, ctx) { const { singleQuote } = ctx.options; @@ -18451,6 +18525,15 @@ function quotedString(value, ctx) { } return qs(value, ctx); } +// The negative lookbehind avoids a polynomial search, +// but isn't supported yet on Safari: https://caniuse.com/js-regexp-lookbehind +let blockEndNewlines; +try { + blockEndNewlines = new RegExp('(^|(?