Add integrity checking to tests and fix various bugs #126
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.
Fixes #115
This commit adds a new
IntegrityCheckingMagicString
class that subclassesMagicString
and does an integrity check operation, which is used in test code.This revealed 5 bugs, all of which are also fixed in this commit:
indent
, the code was callingchunk.split
, then making an attempt atproperly updating
byStart
andbyEnd
. But it wasn't properly updatinglastChunk
. Rather than callingchunk.split
, we can just callthis._splitChunk
, which updatesbyStart
,byEnd
, andlastChunk
correctly.
move
could sometimes assignundefined
as anext
pointer, which isinconsistent since all other cases use
null
. Not a really big deal, but niceto be consistent.
overwrite
was attempting to do a linked list removal in a way that wasn'tproperly updating all state ( overwrite method can cause state corruption #115 ). I tried changing the code to remove the
nodes properly, but the details seemed to get really subtle, especially
accounting for moved chunks, and it didn't seem like the complexity was worth
it, so I effectively just reverted optimisation - remove empty chunks when overwriting #113 to fix the issue. But now with the
new integrity checking, it should be a lot easier to get the details right if
that's desirable.
trimStart
andtrimEnd
were attempting to updatebyStart
andbyEnd
, butthey didn't properly set
byEnd
of the newly-created chunk created bychunk.trimStart
/chunk.trimEnd
. Setting thebyEnd
for that new chunkseems to fix things.
trimEnd
was settingthis.lastChunk = chunk.next
, which makes sense for thefirst iteration (when working with the very last chunk in the linked list),
but doesn't make sense for later iterations, since it meant that some chunks
just get dropped. We now only run that line on the last chunk.