diff options
author | Minteck <contact@minteck.org> | 2022-11-28 17:31:34 +0100 |
---|---|---|
committer | Minteck <contact@minteck.org> | 2022-11-28 17:31:34 +0100 |
commit | 7923aa8942b55884320ef2428417e3ee4b121613 (patch) | |
tree | 7993632f2898b1998f25b11ce40a8d2eb3d44730 /MistyCore/node_modules/yaml/dist/compose/compose-collection.js | |
download | mistyos-og-mane.tar.gz mistyos-og-mane.tar.bz2 mistyos-og-mane.zip |
Diffstat (limited to 'MistyCore/node_modules/yaml/dist/compose/compose-collection.js')
-rw-r--r-- | MistyCore/node_modules/yaml/dist/compose/compose-collection.js | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/MistyCore/node_modules/yaml/dist/compose/compose-collection.js b/MistyCore/node_modules/yaml/dist/compose/compose-collection.js new file mode 100644 index 0000000..015eadd --- /dev/null +++ b/MistyCore/node_modules/yaml/dist/compose/compose-collection.js @@ -0,0 +1,61 @@ +'use strict'; + +var Node = require('../nodes/Node.js'); +var Scalar = require('../nodes/Scalar.js'); +var resolveBlockMap = require('./resolve-block-map.js'); +var resolveBlockSeq = require('./resolve-block-seq.js'); +var resolveFlowCollection = require('./resolve-flow-collection.js'); + +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 + const Coll = coll.constructor; + 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 (!tag) { + const kt = ctx.schema.knownTags[tagName]; + if (kt && kt.collection === expType) { + ctx.schema.tags.push(Object.assign({}, kt, { default: false })); + tag = kt; + } + else { + onError(tagToken, 'TAG_RESOLVE_FAILED', `Unresolved tag: ${tagName}`, true); + coll.tag = tagName; + return coll; + } + } + const res = tag.resolve(coll, msg => onError(tagToken, 'TAG_RESOLVE_FAILED', msg), ctx.options); + const node = Node.isNode(res) + ? res + : new Scalar.Scalar(res); + node.range = coll.range; + node.tag = tagName; + if (tag?.format) + node.format = tag.format; + return node; +} + +exports.composeCollection = composeCollection; |