MCPcopy
hub / github.com/IvanMathy/Boop / storeMappingPair

Function storeMappingPair

Boop/Boop/scripts/lib/js-yaml.js:1289–1344  ·  view source on GitHub ↗
(state, _result, overridableKeys, keyTag, keyNode, valueNode, startLine, startPos)

Source from the content-addressed store, hash-verified

1287}
1288
1289function storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, valueNode, startLine, startPos) {
1290 var index, quantity;
1291
1292 // The output is a plain object here, so keys can only be strings.
1293 // We need to convert keyNode to a string, but doing so can hang the process
1294 // (deeply nested arrays that explode exponentially using aliases).
1295 if (Array.isArray(keyNode)) {
1296 keyNode = Array.prototype.slice.call(keyNode);
1297
1298 for (index = 0, quantity = keyNode.length; index < quantity; index += 1) {
1299 if (Array.isArray(keyNode[index])) {
1300 throwError(state, 'nested arrays are not supported inside keys');
1301 }
1302
1303 if (typeof keyNode === 'object' && _class(keyNode[index]) === '[object Object]') {
1304 keyNode[index] = '[object Object]';
1305 }
1306 }
1307 }
1308
1309 // Avoid code execution in load() via toString property
1310 // (still use its own toString for arrays, timestamps,
1311 // and whatever user schema extensions happen to have @@toStringTag)
1312 if (typeof keyNode === 'object' && _class(keyNode) === '[object Object]') {
1313 keyNode = '[object Object]';
1314 }
1315
1316
1317 keyNode = String(keyNode);
1318
1319 if (_result === null) {
1320 _result = {};
1321 }
1322
1323 if (keyTag === 'tag:yaml.org,2002:merge') {
1324 if (Array.isArray(valueNode)) {
1325 for (index = 0, quantity = valueNode.length; index < quantity; index += 1) {
1326 mergeMappings(state, _result, valueNode[index], overridableKeys);
1327 }
1328 } else {
1329 mergeMappings(state, _result, valueNode, overridableKeys);
1330 }
1331 } else {
1332 if (!state.json &&
1333 !_hasOwnProperty.call(overridableKeys, keyNode) &&
1334 _hasOwnProperty.call(_result, keyNode)) {
1335 state.line = startLine || state.line;
1336 state.position = startPos || state.position;
1337 throwError(state, 'duplicated mapping key');
1338 }
1339 _result[keyNode] = valueNode;
1340 delete overridableKeys[keyNode];
1341 }
1342
1343 return _result;
1344}
1345
1346function readLineBreak(state) {

Callers 2

readFlowCollectionFunction · 0.85
readBlockMappingFunction · 0.85

Calls 3

throwErrorFunction · 0.85
_classFunction · 0.85
mergeMappingsFunction · 0.85

Tested by

no test coverage detected