summaryrefslogtreecommitdiff
path: root/node_modules/yaml/dist/compose/resolve-block-map.js
diff options
context:
space:
mode:
authorMinteck <contact@minteck.org>2022-04-09 18:38:29 +0200
committerMinteck <contact@minteck.org>2022-04-09 18:38:29 +0200
commit457c93328f5b51b3fc0aa1600ce8eb8b45a5c2a9 (patch)
treea899daf11edb7ce6a99700e462a5740e013f5951 /node_modules/yaml/dist/compose/resolve-block-map.js
downloadsnowjail-457c93328f5b51b3fc0aa1600ce8eb8b45a5c2a9.tar.gz
snowjail-457c93328f5b51b3fc0aa1600ce8eb8b45a5c2a9.tar.bz2
snowjail-457c93328f5b51b3fc0aa1600ce8eb8b45a5c2a9.zip
Snowjail v0.1
Diffstat (limited to 'node_modules/yaml/dist/compose/resolve-block-map.js')
-rw-r--r--node_modules/yaml/dist/compose/resolve-block-map.js109
1 files changed, 109 insertions, 0 deletions
diff --git a/node_modules/yaml/dist/compose/resolve-block-map.js b/node_modules/yaml/dist/compose/resolve-block-map.js
new file mode 100644
index 0000000..c3fe91a
--- /dev/null
+++ b/node_modules/yaml/dist/compose/resolve-block-map.js
@@ -0,0 +1,109 @@
+'use strict';
+
+var Pair = require('../nodes/Pair.js');
+var YAMLMap = require('../nodes/YAMLMap.js');
+var resolveProps = require('./resolve-props.js');
+var utilContainsNewline = require('./util-contains-newline.js');
+var utilFlowIndentCheck = require('./util-flow-indent-check.js');
+var utilMapIncludes = require('./util-map-includes.js');
+
+const startColMsg = 'All mapping items must start at the same column';
+function resolveBlockMap({ composeNode, composeEmptyNode }, ctx, bm, onError) {
+ var _a;
+ const map = new YAMLMap.YAMLMap(ctx.schema);
+ if (ctx.atRoot)
+ ctx.atRoot = false;
+ let offset = bm.offset;
+ for (const collItem of bm.items) {
+ const { start, key, sep, value } = collItem;
+ // key properties
+ const keyProps = resolveProps.resolveProps(start, {
+ indicator: 'explicit-key-ind',
+ next: key !== null && key !== void 0 ? key : sep === null || sep === void 0 ? void 0 : sep[0],
+ offset,
+ onError,
+ startOnNewline: true
+ });
+ const implicitKey = !keyProps.found;
+ if (implicitKey) {
+ if (key) {
+ if (key.type === 'block-seq')
+ onError(offset, 'BLOCK_AS_IMPLICIT_KEY', 'A block sequence may not be used as an implicit map key');
+ else if ('indent' in key && key.indent !== bm.indent)
+ onError(offset, 'BAD_INDENT', startColMsg);
+ }
+ if (!keyProps.anchor && !keyProps.tag && !sep) {
+ // TODO: assert being at last item?
+ if (keyProps.comment) {
+ if (map.comment)
+ map.comment += '\n' + keyProps.comment;
+ else
+ map.comment = keyProps.comment;
+ }
+ continue;
+ }
+ }
+ else if (((_a = keyProps.found) === null || _a === void 0 ? void 0 : _a.indent) !== bm.indent)
+ onError(offset, 'BAD_INDENT', startColMsg);
+ if (implicitKey && utilContainsNewline.containsNewline(key))
+ onError(key, // checked by containsNewline()
+ 'MULTILINE_IMPLICIT_KEY', 'Implicit keys need to be on a single line');
+ // key value
+ const keyStart = keyProps.end;
+ const keyNode = key
+ ? composeNode(ctx, key, keyProps, onError)
+ : composeEmptyNode(ctx, keyStart, start, null, keyProps, onError);
+ if (ctx.schema.compat)
+ utilFlowIndentCheck.flowIndentCheck(bm.indent, key, onError);
+ if (utilMapIncludes.mapIncludes(ctx, map.items, keyNode))
+ onError(keyStart, 'DUPLICATE_KEY', 'Map keys must be unique');
+ // value properties
+ const valueProps = resolveProps.resolveProps(sep !== null && sep !== void 0 ? sep : [], {
+ indicator: 'map-value-ind',
+ next: value,
+ offset: keyNode.range[2],
+ onError,
+ startOnNewline: !key || key.type === 'block-scalar'
+ });
+ offset = valueProps.end;
+ if (valueProps.found) {
+ if (implicitKey) {
+ if ((value === null || value === void 0 ? void 0 : value.type) === 'block-map' && !valueProps.hasNewline)
+ onError(offset, 'BLOCK_AS_IMPLICIT_KEY', 'Nested mappings are not allowed in compact mappings');
+ if (ctx.options.strict &&
+ keyProps.start < valueProps.found.offset - 1024)
+ onError(keyNode.range, 'KEY_OVER_1024_CHARS', 'The : indicator must be at most 1024 chars after the start of an implicit block mapping key');
+ }
+ // value value
+ const valueNode = value
+ ? composeNode(ctx, value, valueProps, onError)
+ : composeEmptyNode(ctx, offset, sep, null, valueProps, onError);
+ if (ctx.schema.compat)
+ utilFlowIndentCheck.flowIndentCheck(bm.indent, value, onError);
+ offset = valueNode.range[2];
+ const pair = new Pair.Pair(keyNode, valueNode);
+ if (ctx.options.keepSourceTokens)
+ pair.srcToken = collItem;
+ map.items.push(pair);
+ }
+ else {
+ // key with no value
+ if (implicitKey)
+ onError(keyNode.range, 'MISSING_CHAR', 'Implicit map keys need to be followed by map values');
+ if (valueProps.comment) {
+ if (keyNode.comment)
+ keyNode.comment += '\n' + valueProps.comment;
+ else
+ keyNode.comment = valueProps.comment;
+ }
+ const pair = new Pair.Pair(keyNode);
+ if (ctx.options.keepSourceTokens)
+ pair.srcToken = collItem;
+ map.items.push(pair);
+ }
+ }
+ map.range = [bm.offset, offset, offset];
+ return map;
+}
+
+exports.resolveBlockMap = resolveBlockMap;