Skip to content

Commit

Permalink
fix: only pull out __export() when it's needed
Browse files Browse the repository at this point in the history
  • Loading branch information
hyf0 committed Feb 21, 2024
1 parent 9e517e5 commit 670dbb6
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 10 deletions.
13 changes: 7 additions & 6 deletions crates/rolldown/src/bundler/stages/link_stage/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,16 +84,17 @@ impl<'a> LinkStage<'a> {

if matches!(module.exports_kind, ExportsKind::Esm) {
let linking_info = &self.linking_infos[module.id];

let mut referenced_symbols = vec![];
if !linking_info.exclude_ambiguous_sorted_resolved_exports.is_empty() {
referenced_symbols
.extend(linking_info.sorted_exports().map(|(_, export)| export.symbol_ref));
referenced_symbols.push(self.runtime.resolve_symbol("__export"));
}
// Create a StmtInfo for the namespace statement
let namespace_stmt_info = StmtInfo {
stmt_idx: None,
declared_symbols: vec![module.namespace_symbol],
referenced_symbols: linking_info
.sorted_exports()
.map(|(_, export)| export.symbol_ref)
.chain([self.runtime.resolve_symbol("__export")])
.collect(),
referenced_symbols,
side_effect: false,
is_included: false,
import_records: Vec::new(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ input_file: crates/rolldown/tests/esbuild/default/empty_export_clause_bundle_as_
## entry_js.mjs

```js
import { __esmMin, __export, __toCommonJS } from "./$runtime$.mjs";
import { __esmMin, __toCommonJS } from "./$runtime$.mjs";
// types.mjs
var types_ns;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ input_file: crates/rolldown/tests/fixtures/import_reexport_between_esm_and_cjs/e
## main.mjs

```js
import { __commonJSMin, __export, __reExport, __toESM } from "./$runtime$.mjs";
import { __commonJSMin, __reExport, __toESM } from "./$runtime$.mjs";
// commonjs.js
var require_commonjs = __commonJSMin((exports, module) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ input_file: crates/rolldown/tests/fixtures/import_reexport_between_esm_and_cjs/e
## main.mjs

```js
import { __commonJSMin, __export, __reExport, __toESM } from "./$runtime$.mjs";
import { __commonJSMin, __reExport, __toESM } from "./$runtime$.mjs";
// commonjs.js
var require_commonjs = __commonJSMin((exports, module) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ input_file: crates/rolldown/tests/fixtures/require/require_esm
## main.mjs

```js
import { __esmMin, __export, __toCommonJS } from "./$runtime$.mjs";
import { __esmMin, __toCommonJS } from "./$runtime$.mjs";
// esm.js
var esm_ns;
Expand Down

0 comments on commit 670dbb6

Please sign in to comment.