Skip to content

Commit

Permalink
fix: deconflict export named declartion (#386)
Browse files Browse the repository at this point in the history
  • Loading branch information
underfin committed Dec 4, 2023
1 parent 518aa5f commit 21aaa36
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 0 deletions.
1 change: 1 addition & 0 deletions crates/rolldown/src/bundler/renderer/render_wrapped_esm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ impl<'r> AstRenderer<'r> {
}
_ => {}
}
return RenderControl::Continue;
} else if named_decl.source.is_some() {
match self.ctx.importee_by_span(named_decl.span) {
Module::Normal(importee) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
---
source: crates/rolldown/tests/common/case.rs
expression: content
input_file: crates/rolldown/tests/fixtures/deconflict/wrapped_esm_export_named_function
---
# Assets

## main.mjs

```js
import { default as assert } from "assert";
// <runtime>
var __defProp = Object.defineProperty
var __getOwnPropDesc = Object.getOwnPropertyDescriptor
var __getOwnPropNames = Object.getOwnPropertyNames
var __hasOwnProp = Object.prototype.hasOwnProperty
var __esm = (fn, res) => function () {
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res
}
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === 'object' || typeof from === 'function')
for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
key = keys[i]
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: (k => from[k]).bind(null, key), enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable })
}
return to
}
var __toCommonJS = mod => __copyProps(__defProp({}, '__esModule', { value: true }), mod)
// foo.js
function foo$1(a$1$1) {
console.log(a$1$1, a$1)
}
var foo_ns = {
get foo() { return foo$1 }
};
var init_foo = __esm({
'foo.js'() {
const a$1 = 1;
}
});
// bar.js
init_foo();
var bar_default = { foo: foo$1 }
// main.js
// make foo `a` conflict
const { foo } = bar_default
assert.strictEqual(typeof foo, 'function')
init_foo()
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { foo } from './foo'

export default { foo }
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const a = 1;

export function foo(a$1) {
console.log(a$1, a)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import assert from 'assert'
import bar from './bar'

const a = 2; // make foo `a` conflict

const { foo } = bar

assert.strictEqual(typeof foo, 'function')

require('./foo')
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"input": {
"external": [
"assert"
]
}
}

0 comments on commit 21aaa36

Please sign in to comment.