Repository navigation
Conversation
Since Rich-Harris#371, update() emptied every chunk after `first` in output order while its start was before `end`. Once `first` has been moved, the chunk after it in the output can come from before `start`, so updating a moved range dropped unrelated content: `new MagicString('ab').move(1, 2, 0).update(1, 2, 'P')` gave 'P' instead of 'Pa'. Walk the range itself, as the check before it does.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Since 1.4.5,
update()andoverwrite()on a range that was moved delete unrelated text:No error is thrown, so the text is lost silently.
Cause
#371 rewrote the loop in
update()that empties the rest of the range afterfirsttakes the replacement. It used to walk fromfirsttolast, a run the check above it had already proved contiguous. It now walksfirst.nextin output order whilechunk.start < end. After a move, the chunk that followsfirstin the output can be one from beforestartin the original. Its start is belowend, so it is taken for part of the range and emptied. In the first example,'a'([0, 1)) follows the moved'b'([1, 2)), so it is wiped.Fix
Walk the range itself, with the same condition as the check right above it (
chunk.end < end, followingnext). That check has already thrown unless every chunk in the range is followed by the one starting at its end, so the walk stays inside the range.Evidence
'ab'.move(1, 2, 0).update(1, 2, 'P')gives'Pa'up toaed5675and'P'from877ae76(chore: enable strict type checking #371) on.move,update,overwrite,appendLeft,remove,replaceandreplaceAllon short strings: of 113,024 sequences that include amove, this change alters the output of 3,802, and all 3,802 now match v1.4.3. Nothing else changes.toString(), everyslice(), the decoded maps and the Bundle paths, shows notoString()difference beyond the intended changes since v1.4.3 (empty matches in removed content from fix: skip empty matches at a chunk boundary inside removed content #366, indent exclusions from fix: respect indent exclusions on moved edits and CRLF bundle intros #377).moveyet (tests/fuzz/FINDINGS.mdlists it as next), which is likely why it did not catch this. It still passes at 20,000 sequences for seeds 1 and 2.One test is added, covering a range moved to the front, a single character and two characters, with
updateand withreplace. It fails on master and passes here. The suite is at 495 and passes, ESLint is clean, and typecheck reports no errors.