Skip to content

Commit

Permalink
feat: support SourceMapBuilder#token_chunks
Browse files Browse the repository at this point in the history
  • Loading branch information
underfin committed Jul 12, 2024
1 parent 05b9a73 commit 24dec16
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
2 changes: 1 addition & 1 deletion crates/oxc_sourcemap/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ pub use error::Error;
pub use sourcemap::SourceMap;
pub use sourcemap_builder::SourceMapBuilder;
pub use sourcemap_visualizer::SourcemapVisualizer;
pub use token::{SourceViewToken, Token};
pub use token::{SourceViewToken, Token, TokenChunk};
13 changes: 11 additions & 2 deletions crates/oxc_sourcemap/src/sourcemap_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ use std::sync::Arc;

use rustc_hash::FxHashMap;

use crate::{token::Token, SourceMap};
use crate::{
token::{Token, TokenChunk},
SourceMap,
};

/// The `SourceMapBuilder` is a helper to generate sourcemap.
#[derive(Debug, Default)]
Expand All @@ -14,6 +17,7 @@ pub struct SourceMapBuilder {
pub(crate) sources_map: FxHashMap<Arc<str>, u32>,
pub(crate) source_contents: Vec<Arc<str>>,
pub(crate) tokens: Vec<Token>,
pub(crate) token_chunks: Option<Vec<TokenChunk>>,
}

#[allow(clippy::cast_possible_truncation)]
Expand Down Expand Up @@ -66,6 +70,11 @@ impl SourceMapBuilder {
self.file = Some(file.into());
}

/// Set the `SourceMap::token_chunks` to make the sourcemap to vlq mapping at parallel.
pub fn set_token_chunks(&mut self, token_chunks: Vec<TokenChunk>) {
self.token_chunks = Some(token_chunks);
}

pub fn into_sourcemap(self) -> SourceMap {
SourceMap::new(
self.file,
Expand All @@ -74,7 +83,7 @@ impl SourceMapBuilder {
self.sources,
Some(self.source_contents),
self.tokens,
None,
self.token_chunks,
)
}
}
Expand Down

0 comments on commit 24dec16

Please sign in to comment.