fix(tokenizer): Drop chunks after emitting tokens#432
Merged
Conversation
Fixes #357 Co-Authored-By: Masaki Hara <41755+qnighy@users.noreply.github.com>
Otherwise we might miss some data
And use it to emit text blocks from sax parser as soon as we might drop the buffer.
fb55
commented
Mar 3, 2022
| @@ -536,6 +542,7 @@ export class Tokenizer { | |||
| if (this.currentCharacterToken.type !== type) { | |||
| this.currentLocation = this.getCurrentLocation(0); | |||
| this._emitCurrentCharacterToken(this.currentLocation); | |||
Collaborator
Author
There was a problem hiding this comment.
We can't drop the parsed chunk in _emitCurrentCharacterToken, as it is called from prepareToken and could remove the buffer for the token right after the character token.
The `close` doesn't seem to work in Node 12.
wooorm
reviewed
Mar 3, 2022
Collaborator
wooorm
left a comment
There was a problem hiding this comment.
not my area of expertise in this code base. But if the test was broken before and works now, 👍
|
Thanks a lot for the fix! |
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.
Fixes #292, #357
We would sometimes drop chunks before the corresponding tokens were processed by the rewriting stream. This led to #292. Now, we will drop buffers after emitting events.
BREAKING CHANGE: The SAX parser and rewriting stream will now emit text events when the underlying buffer will be dropped right after the event.
@qnighy I've adopted your test from #357 — hope that's okay! I'd also love it if you could make sure this works for you.