Parse a JSON string that has git merge conflicts, resolving if possible.
If the JSON is valid, it just does
JSON.parse as normal.
If either side of the conflict is invalid JSON, then an error is thrown for that.
// after a git merge that left some conflicts thereconst data = fs// reviverFunction is passed to JSON.parse as the reviver function// preference defaults to 'ours', set to 'theirs' to prefer the other// side's changes.const parsed =// returns true if the data looks like a conflicted diff fileparsed
prefer is set to
theirs, then the vaules of
switched in the resolver function. (Ie, we'll apply their changes on top
of our object, rather than the other way around.)
Parse the conflicted file into 3 pieces:
Get the diff from
Apply each change of that diff to
If any change in the diff set cannot be applied (ie, because they changed an object into a non-object and we changed a field on that object), then replace the object at the specified path with the object at the path in