Skip to content

ref: Refactor sources - #153

Open
loewenheim wants to merge 1 commit into
sebastian/parse-rangesfrom
sebastian/source
Open

loewenheim wants to merge 1 commit into
sebastian/parse-rangesfrom
sebastian/source

Conversation

@loewenheim

Copy link
Copy Markdown
Contributor

This refactors sources (original source files) in sourcemaps in several ways.

  • Name, content, and scopes are now stored together in a struct (RawSource) instead of separate vectors/maps.
  • There is a new type Source<'a> which represents a reference to a source file in a sourcemap. It has accessor methods for the name, contents, and scopes.
  • Various get_source/sources/… methods now return (iterators of) Source instead of just the source name. Because it's common, Token also has get_source_name which behaves like get_source used to.
  • get_source_contents/SourceContentsIter &c. are removed; source contents are now accessed via Source.

@loewenheim
loewenheim requested a review from a team December 3, 2026 12:50
Comment thread src/types/mod.rs
/// - `ignore_list` optional list of source indexes for devtools to ignore
pub fn new(
/// - `sources` a vector of sources (filenames, contents, and scopes)
pub(crate) fn new(

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm changing this constructor's signature and making it private. I don't think it was ever meaningfully usable outside of the crate; if we want a public way to construct SourceMap we should think of something better.

Comment thread src/decoder/mod.rs
None => None,
};

let name = name.map(Arc::from);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the type of name before the conversion here? &str?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

String. The RawSourceMap type uses String internally, though we could change that to Arc<str>.

Comment thread src/types/scope.rs
indices: &'a [usize],
pub(crate) sm: &'a SourceMap,
pub(crate) scopes: &'a [RawOriginalScope],
pub(crate) indices: &'a [usize],

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks leaky, why does the crate need access to the iterator's internals now? Can that access be replaced by a getter?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just for construction purposes. If you prefer I can refactor this to use a constructor function instead.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants