Skip to content

Commit

Permalink
fix: conflict between imported and local binding (#356)
Browse files Browse the repository at this point in the history
<!-- Thank you for contributing! -->

### Description

Fixes #355

<!-- 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 22, 2023
1 parent 19fb1da commit 7387e35
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 4 deletions.
8 changes: 4 additions & 4 deletions crates/rolldown/src/bundler/chunk/de_conflict.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ impl Chunk {
renamer.inc(name);
});

self.imports_from_other_chunks.iter().flat_map(|(_, items)| items.iter()).for_each(|item| {
renamer.add_top_level_symbol(item.import_ref);
});

self
.modules
.iter()
Expand All @@ -50,10 +54,6 @@ impl Chunk {
Module::External(_) => {}
});

self.imports_from_other_chunks.iter().flat_map(|(_, items)| items.iter()).for_each(|item| {
renamer.add_top_level_symbol(item.import_ref);
});

// rename non-top-level names

self.modules.iter().copied().for_each(|module| {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
---
source: crates/rolldown/tests/common/case.rs
expression: content
input_file: crates/rolldown/tests/fixtures/deconflict/conflict_between_imported_and_local_binding
---
# Assets

## main.mjs

```js
import { default as assert } from "node:assert";
import { __commonJS } from "./_rolldown_runtime.mjs";
// main.js
var require_main = __commonJS({
'main.js'(exports, module) {
module.exports = 'main';
const __commonJS$1 = 1
assert.equal(__commonJS$1, 1)
}
});
export default require_main();
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import assert from 'node:assert'
module.exports = 'main';

const __commonJS = 1

assert.equal(__commonJS, 1)
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"input": {
"external": [
"node:assert"
]
}
}

0 comments on commit 7387e35

Please sign in to comment.