Skip to content

Add a pretty-print toggle button - #6433

Draft
mstange wants to merge 2 commits into
firefox-devtools:mainfrom
mstange:push-opoyyxmxnwvx
Draft

mstange wants to merge 2 commits into
firefox-devtools:mainfrom
mstange:push-opoyyxmxnwvx

Conversation

@mstange

@mstange mstange commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

Main | Deploy preview

This adds a {} button to format minified JS source in the source view.

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

codecov Bot commented Oct 29, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 85.52189% with 86 lines in your changes missing coverage. Please review.
✅ Project coverage is 84.79%. Comparing base (fdce9b9) to head (dda6c5c).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
src/profile-logic/js-format/formatter.ts 92.88% 17 Missing ⚠️
src/profile-logic/js-format/run-format-worker.ts 0.00% 15 Missing ⚠️
src/profile-logic/line-timings.ts 76.92% 12 Missing ⚠️
src/components/app/BottomBox.tsx 44.44% 10 Missing ⚠️
src/actions/code.ts 58.82% 7 Missing ⚠️
src/components/app/PrettyPrintToggleButton.tsx 0.00% 7 Missing ⚠️
src/components/shared/SourceView.tsx 66.66% 5 Missing ⚠️
src/reducers/code.ts 84.37% 5 Missing ⚠️
src/components/app/SourceFormatter.tsx 75.00% 3 Missing ⚠️
src/profile-logic/bottom-box.ts 50.00% 3 Missing ⚠️
... and 2 more
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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant