Repository navigation
refactor(formatter)!: replace TabIfBreak with standard indentation - #1822
magic-akari wants to merge 3 commits into
Conversation
The Prettier plugin decoded TabIfBreak as a literal tab, so the two printers could wrap the first union member at different columns. Use a named group to measure the conditional type head at print time and apply indentIfBreak to the line after the tuple comma. Remove Writer::tab_indent_if_break, the printer special case, and opcode 30 from the SWCD codecs.
Deploying swc-next with
|
| Latest commit: |
c15b044
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://a66198b7.swc-next.pages.dev |
| Branch Preview URL: | https://refactor-tuple-union-indent.swc-next.pages.dev |
Binary size diffLinux x64 GNU · release · uncompressed, stripped bindings. Merge:
|
Gungraun benchmark diffBase SHA: f6f4151 Values are shown as Download the raw Gungraun and Valgrind data (retained for 90 days). Callgrind metric changesCallgrind instruction counts (Ir) for the compare and base revisions. Values are shown as compare / base in K (1,000), truncated to whole thousands. Multi-part profiles use the part numbers from Gungraun and include an aggregated Total. New and Removed identify benchmarks that exist on only one side; the missing value is shown as a dash. Percentages are rounded to at most three decimal places. Lower is better: 🟢 improvement, 🔴 regression, ⚪ unchanged. Formatter
Generator
Minifier
Parser
Semantic
Transform
Type strip
Visit
Benchmark results |
JavaScript API Gungraun benchmark diffBase: Values are shown as Download the raw Gungraun and Valgrind data (retained for 90 days). Callgrind metric changesMedian instruction counts from three processes, shown as compare / base in K (1,000), truncated to whole thousands. Percentages are rounded to at most three decimal places. Lower is better: 🟢 improvement, 🔴 regression, ⚪ unchanged or overlapping ranges (inconclusive). JIT disabled (--jitless); predictable mode enabled (--predictable). Counts are not wall time. Exact counts, ranges and profiles are retained in artifacts. Generate
Lang
Parse
Source type
Walk
Benchmark resultsExact instruction counts: median (min–max).
|
Tuples were scanned twice to find conditional types with union checks, even when no separator needed conditional indentation. Detect those checks while formatting each member. When a separator needs indentIfBreak, insert its measurement group before the first member so the printer can resolve the group before it reaches the separator.
Tuple formatting can discover a measurement group after writing earlier members. Keeping a content marker across Writer calls required the tuple formatter to track where the marker was valid. Let write_with_optional_prefix own that position. Write the opening line before entering the scope and prepend measurement groups only when a later tuple member needs conditional indentation.
Codex Review Summary: ❌ FailedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. |
Motivation
SWC used
TabIfBreakto indent the first|when a union wraps inside a TypeScript tuple. The Prettier plugin decoded it asifBreak("\t"), so the two printers measured the same line differently. At a print width of 14, SWC broke afterRef<while Prettier keptRef<A, B>on one line.Changes
indentIfBreakto the line break after the tuple comma. A named group lets the printer decide whether the conditional type head fits and indent the first|using the active tab or space settings.Writer::tab_indent_if_break, its printer special case, and SWCD opcode30from the Rust codec and JS decoder. Rust callers can wrap the preceding line break inWriter::indent_if_break.