Fix after index not being incremented (#1124)

This commit is contained in:
toasted-nutbread 2020-12-18 15:46:39 -05:00 committed by GitHub
parent df7834a880
commit fd91a5b383
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -87,9 +87,16 @@ function applyModifications(manifest, modifications) {
const key = path2[path2.length - 1]; const key = path2[path2.length - 1];
let {index} = modification; let {index} = modification;
if (typeof index !== 'number') { index = -1; } if (typeof index !== 'number') {
if (typeof before === 'string') { index = getObjectKeyIndex(object, before); } index = -1;
if (typeof after === 'string') { index = getObjectKeyIndex(object, after); } }
if (typeof before === 'string') {
index = getObjectKeyIndex(object, before);
}
if (typeof after === 'string') {
index = getObjectKeyIndex(object, after);
if (index >= 0) { ++index; }
}
setObjectKeyAtIndex(object, key, value, index); setObjectKeyAtIndex(object, key, value, index);
} }
@ -139,9 +146,17 @@ function applyModifications(manifest, modifications) {
const oldObjectIsNewObject = arraysAreSame(path2, newPath, -1); const oldObjectIsNewObject = arraysAreSame(path2, newPath, -1);
const value = oldObject[oldKey]; const value = oldObject[oldKey];
let index = (oldObjectIsNewObject && action !== 'copy') ? getObjectKeyIndex(oldObject, oldKey) : -1; let {index} = modification;
if (typeof before === 'string') { index = getObjectKeyIndex(newObject, before); } if (typeof index !== 'number' || index < 0) {
if (typeof after === 'string') { index = getObjectKeyIndex(newObject, after); } index = (oldObjectIsNewObject && action !== 'copy') ? getObjectKeyIndex(oldObject, oldKey) : -1;
}
if (typeof before === 'string') {
index = getObjectKeyIndex(newObject, before);
}
if (typeof after === 'string') {
index = getObjectKeyIndex(newObject, after);
if (index >= 0) { ++index; }
}
setObjectKeyAtIndex(newObject, newKey, value, index); setObjectKeyAtIndex(newObject, newKey, value, index);
if (action !== 'copy' && (!oldObjectIsNewObject || oldKey !== newKey)) { if (action !== 'copy' && (!oldObjectIsNewObject || oldKey !== newKey)) {