You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
hasChanged() returns true for an unchanged string when an edit spans a chunk boundary #332
hasChanged() reports a change on a string that is byte-identical to the original, when an overwrite covers more than one chunk.
Version
master @ e324bc4. Not present in the published 1.2.1.
Reproduction
importMagicStringfrom'magic-string'consts=newMagicString('abcdefghij')s.appendLeft(3,'')// splits the chunk at 3s.overwrite(0,5,'abcde')// spans the splits.toString()// 'abcdefghij's.hasChanged()// true
The split does not have to be explicit. Two overlapping overwrites create one on their own:
#328 replaced original !== toString() with a walk over the chunk list that compares each edited chunk against original.slice(chunk.start, chunk.end). That assumes a chunk's content is the replacement for its own range. An overwrite spanning several chunks stores the whole replacement on the first chunk and empties the rest, so the first chunk's content is longer than the range it covers and the comparison fails even though the concatenation is unchanged.
Scope
Every case I found is a false positive, hasChanged() returning true on an unchanged string. I did not find one where it returns false on a changed string. Comparing against the old implementation over 20,880 random operation sequences drawn from remove, overwrite, update, reset, move, indent and the four append and prepend methods, 775 disagree, all in that direction.
#328 has not been released, so this is on master only.
Activity