mirror of
https://github.com/oven-sh/bun
synced 2026-02-09 10:28:47 +00:00
[JS Printer] Fix CJS <> ESM interop edgecase
For code like this:
```js
module.exports = require("foo")
```
If `"foo"` is bundled, we should access it as the namespace reference from the bundle. Previously, we assumed it would be a property access.
This commit is contained in:
@@ -2018,6 +2018,13 @@ pub fn NewPrinter(
|
||||
p.printSymbol(namespace.namespace_ref);
|
||||
}
|
||||
|
||||
// In the case of code like this:
|
||||
// module.exports = require("foo")
|
||||
// if "foo" is bundled
|
||||
// then we access it as the namespace symbol itself
|
||||
// that means the namespace alias is empty
|
||||
if (namespace.alias.len == 0) return;
|
||||
|
||||
if (p.canPrintIdentifier(namespace.alias)) {
|
||||
p.print(".");
|
||||
p.printIdentifier(namespace.alias);
|
||||
|
||||
Reference in New Issue
Block a user