oxc-project
oxc
BlogDocsChangelog

fix(codegen): correct `CRLF` handling in comment processing

#13169Merged
Comparing
copilot/fix-13059
(
8f533aa
) with
main
(
f10ac33
)
CodSpeed Performance Gauge
0%
Untouched
34

Benchmarks

Passed

minifier[cal.com.tsx]
tasks/benchmark/benches/minifier.rs::minifier::bench_minifier
CodSpeed Performance Gauge
+2%
30.8 ms30 ms
lexer[RadixUIAdoptionSection.jsx]
tasks/benchmark/benches/lexer.rs::lexer::bench_lexer
CodSpeed Performance Gauge
+1%
20 µs19.8 µs
transformer[cal.com.tsx]
tasks/benchmark/benches/transformer.rs::transformer::bench_transformer
CodSpeed Performance Gauge
+1%
26.4 ms26.3 ms
formatter[RadixUIAdoptionSection.jsx]
tasks/benchmark/benches/formatter.rs::formatter::bench_formatter
CodSpeed Performance Gauge
0%
343.7 µs342.8 µs
semantic[RadixUIAdoptionSection.jsx]
tasks/benchmark/benches/semantic.rs::semantic::bench_semantic
CodSpeed Performance Gauge
0%
77 µs76.9 µs
formatter[react.development.js]
tasks/benchmark/benches/formatter.rs::formatter::bench_formatter
CodSpeed Performance Gauge
0%
11.1 ms11.1 ms
semantic[react.development.js]
tasks/benchmark/benches/semantic.rs::semantic::bench_semantic
CodSpeed Performance Gauge
0%
1.7 ms1.7 ms
codegen[RadixUIAdoptionSection.jsx]
tasks/benchmark/benches/codegen.rs::codegen::bench_codegen
CodSpeed Performance Gauge
0%
119.9 µs119.8 µs
semantic[cal.com.tsx]
tasks/benchmark/benches/semantic.rs::semantic::bench_semantic
CodSpeed Performance Gauge
0%
27.9 ms27.9 ms
minifier[react.development.js]
tasks/benchmark/benches/minifier.rs::minifier::bench_minifier
CodSpeed Performance Gauge
0%
2.1 ms2.1 ms
linter[RadixUIAdoptionSection.jsx]
tasks/benchmark/benches/linter.rs::linter::bench_linter
CodSpeed Performance Gauge
0%
2.5 ms2.5 ms
lexer[react.development.js]
tasks/benchmark/benches/lexer.rs::lexer::bench_lexer
CodSpeed Performance Gauge
0%
356.8 µs356.6 µs
parser[react.development.js]
tasks/benchmark/benches/parser.rs::parser::bench_parser
CodSpeed Performance Gauge
0%
1.3 ms1.3 ms
isolated-declarations[vue-id.ts]
tasks/benchmark/benches/transformer.rs::transformer::bench_isolated_declarations
CodSpeed Performance Gauge
0%
57.3 ms57.3 ms
parser[binder.ts]
tasks/benchmark/benches/parser.rs::parser::bench_parser
CodSpeed Performance Gauge
0%
3.3 ms3.3 ms
parser[cal.com.tsx]
tasks/benchmark/benches/parser.rs::parser::bench_parser
CodSpeed Performance Gauge
0%
26.7 ms26.7 ms
lexer[binder.ts]
tasks/benchmark/benches/lexer.rs::lexer::bench_lexer
CodSpeed Performance Gauge
0%
870.2 µs870.1 µs
formatter[cal.com.tsx]
tasks/benchmark/benches/formatter.rs::formatter::bench_formatter
CodSpeed Performance Gauge
0%
179.4 ms179.4 ms
minifier[binder.ts]
tasks/benchmark/benches/minifier.rs::minifier::bench_minifier
CodSpeed Performance Gauge
0%
3.7 ms3.7 ms
linter[binder.ts]
tasks/benchmark/benches/linter.rs::linter::bench_linter
CodSpeed Performance Gauge
0%
146.6 ms146.6 ms
estree[checker.ts]
tasks/benchmark/benches/parser.rs::parser::bench_estree
CodSpeed Performance Gauge
0%
104.5 ms104.5 ms
lexer[cal.com.tsx]
tasks/benchmark/benches/lexer.rs::lexer::bench_lexer
CodSpeed Performance Gauge
0%
5.3 ms5.3 ms
linter[react.development.js]
tasks/benchmark/benches/linter.rs::linter::bench_linter
CodSpeed Performance Gauge
0%
52.3 ms52.3 ms
linter[cal.com.tsx]
tasks/benchmark/benches/linter.rs::linter::bench_linter
CodSpeed Performance Gauge
0%
1.2 s1.2 s
semantic[binder.ts]
tasks/benchmark/benches/semantic.rs::semantic::bench_semantic
CodSpeed Performance Gauge
0%
4.3 ms4.3 ms
codegen[react.development.js]
tasks/benchmark/benches/codegen.rs::codegen::bench_codegen
CodSpeed Performance Gauge
0%
1.9 ms1.9 ms
parser[RadixUIAdoptionSection.jsx]
tasks/benchmark/benches/parser.rs::parser::bench_parser
CodSpeed Performance Gauge
0%
83.7 µs83.7 µs
transformer[react.development.js]
tasks/benchmark/benches/transformer.rs::transformer::bench_transformer
CodSpeed Performance Gauge
0%
717.7 µs718.4 µs
transformer[binder.ts]
tasks/benchmark/benches/transformer.rs::transformer::bench_transformer
CodSpeed Performance Gauge
0%
1.7 ms1.7 ms
formatter[binder.ts]
tasks/benchmark/benches/formatter.rs::formatter::bench_formatter
CodSpeed Performance Gauge
0%
21.5 ms21.6 ms
codegen[cal.com.tsx]
tasks/benchmark/benches/codegen.rs::codegen::bench_codegen
CodSpeed Performance Gauge
0%
33.8 ms33.9 ms
codegen[binder.ts]
tasks/benchmark/benches/codegen.rs::codegen::bench_codegen
CodSpeed Performance Gauge
0%
4.1 ms4.1 ms
minifier[RadixUIAdoptionSection.jsx]
tasks/benchmark/benches/minifier.rs::minifier::bench_minifier
CodSpeed Performance Gauge
0%
58.3 µs58.5 µs
transformer[RadixUIAdoptionSection.jsx]
tasks/benchmark/benches/transformer.rs::transformer::bench_transformer
CodSpeed Performance Gauge
0%
133.2 µs133.7 µs

Commits

Click on a commit to change the comparison range
Base
main
f10ac33
+0.09%
fix(codegen): correct `CRLF` handling in comment processing (#13169) The oxc-transform's isolated declaration feature was incorrectly handling Windows line endings (`\r\n`) in comments, generating double newlines in the output. Consider: ```typescript import { isolatedDeclaration } from 'oxc-transform' console.log([ isolatedDeclaration('a.ts', // Simulates windows file line-ending. [ '/**', ' * Comment.', ' */', 'export const a: number = 1;' ].join('\r\n') ).code ]) // Before: [ '/**\n\n* Comment.\n\n*/\nexport declare const a: number;\n' ] // After: [ '/**\n* Comment.\n*/\nexport declare const a: number;\n' ] ``` ## Root Cause The issue was in the comment processing logic in `oxc_codegen/src/comment.rs`. The `split(is_line_terminator)` function treats both `\r` and `\n` as separate line terminators, causing `\r\n` sequences to split incorrectly with empty strings between them, leading to double newlines in the output. ## Solution Implemented an allocation-free approach using a custom `LineTerminatorSplitter` iterator that: 1. Handles CRLF sequences correctly by treating `\r\n` as a single line terminator 2. Eliminates performance overhead from string allocations during comment processing 3. Processes line terminators on-demand without creating temporary strings This approach provides better performance compared to the previous normalization function while correctly handling Windows line endings. ## Additional Changes - Converted all single-line block comments (`/** comment */`) to multiline format in test fixtures to better verify the CRLF fix - Updated corresponding test snapshots to reflect the improved comment formatting ## Testing - Added comprehensive tests covering Windows line endings, mixed line endings, and standalone CR handling - All existing tests continue to pass (codegen, isolated declarations, transform) - Verified the exact reproduction case from the issue works correctly - Confirmed zero allocation overhead in comment processing Fixes #13059. <!-- START COPILOT CODING AGENT TIPS --> --- 💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click [here](https://survey.alchemer.com/s3/8343779/Copilot-Coding-agent) to start the survey.
8f533aa
3 months ago
by Copilot
© 2025 CodSpeed Technology
Home Terms Privacy Docs