Skip to content

Commit

Permalink
fix: should not panic if there are accessing on star as member (#1730)
Browse files Browse the repository at this point in the history
<!-- Thank you for contributing! -->

### Description



<!-- Please insert your description here and provide especially info
about the "what" this PR is solving -->

---------

Co-authored-by: IWANABETHATGUY <iwanabethatguy@qq.com>
  • Loading branch information
hyf0 and IWANABETHATGUY authored Jul 28, 2024
1 parent cde1203 commit 250c11a
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 2 deletions.
15 changes: 13 additions & 2 deletions crates/rolldown/src/stages/generate_stage/code_splitting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,19 @@ impl<'a> GenerateStage<'a> {
// We need this step to include the runtime module, if there are symbols of it.
// TODO: Maybe we should push runtime module to `LinkingMetadata::dependencies` while pushing the runtime symbols.
stmt_info.referenced_symbols.iter().for_each(|reference_ref| {
let canonical_ref =
self.link_output.symbols.par_canonical_ref_for(*reference_ref.symbol_ref());
let canonical_ref = match reference_ref {
rolldown_common::SymbolOrMemberExprRef::Symbol(s) => {
self.link_output.symbols.par_canonical_ref_for(*s)
}
// try to resolve member expression to the pointed symbol
// fallback to namespace_ref if not found
rolldown_common::SymbolOrMemberExprRef::MemberExpr(member_expr) => self
.link_output
.top_level_member_expr_resolved_cache
.get(&member_expr.object_ref)
.and_then(|map| map.get(&member_expr.props.clone().into_boxed_slice()))
.map_or(member_expr.object_ref, |(finalized_symbol_ref, _, _)| *finalized_symbol_ref),
};

self.determine_reachable_modules_for_entry(
canonical_ref.owner,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"config": {
"treeshake": {
"moduleSideEffects": false
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
source: crates/rolldown_testing/src/integration_test.rs
expression: snapshot
input_file: crates/rolldown/tests/fixtures/tree_shaking/export_star2
---
# Assets

## main.mjs

```js
//#region foo.js
const foo = 1;
//#endregion
//#region main.js
console.log(foo);
//#endregion
```
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './export-star2';
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './foo';
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const foo = 1;
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import * as star from './export-star';
console.log(star.foo);
Original file line number Diff line number Diff line change
Expand Up @@ -1915,6 +1915,10 @@ expression: "snapshot_outputs.join(\"\\n\")"

- main-!~{000}~.mjs => main-D_8Z2hmK.mjs

# tests/fixtures/tree_shaking/export_star2

- main-!~{000}~.mjs => main-Ll-xem_E.mjs

# tests/fixtures/tree_shaking/external-export-star1

- main-!~{000}~.mjs => main-0iPGFsZ0.mjs
Expand Down

0 comments on commit 250c11a

Please sign in to comment.