Skip to content

Commit

Permalink
feat(rust): don't generate sourcemap for virtual modules (#733)
Browse files Browse the repository at this point in the history
  • Loading branch information
underfin authored Apr 3, 2024
1 parent 06cf72d commit b546e8f
Show file tree
Hide file tree
Showing 10 changed files with 21 additions and 7 deletions.
2 changes: 1 addition & 1 deletion crates/rolldown/src/chunk/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ impl Chunk {
.expect_file()
.relative_path(&input_options.cwd)
.to_string_lossy().as_ref(),
!output_options.sourcemap.is_hidden()
!output_options.sourcemap.is_hidden() && !m.is_virtual
);
Some((
m.resource_id.expect_file().to_string(),
Expand Down
1 change: 1 addition & 0 deletions crates/rolldown/src/module_loader/normal_module_task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ impl<'task> NormalModuleTask<'task> {
module_type: self.module_type,
pretty_path: Some(self.resolved_path.prettify(&self.ctx.input_options.cwd)),
sourcemap_chain,
is_virtual: self.resolved_path.is_virtual_module_path(),
..Default::default()
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ impl RuntimeNormalModuleTask {
builder.namespace_symbol = Some(namespace_symbol);
builder.pretty_path = Some("<runtime>".to_string());
builder.is_user_defined_entry = Some(false);
builder.is_virtual = true;

if let Err(_err) = self.tx.send(Msg::RuntimeNormalModuleDone(RuntimeNormalModuleTaskResult {
warnings: self.warnings,
Expand Down
2 changes: 2 additions & 0 deletions crates/rolldown/src/types/normal_module_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ pub struct NormalModuleBuilder {
pub is_user_defined_entry: Option<bool>,
pub pretty_path: Option<String>,
pub sourcemap_chain: Vec<rolldown_sourcemap::SourceMap>,
pub is_virtual: bool,
}

impl NormalModuleBuilder {
Expand All @@ -54,6 +55,7 @@ impl NormalModuleBuilder {
pretty_path: self.pretty_path.unwrap(),
sourcemap_chain: self.sourcemap_chain,
is_included: false,
is_virtual: self.is_virtual,
}
}
}
1 change: 0 additions & 1 deletion crates/rolldown/tests/common/case.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,6 @@ impl Case {
self.snapshot.push_str("\n\n# Sourcemap Visualizer\n\n");
let visualizer_result = assets
.iter()
.filter(|asset| !asset.file_name().contains("$runtime$"))
.filter_map(|asset| match asset {
Output::Chunk(chunk) => chunk
.map
Expand Down
2 changes: 2 additions & 0 deletions crates/rolldown_common/src/module/normal_module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ pub struct NormalModule {
pub default_export_ref: SymbolRef,
pub sourcemap_chain: Vec<rolldown_sourcemap::SourceMap>,
pub is_included: bool,
// The runtime module and module which path starts with `\0` shouldn't generate sourcemap. Ref see https://github.com/rollup/rollup/blob/master/src/Module.ts#L279.
pub is_virtual: bool,
}

impl NormalModule {
Expand Down
10 changes: 10 additions & 0 deletions crates/rolldown_resolver/src/types/resolved_path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ impl ResolvedPath {
pretty
}
}

pub fn is_virtual_module_path(&self) -> bool {
self.path.starts_with('\0')
}
}

#[test]
Expand All @@ -56,3 +60,9 @@ fn test() {

assert_eq!(ignore_prettify_res, "(ignored) resolved_path.rs");
}

#[test]
fn is_virtual_module_path() {
assert!(ResolvedPath::from("\0a.js".to_string()).is_virtual_module_path());
assert!(!ResolvedPath::from("a.js".to_string()).is_virtual_module_path());
}
1 change: 0 additions & 1 deletion packages/rollup-tests/src/failed-tests.json
Original file line number Diff line number Diff line change
Expand Up @@ -712,7 +712,6 @@
"rollup@sourcemaps@basic-support: basic sourcemap support@generates es",
"rollup@sourcemaps@combined-sourcemap-with-loader: get combined sourcemap in transforming with loader@generates es",
"rollup@sourcemaps@combined-sourcemap: get combined sourcemap in transforming@generates es",
"rollup@sourcemaps@excludes-plugin-helpers: excludes plugin helpers from sources@generates es",
"rollup@sourcemaps@existing-external-sourcemaps-combined: removes sourcemap comments@generates es",
"rollup@sourcemaps@ignore-list-default: defaults to adding files within node_modules to the ignore list@generates es",
"rollup@sourcemaps@ignore-list-false: accepts false for `sourcemapIgnoreList` to disable the default ignore-listing of node_modules@generates es",
Expand Down
4 changes: 2 additions & 2 deletions packages/rollup-tests/src/status.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"failed": 0,
"skipFailed": 681,
"skipFailed": 680,
"skipped": 0,
"passed": 238
"passed": 239
}
4 changes: 2 additions & 2 deletions packages/rollup-tests/src/status.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
| | number |
|----| ---- |
| failed | 0|
| skipFailed | 681|
| skipFailed | 680|
| skipped | 0|
| passed | 238|
| passed | 239|

0 comments on commit b546e8f

Please sign in to comment.