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.
peek() is required for streaming parsers.
In browsers, the live DOM (document.*) must be updated with new output from the HTML parser in these situations (and possibly others):
1 Done reading HTML from a single packet
2 script tag found
3 document.write() call completed
So we need a way to query the parser's DOM state without calling done(), which prevents any further parsing.
This gist shows how peek() would be used in a simple case:
https://gist.github.com/849639/ec57b97213acb92b8a20e377d06cf1cffaf01e99
This is a more complex use case where we sync the DOM whenever a script tag appears:
https://gist.github.com/849639/dd05bcccefe82c0cc01d10c0ec54ce3f31bda4b8