summaryrefslogtreecommitdiff
path: root/node_modules/yaml/dist/compose/compose-collection.js
diff options
context:
space:
mode:
authorPhilipp Tanlak <philipp.tanlak@gmail.com>2025-11-24 20:54:57 +0100
committerPhilipp Tanlak <philipp.tanlak@gmail.com>2025-11-24 20:57:48 +0100
commitb1e2c8fd5cb5dfa46bc440a12eafaf56cd844b1c (patch)
tree49d360fd6cbc6a2754efe93524ac47ff0fbe0f7d /node_modules/yaml/dist/compose/compose-collection.js
Docs
Diffstat (limited to 'node_modules/yaml/dist/compose/compose-collection.js')
-rw-r--r--node_modules/yaml/dist/compose/compose-collection.js78
1 files changed, 78 insertions, 0 deletions
diff --git a/node_modules/yaml/dist/compose/compose-collection.js b/node_modules/yaml/dist/compose/compose-collection.js
new file mode 100644
index 0000000..e4b1971
--- /dev/null
+++ b/node_modules/yaml/dist/compose/compose-collection.js
@@ -0,0 +1,78 @@
+'use strict';
+
+var identity = require('../nodes/identity.js');
+var Scalar = require('../nodes/Scalar.js');
+var YAMLMap = require('../nodes/YAMLMap.js');
+var YAMLSeq = require('../nodes/YAMLSeq.js');
+var resolveBlockMap = require('./resolve-block-map.js');
+var resolveBlockSeq = require('./resolve-block-seq.js');
+var resolveFlowCollection = require('./resolve-flow-collection.js');
+
+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;
+ }
+ 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) {
+ ctx.schema.tags.push(Object.assign({}, kt, { default: false }));
+ tag = kt;
+ }
+ else {
+ 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 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;
+ node.tag = tagName;
+ if (tag?.format)
+ node.format = tag.format;
+ return node;
+}
+
+exports.composeCollection = composeCollection;