Repository navigation
Conversation
This adds the code for formatting JS source code. Nothing uses it yet; the source views will use it to pretty-print minified code. The formatter is based on the Lezer syntax tree and only changes the whitespace between tokens. It describes the result as a buffer of whitespace edits instead of a string, which keeps the mapping between the original and the formatted positions simple. It parses the code incrementally and reports the edits after each step, so that a caller can show partially-formatted code while the formatting is in progress. The formatter runs in a new worker, format.worker.js, which is built like the source map worker. The worker sends back the edits, and applyFormatEdits builds the formatted code on the main thread as an array of lines, which are mostly slices of the original code. The Lezer dialect helpers move from scope-tree.ts to a new module that doesn't import the parser, so that the main bundle can use them.
Both the source view and the generated source view get a {} toggle
button for JavaScript sources. The URL records it with the
sourceViewPretty and generatedSourceViewPretty parameters.
Once the code of a pretty-printed source is available, the source is
formatted in the format worker. The edits of each formatting step go
into a new cache in the code state, so the view shows
partially-formatted code while the worker is busy. The source view
passes the formatted lines to CodeMirror as an array instead of one
string.
The line timings use the columns of the frames to find the formatted
line for each sample, because minified code often has very long lines.
For the same reason, the bottom box now also records the column of the
line to scroll to and of the highlighted line.
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #6433 +/- ##
========================================
Coverage 84.79% 84.79%
========================================
Files 358 365 +7
Lines 38970 39538 +568
Branches 11028 11225 +197
========================================
+ Hits 33044 33528 +484
- Misses 5490 5574 +84
Partials 436 436 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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.
Main | Deploy preview
This adds a {} button to format minified JS source in the source view.