Skip to content

Commit

Permalink
fix: A Symbol should only be declared in one chunk (#338)
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 -->

### Test Plan

<!-- e.g. is there anything you'd like reviewers to focus on? -->

---
  • Loading branch information
hyf0 authored Nov 20, 2023
1 parent d53155b commit 340cd27
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
10 changes: 6 additions & 4 deletions crates/rolldown/src/bundler/stages/bundle_stage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,13 @@ impl<'a> BundleStage<'a> {
Module::Normal(module) => {
for stmt_info in module.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.
let symbol = self.link_output.symbols.get_mut(*declared);
debug_assert!(
self.link_output.symbols.get(*declared).chunk_id.unwrap_or(chunk_id) == chunk_id
symbol.chunk_id.unwrap_or(chunk_id) == chunk_id,
"Symbol: {:?}, {:?} in {:?} should only be declared in one chunk",
symbol.name,
declared,
module.resource_id,
);

self.link_output.symbols.get_mut(*declared).chunk_id = Some(chunk_id);
Expand Down
2 changes: 0 additions & 2 deletions crates/rolldown/src/bundler/visitors/scanner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -259,8 +259,6 @@ impl<'ast> Scanner<'ast> {
}
oxc::ast::ast::Declaration::FunctionDeclaration(fn_decl) => {
let id = fn_decl.id.as_ref().unwrap();
// FIXME: remove this line after https://github.com/web-infra-dev/oxc/pull/843 being merged.
self.add_declared_id(id.expect_symbol_id());
self.add_local_export(&id.name, id.expect_symbol_id());
}
oxc::ast::ast::Declaration::ClassDeclaration(cls_decl) => {
Expand Down

0 comments on commit 340cd27

Please sign in to comment.