Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions compiler/crates/react_compiler_swc/src/convert_ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,16 +196,19 @@ impl<'a> ConvertCtx<'a> {
}
}

/// `BytePos` is 1-based; emit 0-based `loc` to match Babel.
/// (`BaseNode.start`/`end` stays 1-based: `convert_scope` keys on it.)
fn position(&self, offset: u32) -> Position {
let line_idx = match self.line_offsets.binary_search(&offset) {
let zero_based = offset.saturating_sub(1);
let line_idx = match self.line_offsets.binary_search(&zero_based) {
Ok(idx) => idx,
Err(idx) => idx.saturating_sub(1),
};
let line_start = self.line_offsets[line_idx];
Position {
line: (line_idx as u32) + 1,
column: offset - line_start,
index: Some(offset),
column: zero_based - line_start,
index: Some(zero_based),
}
}

Expand Down
4 changes: 1 addition & 3 deletions compiler/scripts/test-e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -484,11 +484,9 @@ async function runVariant(
for (let i = 0; i < fixtureInfos.length; i++) {
const {fixturePath, relPath, source, firstLine, isFlow} = fixtureInfos[i];
const tsCode = tsBaselines.get(fixturePath)!;
// TS baseline uses Babel (0-based columns), no adjustment needed
// All variants emit 0-based columns/indices.
oneBasedColumns = false;
const tsEvents = normalizeEvents(tsRawEvents.get(fixturePath)!);
// SWC uses 1-based columns/indices (BytePos); OXC is 0-based like Babel
oneBasedColumns = variant === 'swc';

writeProgress(
` ${variant}: ${i + 1}/${fixtureInfos.length} (${s.passed} passed, ${s.failed} failed)`,
Expand Down
Loading