Skip to content

Commit

Permalink
oxc_sourcemaps
Browse files Browse the repository at this point in the history
  • Loading branch information
topheman committed Oct 26, 2024
1 parent 727f20c commit c4f5090
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
29 changes: 29 additions & 0 deletions src/oxc/explore.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,33 @@

<https://github.com/oxc-project/oxc>

## oxc_codegen

See more about sourcemaps on [oxc::oxc_sourcemaps](#oxc_sourcemap).

<a href="https://github.com/oxc-project/oxc/blob/main/crates/oxc_codegen/src/lib.rs" title="Source Code of oxc_codegen">📄</a>

## oxc_sourcemap

> The sourcemap implement port from [rust-sourcemap](https://github.com/getsentry/rust-sourcemap), but has some different with it.
>
> Encode sourcemap at parallel, including quote sourceContent and encode token to vlq mappings.
> Avoid Sourcemap some methods overhead, like SourceMap::tokens().
The main interface for creating sourcemaps from existing files seems to be [`oxc::oxc_codegen::CodeGen::new().enable_source_map(&filename, &source_text).build()`](https://github.com/oxc-project/oxc/blob/main/crates/oxc_codegen/src/lib.rs) (or any other options allowed by the builder pattern).

### Understand the relation about SourceMap between oxc_codegen and oxc_sourcemap

- [`oxc::oxc_codegen::SourcemapBuilder`](https://github.com/oxc-project/oxc/blob/main/crates/oxc_codegen/src/sourcemap_builder.rs) vs [`oxc::oxc_sourcemap::SourceMapBuilder`](https://github.com/oxc-project/oxc/blob/main/crates/oxc_sourcemap/src/sourcemap_builder.rs) (map vs Map - may be a typo ?)
- [`oxc::oxc_codegen::Codegen`](https://github.com/oxc-project/oxc/blob/main/crates/oxc_codegen/src/lib.rs) contains a field `sourcemap_builder`: [`Option<oxc::oxc_codegen::SourcemapBuilder>`](https://github.com/oxc-project/oxc/blob/main/crates/oxc_codegen/src/sourcemap_builder.rs)
- `oxc::oxc_codegen::SourcemapBuilder` contains a field `sourcemap_builder`: [`oxc::oxc_sourcemap::SourceMapBuilder`](https://github.com/oxc-project/oxc/blob/main/crates/oxc_sourcemap/src/sourcemap_builder.rs)
- `oxc::oxc_codegen::SourcemapBuilder` has `into_sourcemap(self) -> oxc::oxc_sourcemap::SourceMap`, which calls:
- `oxc::oxc_sourcemap::SourceMapBuilder` with `into_sourcemap(self) -> SourceMap`

See more in [`oxc::oxc_codegen`](#oxc_codegen).

<a href="https://github.com/oxc-project/oxc/blob/main/crates/oxc_sourcemap" title="Source Code of oxc_sourcemap">📄</a>

## oxc_span

[`oxc::oxc_span::span::types`](https://github.com/oxc-project/oxc/blob/main/crates/oxc_span/src/span/types.rs)
Expand All @@ -14,3 +41,5 @@ let text = "foo bar baz";
let span = Span::new(4, 7);
assert_eq!(&text[span], "bar");
```

<a href="https://github.com/oxc-project/oxc/blob/main/crates/oxc_span/src/lib.rs" title="Source Code of oxc_span">📄</a>
6 changes: 5 additions & 1 deletion src/rolldown/explore-shared.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,10 @@ Exposes `rolldown_rstr::Rstr` which is a thin wrapper over [`oxc::span::CompactS

## rolldown_sourcemap

Exposes `collapse_sourcemaps(mut sourcemap_chain: Vec<&SourceMap>) -> SourceMap`.
Exposes [`collapse_sourcemaps(mut sourcemap_chain: Vec<&SourceMap>) -> SourceMap`](https://github.com/rolldown/rolldown/blob/main/crates/rolldown_sourcemap/src/lib.rs).

It collapses multiple sourcemaps generated by calls to `oxc::oxc_codegen::CodeGen::new().enable_source_map(&filename, &source_text).build()` into one giant sourcemap.

Relies on [`oxc::sourcemap::*`](https://github.com/oxc-project/oxc/tree/main/crates/oxc_sourcemap).

<a href="https://github.com/rolldown/rolldown/tree/main/crates/rolldown_sourcemap" title="Source Code of rolldown_sourcemap">📄</a>

0 comments on commit c4f5090

Please sign in to comment.