Skip to content

fix: empty chunk generated and imported when using advancedChunks#8625

Open
AliceLanniste wants to merge 6 commits into
rolldown:mainfrom
AliceLanniste:fix_empty_chunk
Open

fix: empty chunk generated and imported when using advancedChunks#8625
AliceLanniste wants to merge 6 commits into
rolldown:mainfrom
AliceLanniste:fix_empty_chunk

Conversation

@AliceLanniste

Copy link
Copy Markdown
Contributor

related #6677

Comment on lines +338 to +340
if !(import_str.starts_with("import") && import_str.contains("from")) {
return false;
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This check will incorrectly return false for side-effect imports that don't use the from keyword:

import './side-effect-module'

Such imports start with "import" but don't contain "from". This could cause modules with side-effect imports to be misclassified, potentially leading to incorrect pure re-export detection. The logic should handle all valid import statement formats including side-effect imports.

Suggested change
if !(import_str.starts_with("import") && import_str.contains("from")) {
return false;
}
if !import_str.starts_with("import") {
return false;
}

Spotted by Graphite

Fix in Graphite


Is this helpful? React 👍 or 👎 to let us know.

Comment on lines +318 to +320
if export_str.contains("import") {
return false;
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

String pattern matching is too simplistic and will cause false positives. The check if export_str.contains("import") will incorrectly reject valid reexport statements that contain the substring "import" in identifiers (e.g., export { importantData } from './data'). This will cause modules to be incorrectly classified as non-pure-reexports, preventing proper chunk optimization.

// This check is too broad - it rejects any statement containing "import"
// even if "import" appears in a variable name like "importantData"
if export_str.contains("import") {
  return false;
}

Recommendation: Use proper AST-based checks instead of string matching, or use more precise regex patterns that match only the import keyword.

Suggested change
if export_str.contains("import") {
return false;
}
if export_str.contains(" import ") || export_str.starts_with("import ") {
return false;
}

Spotted by Graphite

Fix in Graphite


Is this helpful? React 👍 or 👎 to let us know.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant