[turbopack] Ignore writes to `exports` after a `module.exports = {}` writes (#96380)
Take this example:
```javascript
// Discarded by the literal below, so not an export.
exports.early = 'early-value'
module.exports = {
used: 'used-value',
unused: 'unused-value',
}
// Not exports: `exports` and top-level `this` hold the object the literal discarded.
exports.deadExports = 'dead-exports'
this.deadThis = 'dead-this'
Object.defineProperty(exports, 'deadDefined', { value: 'dead-defined' })
// Exports: `module.exports` is the live object.
module.exports.usedLate = 'used-late'
module.exports.unusedLate = 'unused-late'
```
Previously, we'd treat all of these as exports. Even though some of them
aren't, this PR cleans that inaccuracy up so that scope-hoisting can
land without a bug.
Now this does cause an odd case, consider:
```javascript
// Discarded by the literal below, so not an export.
exports.early = 'early-value'
exports.unused = 'unused-value'
module.exports = {
used: 'used-value',
unused: 'unused-value',
}
// Not exports: `exports` and top-level `this` hold the object the literal discarded.
exports.deadExports = 'dead-exports'
this.deadThis = 'dead-this'
Object.defineProperty(exports, 'deadDefined', { value: 'dead-defined' })
// Exports: `module.exports` is the live object.
module.exports.usedLate = 'used-late'
module.exports.unusedLate = 'unused-late'
```
We would actually not drop:
```
exports.unused = 'unused-value'
```
Now. But I'm going to make a follow-up PR to drop these.
Showing
Please
register
or
sign in
to comment