JavaScript: Diff is not iterable
Author: JackuBCreated Sep 3, 2018Updated May 2, 2024
There was a change in JS version https://github.com/google/diff-match-patch/commit/cd60d246aecf871367313c7cf6dc8814af32c5e3#diff-5270d640a6c9c1b0590326b029d71ec8R76 from plain Array to a diff_match_patch.Diff Object that's trying to emulate Array.
The new object is not iterable, which messes up for example with Array destructing:
const a = dmp.diff_main('abc', 'ab123c', false);
const [eq, str] = a[0]; // => Uncaught TypeError: a[0] is not iterable- was this change necessary? Tested that plain array works just fine with current version
- To really emulate array here, adding
[Symbol.iterator]would do the trick, but its browser support is questionable
Source: google/diff-match-patch