diff --git a/crates/rolldown/src/bundler/bundle/bundle.rs b/crates/rolldown/src/bundler/bundle/bundle.rs index d709cba0212..f8c72f4edaa 100644 --- a/crates/rolldown/src/bundler/bundle/bundle.rs +++ b/crates/rolldown/src/bundler/bundle/bundle.rs @@ -70,6 +70,13 @@ impl<'a> Bundle<'a> { for stmt_info in module.stmt_infos.iter().chain(linking_info.facade_stmt_infos.iter()) { for declared in &stmt_info.declared_symbols { + // TODO: pass debug_assert!(self.graph.symbols.get(*declared).chunk_id.is_none()); + // FIXME: I don't think this is correct, even though the assigned chunk_id is the same as the current chunk_id. + // A declared symbol should only be processed once. + debug_assert!( + self.graph.symbols.get(*declared).chunk_id.unwrap_or(chunk_id) == chunk_id + ); + self.graph.symbols.get_mut(*declared).chunk_id = Some(chunk_id); } @@ -98,11 +105,13 @@ impl<'a> Bundle<'a> { } } } - for (chunk_id, chunk) in chunk_graph.chunks.iter_mut_enumerated() { let chunk_meta_imports = &chunk_meta_imports_vec[chunk_id]; for import_ref in chunk_meta_imports.iter().copied() { - let importee_chunk_id = self.graph.symbols.get(import_ref).chunk_id.unwrap(); + let import_symbol = self.graph.symbols.get(import_ref); + let importee_chunk_id = import_symbol.chunk_id.unwrap_or_else(|| { + panic!("symbol {import_ref:?} {import_symbol:?} is not assigned to any chunk") + }); if chunk_id != importee_chunk_id { chunk .imports_from_other_chunks @@ -168,6 +177,14 @@ impl<'a> Bundle<'a> { FxHashMap::with_capacity_and_hasher(self.graph.entries.len(), BuildHasherDefault::default()); let mut chunks = ChunksVec::with_capacity(self.graph.entries.len()); + // FIXME: should only do this while `ROLLDOWN_TEST=1` + let _runtime_chunk_id = chunks.push(Chunk::new( + Some("_rolldown_runtime".to_string()), + None, + BitSet::new(0), + vec![self.graph.runtime.id], + )); + // Create chunk for each static and dynamic entry for (entry_index, (name, module_id)) in self.graph.entries.iter().enumerate() { let count: u32 = u32::try_from(entry_index).unwrap(); diff --git a/crates/rolldown/src/bundler/chunk/render_chunk_imports.rs b/crates/rolldown/src/bundler/chunk/render_chunk_imports.rs index 9755aad31eb..7fb92502b88 100644 --- a/crates/rolldown/src/bundler/chunk/render_chunk_imports.rs +++ b/crates/rolldown/src/bundler/chunk/render_chunk_imports.rs @@ -31,7 +31,7 @@ impl Chunk { .collect::>(); import_items.sort(); s.append(format!( - "import {{ {} }} from \"./{}\";", + "import {{ {} }} from \"./{}\";\n", import_items.join(", "), chunk.file_name.as_ref().unwrap() )); diff --git a/crates/rolldown/src/bundler/graph/linker.rs b/crates/rolldown/src/bundler/graph/linker.rs index 18311d2da61..8b1e141884f 100644 --- a/crates/rolldown/src/bundler/graph/linker.rs +++ b/crates/rolldown/src/bundler/graph/linker.rs @@ -160,6 +160,9 @@ impl<'graph> Linker<'graph> { linking_infos: &mut LinkingInfoVec, ) { let linking_info = &mut linking_infos[target]; + if let Module::Normal(module) = &self.graph.modules[target] { + module.initialize_namespace(linking_info); + } if linking_info.wrap_symbol.is_some() { return; } @@ -170,6 +173,7 @@ impl<'graph> Linker<'graph> { match &self.graph.modules[target] { Module::Normal(module) => { module.create_wrap_symbol(linking_info, symbols); + let name = if module.exports_kind == ExportsKind::CommonJs { "__commonJS".into() } else { @@ -187,13 +191,25 @@ impl<'graph> Linker<'graph> { #[allow(clippy::needless_collect)] fn mark_extra_symbols(&mut self, symbols: &mut Symbols, linking_infos: &mut LinkingInfoVec) { - for id in &self.graph.sorted_modules { - let importer = &self.graph.modules[*id]; + // Determine if the namespace symbol need to be generated + for importer_id in &self.graph.sorted_modules { + let importer = &self.graph.modules[*importer_id]; + + if let Module::Normal(importer) = importer { + let has_reexport_all_from_cjs = importer.get_star_exports_modules().any(|importee| matches!(&self.graph.modules[importee], Module::Normal(m) if m.exports_kind == ExportsKind::CommonJs)); + if has_reexport_all_from_cjs { + self.graph.modules[*importer_id] + .mark_symbol_for_namespace_referenced(&mut linking_infos[*importer_id]); + } + } + importer .import_records() .iter() .filter_map(|rec| { - (rec.is_import_namespace && rec.resolved_module.is_valid()).then_some(rec.resolved_module) + ((rec.is_import_namespace || matches!(rec.kind, ImportKind::Require)) + && rec.resolved_module.is_valid()) + .then_some(rec.resolved_module) }) .for_each(|importee| { self.graph.modules[importee] diff --git a/crates/rolldown/src/bundler/graph/symbols.rs b/crates/rolldown/src/bundler/graph/symbols.rs index 6f371881cf7..25bb4fc935e 100644 --- a/crates/rolldown/src/bundler/graph/symbols.rs +++ b/crates/rolldown/src/bundler/graph/symbols.rs @@ -76,6 +76,19 @@ impl Symbols { Self { inner, references_table: reference_table } } + pub fn create_facade_symbol(&mut self, owner: ModuleId) -> SymbolRef { + let symbol_id = self.inner[owner].push(Symbol { + // name is meaningless for facade symbols + name: Atom::new_inline("#FACADE#"), + link: None, + chunk_id: None, + namespace_alias: None, + }); + let symbol_ref = SymbolRef { owner, symbol: symbol_id }; + self.references_table[owner].push(Some(symbol_id)); + symbol_ref + } + pub fn create_symbol(&mut self, owner: ModuleId, name: Atom) -> SymbolRef { let symbol_id = self.inner[owner].push(Symbol { name, link: None, chunk_id: None, namespace_alias: None }); diff --git a/crates/rolldown/src/bundler/module/normal_module.rs b/crates/rolldown/src/bundler/module/normal_module.rs index 0e3e0f74f49..34e6ac782db 100644 --- a/crates/rolldown/src/bundler/module/normal_module.rs +++ b/crates/rolldown/src/bundler/module/normal_module.rs @@ -333,14 +333,25 @@ impl NormalModule { pub fn generate_symbol_import_and_use( &self, - symbol_ref_from_importee: SymbolRef, + other_module_symbol_ref: SymbolRef, self_linking_info: &mut LinkingInfo, symbols: &mut Symbols, ) { - debug_assert!(symbol_ref_from_importee.owner != self.id); - let name = symbols.get_original_name(symbol_ref_from_importee).clone(); - let local_symbol_ref = self.generate_local_symbol(name, self_linking_info, symbols); - symbols.union(local_symbol_ref, symbol_ref_from_importee); + debug_assert!(other_module_symbol_ref.owner != self.id); + // Create a facade symbol belongs to the self module. + let facade_ref = symbols.create_facade_symbol(self.id); + // The facade symbol is used to reference the symbol from the other module. + symbols.union(facade_ref, other_module_symbol_ref); + + self_linking_info.facade_stmt_infos.push(StmtInfo { + // Since the facade symbol is created, it should be declared. This will be used to + // 1. de-conflict the symbol in the de-conflict pass + declared_symbols: vec![facade_ref], + // Since the facade symbol is used, it should be referenced. This will be used to + // create correct cross-chunk links + referenced_symbols: vec![facade_ref], + ..Default::default() + }); } pub fn generate_local_symbol( diff --git a/crates/rolldown/src/bundler/visitors/mod.rs b/crates/rolldown/src/bundler/visitors/mod.rs index 26246ef0f2f..a40ca7a3043 100644 --- a/crates/rolldown/src/bundler/visitors/mod.rs +++ b/crates/rolldown/src/bundler/visitors/mod.rs @@ -39,11 +39,8 @@ impl<'ast> RendererContext<'ast> { ) -> Self { let wrap_symbol_name = linking_info.wrap_symbol.and_then(|s| get_symbol_final_name(s, &graph.symbols, final_names)); - let namespace_symbol_name = get_symbol_final_name( - (module.id, module.namespace_symbol.symbol).into(), - &graph.symbols, - final_names, - ); + let namespace_symbol_name = + get_symbol_final_name(module.namespace_symbol, &graph.symbols, final_names); let default_symbol_name = module .default_export_symbol .and_then(|s| get_symbol_final_name((module.id, s).into(), &graph.symbols, final_names)); @@ -266,9 +263,7 @@ impl<'ast> RendererContext<'ast> { if importee.exports_kind == ExportsKind::CommonJs { self.source.update(expr.span.start, expr.span.end, format!("{wrap_symbol_name}()")); } else { - let namespace_name = self - .get_symbol_final_name((importee.id, importee.namespace_symbol.symbol).into()) - .unwrap(); + let namespace_name = self.get_symbol_final_name(importee.namespace_symbol).unwrap(); let to_commonjs_runtime_symbol_name = self.get_runtime_symbol_final_name(&"__toCommonJS".into()); self.source.update( diff --git a/crates/rolldown/tests/common/case.rs b/crates/rolldown/tests/common/case.rs index a17fe3b2f11..d2bc7efbece 100644 --- a/crates/rolldown/tests/common/case.rs +++ b/crates/rolldown/tests/common/case.rs @@ -27,6 +27,8 @@ impl Case { assets.sort_by_key(|c| c.file_name.clone()); assets .iter() + // FIXME: should render the runtime module while tree shaking being supported + .filter(|asset| !asset.file_name.contains("rolldown_runtime")) .flat_map(|asset| { [ Cow::Owned(format!("# {}\n", asset.file_name)), diff --git a/crates/rolldown/tests/esbuild/default/common_js_from_es6/artifacts.snap b/crates/rolldown/tests/esbuild/default/common_js_from_es6/artifacts.snap index 17e4343c5ee..c2596d235ab 100644 --- a/crates/rolldown/tests/esbuild/default/common_js_from_es6/artifacts.snap +++ b/crates/rolldown/tests/esbuild/default/common_js_from_es6/artifacts.snap @@ -6,6 +6,8 @@ input_file: crates/rolldown/tests/esbuild/default/common_js_from_es6 # entry_js.js ```js +import { __esm, __toCommonJS } from "./_rolldown_runtime.js"; + // bar.js function bar$1() { return 'bar' diff --git a/crates/rolldown/tests/esbuild/default/empty_export_clause_bundle_as_common_js_issue910/artifacts.snap b/crates/rolldown/tests/esbuild/default/empty_export_clause_bundle_as_common_js_issue910/artifacts.snap index d3dba596e95..dbc16091a0d 100644 --- a/crates/rolldown/tests/esbuild/default/empty_export_clause_bundle_as_common_js_issue910/artifacts.snap +++ b/crates/rolldown/tests/esbuild/default/empty_export_clause_bundle_as_common_js_issue910/artifacts.snap @@ -6,6 +6,8 @@ input_file: crates/rolldown/tests/esbuild/default/empty_export_clause_bundle_as_ # entry_js.js ```js +import { __esm, __toCommonJS } from "./_rolldown_runtime.js"; + // types.mjs var types_ns = { diff --git a/crates/rolldown/tests/esbuild/default/es6_from_common_js/artifacts.snap b/crates/rolldown/tests/esbuild/default/es6_from_common_js/artifacts.snap index 6e88954e86a..87fc7997605 100644 --- a/crates/rolldown/tests/esbuild/default/es6_from_common_js/artifacts.snap +++ b/crates/rolldown/tests/esbuild/default/es6_from_common_js/artifacts.snap @@ -6,6 +6,8 @@ input_file: crates/rolldown/tests/esbuild/default/es6_from_common_js # entry_js.js ```js +import { __commonJS, __toESM } from "./_rolldown_runtime.js"; + // bar.js var require_bar = __commonJS({ 'bar.js'(exports, module) { diff --git a/crates/rolldown/tests/esbuild/default/export_forms_common_js/artifacts.snap b/crates/rolldown/tests/esbuild/default/export_forms_common_js/artifacts.snap index e28e360bd2f..415b8beb279 100644 --- a/crates/rolldown/tests/esbuild/default/export_forms_common_js/artifacts.snap +++ b/crates/rolldown/tests/esbuild/default/export_forms_common_js/artifacts.snap @@ -6,6 +6,8 @@ input_file: crates/rolldown/tests/esbuild/default/export_forms_common_js # entry_js.js ```js +import { __esm, __toCommonJS } from "./_rolldown_runtime.js"; + // h.js async function foo$1() {} var h_ns = { diff --git a/crates/rolldown/tests/esbuild/default/import_missing_common_js/artifacts.snap b/crates/rolldown/tests/esbuild/default/import_missing_common_js/artifacts.snap index 8e01051851b..777d30bcdbf 100644 --- a/crates/rolldown/tests/esbuild/default/import_missing_common_js/artifacts.snap +++ b/crates/rolldown/tests/esbuild/default/import_missing_common_js/artifacts.snap @@ -6,6 +6,8 @@ input_file: crates/rolldown/tests/esbuild/default/import_missing_common_js # entry_js.js ```js +import { __commonJS, __toESM } from "./_rolldown_runtime.js"; + // foo.js var require_foo = __commonJS({ 'foo.js'(exports, module) { diff --git a/crates/rolldown/tests/esbuild/default/nested_common_js/artifacts.snap b/crates/rolldown/tests/esbuild/default/nested_common_js/artifacts.snap index 82495c603a7..a9c253d8f12 100644 --- a/crates/rolldown/tests/esbuild/default/nested_common_js/artifacts.snap +++ b/crates/rolldown/tests/esbuild/default/nested_common_js/artifacts.snap @@ -6,6 +6,8 @@ input_file: crates/rolldown/tests/esbuild/default/nested_common_js # entry_js.js ```js +import { __commonJS, __toESM } from "./_rolldown_runtime.js"; + // foo.js var require_foo = __commonJS({ 'foo.js'(exports, module) { diff --git a/crates/rolldown/tests/esbuild/default/nested_es6_from_common_js/artifacts.snap b/crates/rolldown/tests/esbuild/default/nested_es6_from_common_js/artifacts.snap index fa9e9523677..9241f01897e 100644 --- a/crates/rolldown/tests/esbuild/default/nested_es6_from_common_js/artifacts.snap +++ b/crates/rolldown/tests/esbuild/default/nested_es6_from_common_js/artifacts.snap @@ -6,6 +6,8 @@ input_file: crates/rolldown/tests/esbuild/default/nested_es6_from_common_js # entry_js.js ```js +import { __commonJS, __toESM } from "./_rolldown_runtime.js"; + // foo.js var require_foo = __commonJS({ 'foo.js'(exports, module) { diff --git a/crates/rolldown/tests/esbuild/default/new_expression_common_js/artifacts.snap b/crates/rolldown/tests/esbuild/default/new_expression_common_js/artifacts.snap index a8c2681a5a8..18b8463000c 100644 --- a/crates/rolldown/tests/esbuild/default/new_expression_common_js/artifacts.snap +++ b/crates/rolldown/tests/esbuild/default/new_expression_common_js/artifacts.snap @@ -6,6 +6,8 @@ input_file: crates/rolldown/tests/esbuild/default/new_expression_common_js # entry_js.js ```js +import { __commonJS, __toESM } from "./_rolldown_runtime.js"; + // foo.js var require_foo = __commonJS({ 'foo.js'(exports, module) { diff --git a/crates/rolldown/tests/esbuild/default/re_export_common_js_as_es6/artifacts.snap b/crates/rolldown/tests/esbuild/default/re_export_common_js_as_es6/artifacts.snap index e7abf3e47bc..f1fbdf89ff0 100644 --- a/crates/rolldown/tests/esbuild/default/re_export_common_js_as_es6/artifacts.snap +++ b/crates/rolldown/tests/esbuild/default/re_export_common_js_as_es6/artifacts.snap @@ -6,6 +6,8 @@ input_file: crates/rolldown/tests/esbuild/default/re_export_common_js_as_es6 # entry_js.js ```js +import { __commonJS, __toESM } from "./_rolldown_runtime.js"; + // foo.js var require_foo = __commonJS({ 'foo.js'(exports, module) { diff --git a/crates/rolldown/tests/esbuild/default/require_child_dir_common_js/artifacts.snap b/crates/rolldown/tests/esbuild/default/require_child_dir_common_js/artifacts.snap index 7cac8b5c505..1bf2118482e 100644 --- a/crates/rolldown/tests/esbuild/default/require_child_dir_common_js/artifacts.snap +++ b/crates/rolldown/tests/esbuild/default/require_child_dir_common_js/artifacts.snap @@ -6,6 +6,8 @@ input_file: crates/rolldown/tests/esbuild/default/require_child_dir_common_js # entry_js.js ```js +import { __commonJS, __toESM } from "./_rolldown_runtime.js"; + // dir/index.js var require_dir_index = __commonJS({ 'dir/index.js'(exports, module) { diff --git a/crates/rolldown/tests/esbuild/default/require_parent_dir_common_js/artifacts.snap b/crates/rolldown/tests/esbuild/default/require_parent_dir_common_js/artifacts.snap index 55add61af7e..3bd26c63c74 100644 --- a/crates/rolldown/tests/esbuild/default/require_parent_dir_common_js/artifacts.snap +++ b/crates/rolldown/tests/esbuild/default/require_parent_dir_common_js/artifacts.snap @@ -6,6 +6,8 @@ input_file: crates/rolldown/tests/esbuild/default/require_parent_dir_common_js # dir_entry_js.js ```js +import { __commonJS, __toESM } from "./_rolldown_runtime.js"; + // index.js var require_require_parent_dir_common_js_index = __commonJS({ 'index.js'(exports, module) { diff --git a/crates/rolldown/tests/esbuild/default/require_with_call_inside_try/artifacts.snap b/crates/rolldown/tests/esbuild/default/require_with_call_inside_try/artifacts.snap index da637b12597..cf14d795119 100644 --- a/crates/rolldown/tests/esbuild/default/require_with_call_inside_try/artifacts.snap +++ b/crates/rolldown/tests/esbuild/default/require_with_call_inside_try/artifacts.snap @@ -6,6 +6,8 @@ input_file: crates/rolldown/tests/esbuild/default/require_with_call_inside_try # entry_js.js ```js +import { __commonJS } from "./_rolldown_runtime.js"; + // entry.js var require_entry = __commonJS({ 'entry.js'(exports, module) { diff --git a/crates/rolldown/tests/esbuild/default/simple_common_js/artifacts.snap b/crates/rolldown/tests/esbuild/default/simple_common_js/artifacts.snap index aa98757d8fe..13df5e7d480 100644 --- a/crates/rolldown/tests/esbuild/default/simple_common_js/artifacts.snap +++ b/crates/rolldown/tests/esbuild/default/simple_common_js/artifacts.snap @@ -6,6 +6,8 @@ input_file: crates/rolldown/tests/esbuild/default/simple_common_js # entry_js.js ```js +import { __commonJS, __toESM } from "./_rolldown_runtime.js"; + // foo.js var require_foo = __commonJS({ 'foo.js'(exports, module) { diff --git a/crates/rolldown/tests/esbuild/default/use_strict_directive_bundle_issue1837/artifacts.snap b/crates/rolldown/tests/esbuild/default/use_strict_directive_bundle_issue1837/artifacts.snap index 5856820e4dd..f782c7aff44 100644 --- a/crates/rolldown/tests/esbuild/default/use_strict_directive_bundle_issue1837/artifacts.snap +++ b/crates/rolldown/tests/esbuild/default/use_strict_directive_bundle_issue1837/artifacts.snap @@ -6,6 +6,8 @@ input_file: crates/rolldown/tests/esbuild/default/use_strict_directive_bundle_is # entry_js.js ```js +import { __commonJS, __toESM } from "./_rolldown_runtime.js"; + // cjs.js var require_cjs = __commonJS({ 'cjs.js'(exports, module) { diff --git a/crates/rolldown/tests/esbuild/import_star/import_namespace_undefined_property_side_effect_free_file/artifacts.snap b/crates/rolldown/tests/esbuild/import_star/import_namespace_undefined_property_side_effect_free_file/artifacts.snap index 5b5212483c9..78850b1fbb9 100644 --- a/crates/rolldown/tests/esbuild/import_star/import_namespace_undefined_property_side_effect_free_file/artifacts.snap +++ b/crates/rolldown/tests/esbuild/import_star/import_namespace_undefined_property_side_effect_free_file/artifacts.snap @@ -6,6 +6,8 @@ input_file: crates/rolldown/tests/esbuild/import_star/import_namespace_undefined # 2.js ```js +import { __commonJS } from "./_rolldown_runtime.js"; + // foo/no-side-effects.cjs var require_no_side_effects = __commonJS({ 'foo/no-side-effects.cjs'(exports, module) { @@ -22,12 +24,14 @@ var no_side_effects_ns = { }; console.log('js') -export { no_side_effects_ns$1 as no_side_effects_ns, no_side_effects_ns$2 as no_side_effects_ns$1, no_side_effects_ns as no_side_effects_ns$2 }; +export { no_side_effects_ns$1 as no_side_effects_ns, no_side_effects_ns$2 as no_side_effects_ns$1, no_side_effects_ns as no_side_effects_ns$2, require_no_side_effects }; ``` # entry-default_js.js ```js -import { no_side_effects_ns as no_side_effects_ns$2, no_side_effects_ns$1 as no_side_effects_ns, no_side_effects_ns$2 as no_side_effects_ns$1 } from "./2.js"; +import { __toESM } from "./_rolldown_runtime.js"; +import { no_side_effects_ns as no_side_effects_ns$2, no_side_effects_ns$1 as no_side_effects_ns, no_side_effects_ns$2 as no_side_effects_ns$1, require_no_side_effects } from "./2.js"; + // entry-default.js var no_side_effects_ns$2 = __toESM(require_no_side_effects()); @@ -42,7 +46,9 @@ console.log( # entry-nope_js.js ```js -import { no_side_effects_ns as no_side_effects_ns$2, no_side_effects_ns$1 as no_side_effects_ns, no_side_effects_ns$2 as no_side_effects_ns$1 } from "./2.js"; +import { __toESM } from "./_rolldown_runtime.js"; +import { no_side_effects_ns as no_side_effects_ns$2, no_side_effects_ns$1 as no_side_effects_ns, no_side_effects_ns$2 as no_side_effects_ns$1, require_no_side_effects } from "./2.js"; + // entry-nope.js var no_side_effects_ns$2 = __toESM(require_no_side_effects()); diff --git a/crates/rolldown/tests/esbuild/import_star/import_star_and_common_js/artifacts.snap b/crates/rolldown/tests/esbuild/import_star/import_star_and_common_js/artifacts.snap index 86d097aea34..cb10fca4892 100644 --- a/crates/rolldown/tests/esbuild/import_star/import_star_and_common_js/artifacts.snap +++ b/crates/rolldown/tests/esbuild/import_star/import_star_and_common_js/artifacts.snap @@ -6,6 +6,8 @@ input_file: crates/rolldown/tests/esbuild/import_star/import_star_and_common_js # entry_js.js ```js +import { __esm, __toCommonJS } from "./_rolldown_runtime.js"; + // foo.js var foo; var foo_ns = { diff --git a/crates/rolldown/tests/esbuild/import_star/import_star_common_js_capture/artifacts.snap b/crates/rolldown/tests/esbuild/import_star/import_star_common_js_capture/artifacts.snap index 812885eb99b..67d602069bb 100644 --- a/crates/rolldown/tests/esbuild/import_star/import_star_common_js_capture/artifacts.snap +++ b/crates/rolldown/tests/esbuild/import_star/import_star_common_js_capture/artifacts.snap @@ -6,6 +6,8 @@ input_file: crates/rolldown/tests/esbuild/import_star/import_star_common_js_capt # entry_js.js ```js +import { __commonJS, __toESM } from "./_rolldown_runtime.js"; + // foo.js var require_foo = __commonJS({ 'foo.js'(exports, module) { diff --git a/crates/rolldown/tests/esbuild/import_star/import_star_common_js_no_capture/artifacts.snap b/crates/rolldown/tests/esbuild/import_star/import_star_common_js_no_capture/artifacts.snap index 459012ddaa2..afe77d0d882 100644 --- a/crates/rolldown/tests/esbuild/import_star/import_star_common_js_no_capture/artifacts.snap +++ b/crates/rolldown/tests/esbuild/import_star/import_star_common_js_no_capture/artifacts.snap @@ -6,6 +6,8 @@ input_file: crates/rolldown/tests/esbuild/import_star/import_star_common_js_no_c # entry_js.js ```js +import { __commonJS, __toESM } from "./_rolldown_runtime.js"; + // foo.js var require_foo = __commonJS({ 'foo.js'(exports, module) { diff --git a/crates/rolldown/tests/esbuild/import_star/import_star_common_js_unused/artifacts.snap b/crates/rolldown/tests/esbuild/import_star/import_star_common_js_unused/artifacts.snap index 7d5dc8837c2..b06d3deea56 100644 --- a/crates/rolldown/tests/esbuild/import_star/import_star_common_js_unused/artifacts.snap +++ b/crates/rolldown/tests/esbuild/import_star/import_star_common_js_unused/artifacts.snap @@ -6,6 +6,8 @@ input_file: crates/rolldown/tests/esbuild/import_star/import_star_common_js_unus # entry_js.js ```js +import { __commonJS, __toESM } from "./_rolldown_runtime.js"; + // foo.js var require_foo = __commonJS({ 'foo.js'(exports, module) { diff --git a/crates/rolldown/tests/esbuild/import_star/namespace_import_missing_common_js/artifacts.snap b/crates/rolldown/tests/esbuild/import_star/namespace_import_missing_common_js/artifacts.snap index be581424263..2f48e1e42b3 100644 --- a/crates/rolldown/tests/esbuild/import_star/namespace_import_missing_common_js/artifacts.snap +++ b/crates/rolldown/tests/esbuild/import_star/namespace_import_missing_common_js/artifacts.snap @@ -6,6 +6,8 @@ input_file: crates/rolldown/tests/esbuild/import_star/namespace_import_missing_c # entry_js.js ```js +import { __commonJS, __toESM } from "./_rolldown_runtime.js"; + // foo.js var require_foo = __commonJS({ 'foo.js'(exports, module) { diff --git a/crates/rolldown/tests/esbuild/import_star/namespace_import_unused_missing_common_js/artifacts.snap b/crates/rolldown/tests/esbuild/import_star/namespace_import_unused_missing_common_js/artifacts.snap index deefde83ce1..83478cac8d4 100644 --- a/crates/rolldown/tests/esbuild/import_star/namespace_import_unused_missing_common_js/artifacts.snap +++ b/crates/rolldown/tests/esbuild/import_star/namespace_import_unused_missing_common_js/artifacts.snap @@ -6,6 +6,8 @@ input_file: crates/rolldown/tests/esbuild/import_star/namespace_import_unused_mi # entry_js.js ```js +import { __commonJS, __toESM } from "./_rolldown_runtime.js"; + // foo.js var require_foo = __commonJS({ 'foo.js'(exports, module) { diff --git a/crates/rolldown/tests/esbuild/splitting/assign-to-local/artifacts.snap b/crates/rolldown/tests/esbuild/splitting/assign-to-local/artifacts.snap index 7b12c005794..dc652f18124 100644 --- a/crates/rolldown/tests/esbuild/splitting/assign-to-local/artifacts.snap +++ b/crates/rolldown/tests/esbuild/splitting/assign-to-local/artifacts.snap @@ -17,6 +17,7 @@ export { foo, setFoo }; ```js import { foo, setFoo } from "./2.js"; + // a.js setFoo(123) @@ -26,6 +27,7 @@ console.log(foo) ```js import { foo } from "./2.js"; + // b.js console.log(foo) diff --git a/crates/rolldown/tests/esbuild/splitting/.shared-commonjs-into-es6/a.js b/crates/rolldown/tests/esbuild/splitting/shared-commonjs-into-es6/a.js similarity index 100% rename from crates/rolldown/tests/esbuild/splitting/.shared-commonjs-into-es6/a.js rename to crates/rolldown/tests/esbuild/splitting/shared-commonjs-into-es6/a.js diff --git a/crates/rolldown/tests/esbuild/splitting/shared-commonjs-into-es6/artifacts.snap b/crates/rolldown/tests/esbuild/splitting/shared-commonjs-into-es6/artifacts.snap new file mode 100644 index 00000000000..20f725d6acc --- /dev/null +++ b/crates/rolldown/tests/esbuild/splitting/shared-commonjs-into-es6/artifacts.snap @@ -0,0 +1,38 @@ +--- +source: crates/rolldown/tests/common/case.rs +expression: content +input_file: crates/rolldown/tests/esbuild/splitting/shared-commonjs-into-es6 +--- +# 2.js + +```js +import { __commonJS } from "./_rolldown_runtime.js"; + +// shared.js +var require_shared = __commonJS({ +'shared.js'(exports, module) { +exports.foo = 123 +} +}); +export { require_shared, shared_ns }; +``` +# a.js + +```js +import { __toESM } from "./_rolldown_runtime.js"; +import { require_shared, shared_ns } from "./2.js"; + +// a.js +const {foo} = require_shared() +console.log(foo) +``` +# b.js + +```js +import { __toESM } from "./_rolldown_runtime.js"; +import { require_shared, shared_ns } from "./2.js"; + +// b.js +const {foo} = require_shared() +console.log(foo) +``` diff --git a/crates/rolldown/tests/esbuild/splitting/.shared-commonjs-into-es6/b.js b/crates/rolldown/tests/esbuild/splitting/shared-commonjs-into-es6/b.js similarity index 100% rename from crates/rolldown/tests/esbuild/splitting/.shared-commonjs-into-es6/b.js rename to crates/rolldown/tests/esbuild/splitting/shared-commonjs-into-es6/b.js diff --git a/crates/rolldown/tests/esbuild/splitting/.shared-commonjs-into-es6/shared.js b/crates/rolldown/tests/esbuild/splitting/shared-commonjs-into-es6/shared.js similarity index 100% rename from crates/rolldown/tests/esbuild/splitting/.shared-commonjs-into-es6/shared.js rename to crates/rolldown/tests/esbuild/splitting/shared-commonjs-into-es6/shared.js diff --git a/crates/rolldown/tests/esbuild/splitting/.shared-commonjs-into-es6/test.config.json b/crates/rolldown/tests/esbuild/splitting/shared-commonjs-into-es6/test.config.json similarity index 100% rename from crates/rolldown/tests/esbuild/splitting/.shared-commonjs-into-es6/test.config.json rename to crates/rolldown/tests/esbuild/splitting/shared-commonjs-into-es6/test.config.json diff --git a/crates/rolldown/tests/esbuild/splitting/shared-es6-into-es6/artifacts.snap b/crates/rolldown/tests/esbuild/splitting/shared-es6-into-es6/artifacts.snap index a02272ed617..7615b584d6c 100644 --- a/crates/rolldown/tests/esbuild/splitting/shared-es6-into-es6/artifacts.snap +++ b/crates/rolldown/tests/esbuild/splitting/shared-es6-into-es6/artifacts.snap @@ -14,6 +14,7 @@ export { foo }; ```js import { foo } from "./2.js"; + // a.js console.log(foo) @@ -22,6 +23,7 @@ console.log(foo) ```js import { foo } from "./2.js"; + // b.js console.log(foo) diff --git a/crates/rolldown/tests/fixtures/basic_commonjs/artifacts.snap b/crates/rolldown/tests/fixtures/basic_commonjs/artifacts.snap index 41e9ea6ebf9..a983613cdd2 100644 --- a/crates/rolldown/tests/fixtures/basic_commonjs/artifacts.snap +++ b/crates/rolldown/tests/fixtures/basic_commonjs/artifacts.snap @@ -6,6 +6,8 @@ input_file: crates/rolldown/tests/fixtures/basic_commonjs # main.js ```js +import { __commonJS, __esm, __toCommonJS, __toESM } from "./_rolldown_runtime.js"; + // esm.js function esm_default_fn() {}function esm_named_fn() {} diff --git a/crates/rolldown/tests/fixtures/import_reexport_between_esm_and_cjs/esm_import_cjs_import_star_as/artifacts.snap b/crates/rolldown/tests/fixtures/import_reexport_between_esm_and_cjs/esm_import_cjs_import_star_as/artifacts.snap index abeca6ef63c..fd8d4e02a28 100644 --- a/crates/rolldown/tests/fixtures/import_reexport_between_esm_and_cjs/esm_import_cjs_import_star_as/artifacts.snap +++ b/crates/rolldown/tests/fixtures/import_reexport_between_esm_and_cjs/esm_import_cjs_import_star_as/artifacts.snap @@ -6,6 +6,8 @@ input_file: crates/rolldown/tests/fixtures/import_reexport_between_esm_and_cjs/e # main.js ```js +import { __commonJS, __toESM } from "./_rolldown_runtime.js"; + // commonjs.js var require_commonjs = __commonJS({ 'commonjs.js'(exports, module) { diff --git a/crates/rolldown/tests/fixtures/import_reexport_between_esm_and_cjs/esm_import_cjs_named_import/artifacts.snap b/crates/rolldown/tests/fixtures/import_reexport_between_esm_and_cjs/esm_import_cjs_named_import/artifacts.snap index 2810bbc73a4..b25c5e16487 100644 --- a/crates/rolldown/tests/fixtures/import_reexport_between_esm_and_cjs/esm_import_cjs_named_import/artifacts.snap +++ b/crates/rolldown/tests/fixtures/import_reexport_between_esm_and_cjs/esm_import_cjs_named_import/artifacts.snap @@ -6,6 +6,8 @@ input_file: crates/rolldown/tests/fixtures/import_reexport_between_esm_and_cjs/e # main.js ```js +import { __commonJS, __toESM } from "./_rolldown_runtime.js"; + // commonjs.js var require_commonjs = __commonJS({ 'commonjs.js'(exports, module) { diff --git a/crates/rolldown/tests/fixtures/import_reexport_between_esm_and_cjs/esm_import_esm_which_export_all_from_cjs_named_import/artifacts.snap b/crates/rolldown/tests/fixtures/import_reexport_between_esm_and_cjs/esm_import_esm_which_export_all_from_cjs_named_import/artifacts.snap index 0b5a0025df3..80127cb5db9 100644 --- a/crates/rolldown/tests/fixtures/import_reexport_between_esm_and_cjs/esm_import_esm_which_export_all_from_cjs_named_import/artifacts.snap +++ b/crates/rolldown/tests/fixtures/import_reexport_between_esm_and_cjs/esm_import_esm_which_export_all_from_cjs_named_import/artifacts.snap @@ -6,6 +6,8 @@ input_file: crates/rolldown/tests/fixtures/import_reexport_between_esm_and_cjs/e # main.js ```js +import { __commonJS, __reExport, __toESM } from "./_rolldown_runtime.js"; + // commonjs.js var require_commonjs = __commonJS({ 'commonjs.js'(exports, module) { diff --git a/crates/rolldown/tests/fixtures/import_reexport_between_esm_and_cjs/esm_import_esm_which_export_all_from_multiple_cjs_named_import/artifacts.snap b/crates/rolldown/tests/fixtures/import_reexport_between_esm_and_cjs/esm_import_esm_which_export_all_from_multiple_cjs_named_import/artifacts.snap index 13ce4c807f2..645908f06e8 100644 --- a/crates/rolldown/tests/fixtures/import_reexport_between_esm_and_cjs/esm_import_esm_which_export_all_from_multiple_cjs_named_import/artifacts.snap +++ b/crates/rolldown/tests/fixtures/import_reexport_between_esm_and_cjs/esm_import_esm_which_export_all_from_multiple_cjs_named_import/artifacts.snap @@ -6,6 +6,8 @@ input_file: crates/rolldown/tests/fixtures/import_reexport_between_esm_and_cjs/e # main.js ```js +import { __commonJS, __reExport, __toESM } from "./_rolldown_runtime.js"; + // commonjs2.js var require_commonjs2 = __commonJS({ 'commonjs2.js'(exports, module) { diff --git a/crates/rolldown/tests/fixtures/import_reexport_between_esm_and_cjs/esm_reexport_cjs_named_reexport/artifacts.snap b/crates/rolldown/tests/fixtures/import_reexport_between_esm_and_cjs/esm_reexport_cjs_named_reexport/artifacts.snap index 1111cf3b4a4..b7c43ae0997 100644 --- a/crates/rolldown/tests/fixtures/import_reexport_between_esm_and_cjs/esm_reexport_cjs_named_reexport/artifacts.snap +++ b/crates/rolldown/tests/fixtures/import_reexport_between_esm_and_cjs/esm_reexport_cjs_named_reexport/artifacts.snap @@ -6,6 +6,8 @@ input_file: crates/rolldown/tests/fixtures/import_reexport_between_esm_and_cjs/e # main.js ```js +import { __commonJS, __toESM } from "./_rolldown_runtime.js"; + // commonjs.js var require_commonjs = __commonJS({ 'commonjs.js'(exports, module) { diff --git a/crates/rolldown/tests/fixtures/mix-cjs-esm/artifacts.snap b/crates/rolldown/tests/fixtures/mix-cjs-esm/artifacts.snap index 8818d1abe25..77d18976875 100644 --- a/crates/rolldown/tests/fixtures/mix-cjs-esm/artifacts.snap +++ b/crates/rolldown/tests/fixtures/mix-cjs-esm/artifacts.snap @@ -6,6 +6,8 @@ input_file: crates/rolldown/tests/fixtures/mix-cjs-esm # main.js ```js +import { __commonJS, __esm, __toCommonJS, __toESM } from "./_rolldown_runtime.js"; + // foo.js var foo_ns = { diff --git a/crates/rolldown/tests/fixtures/node_module_commonjs/artifacts.snap b/crates/rolldown/tests/fixtures/node_module_commonjs/artifacts.snap index 9318c05e8aa..0cc67b74fc9 100644 --- a/crates/rolldown/tests/fixtures/node_module_commonjs/artifacts.snap +++ b/crates/rolldown/tests/fixtures/node_module_commonjs/artifacts.snap @@ -6,16 +6,22 @@ input_file: crates/rolldown/tests/fixtures/node_module_commonjs # 2.js ```js +import { __commonJS } from "./_rolldown_runtime.js"; + // commonjs.js var require_commonjs = __commonJS({ 'commonjs.js'(exports, module) { module.exports = 1; } }); +export { commonjs_ns, require_commonjs }; ``` # entry.js ```js +import { __toESM } from "./_rolldown_runtime.js"; +import { commonjs_ns, require_commonjs } from "./2.js"; + // entry.js var commonjs_ns = __toESM(require_commonjs(), 1); @@ -24,6 +30,9 @@ console.log(commonjs_ns.default) # main.js ```js +import { __reExport, __toESM } from "./_rolldown_runtime.js"; +import { commonjs_ns, require_commonjs } from "./2.js"; + // star_export.js var star_export_ns = { diff --git a/crates/rolldown/tests/fixtures/reexport_commonjs/artifacts.snap b/crates/rolldown/tests/fixtures/reexport_commonjs/artifacts.snap index 5bce1145175..e3134cc64f1 100644 --- a/crates/rolldown/tests/fixtures/reexport_commonjs/artifacts.snap +++ b/crates/rolldown/tests/fixtures/reexport_commonjs/artifacts.snap @@ -6,6 +6,8 @@ input_file: crates/rolldown/tests/fixtures/reexport_commonjs # main.js ```js +import { __commonJS, __reExport, __toESM } from "./_rolldown_runtime.js"; + // commonjs.js var require_commonjs = __commonJS({ 'commonjs.js'(exports, module) { diff --git a/crates/rolldown/tests/fixtures/reexport_star/artifacts.snap b/crates/rolldown/tests/fixtures/reexport_star/artifacts.snap index 497df7f26eb..a78b9db6561 100644 --- a/crates/rolldown/tests/fixtures/reexport_star/artifacts.snap +++ b/crates/rolldown/tests/fixtures/reexport_star/artifacts.snap @@ -18,6 +18,7 @@ export { a_ns }; ```js import { a_ns } from "./2.js"; + // entry.js @@ -27,6 +28,7 @@ export { a_ns as a }; ```js import { a_ns } from "./2.js"; + // main.js diff --git a/packages/rollup-tests/src/failed-tests.json b/packages/rollup-tests/src/failed-tests.json index 4cfe9c9da58..472bf8d22bb 100644 --- a/packages/rollup-tests/src/failed-tests.json +++ b/packages/rollup-tests/src/failed-tests.json @@ -448,6 +448,7 @@ "rollup@function@max-parallel-file-operations@infinity: maxParallelFileOps set to infinity", "rollup@function@max-parallel-file-operations@set: maxParallelFileOps set to 3", "rollup@function@max-parallel-file-operations@with-plugin: maxParallelFileOps with plugin", + "rollup@function@member-expression-assignment-in-function: detect side effect in member expression assignment when not top level", "rollup@function@merged-namespace-live-bindings: respects getters when accessing properties of an instance", "rollup@function@method-call-mutates-this: method calls are assumed to mutate the owner", "rollup@function@missing-export-preserve-modules: supports shimming missing exports when preserving modules", diff --git a/packages/rollup-tests/src/status.json b/packages/rollup-tests/src/status.json index 83037311717..ff305cfbf85 100644 --- a/packages/rollup-tests/src/status.json +++ b/packages/rollup-tests/src/status.json @@ -1,8 +1,8 @@ { "total": 901, "failed": 0, - "skipFailed": 641, + "skipFailed": 642, "ignored": 7, "skipped": 0, - "passed": 253 + "passed": 252 } \ No newline at end of file diff --git a/packages/rollup-tests/src/status.md b/packages/rollup-tests/src/status.md index 105bb4eb8d9..48138de0423 100644 --- a/packages/rollup-tests/src/status.md +++ b/packages/rollup-tests/src/status.md @@ -2,7 +2,7 @@ |----| ---- | | total | 901| | failed | 0| -| skipFailed | 641| +| skipFailed | 642| | ignored | 7| | skipped | 0| -| passed | 253| +| passed | 252|