-
-
Notifications
You must be signed in to change notification settings - Fork 611
Closed
Description
- Rollup Plugin Name: @rollup/plugin-commonjs
- Rollup Plugin Version: 16.0.0
- Rollup Version: 2.33.2
- Operating System (or Browser): macOS
- Node Version: v14.15.0
- Link to reproduction (
⚠️ read below): https://repl.it/@EvanWallace1/rollup-commonjs-import-inconsistency
// input.js
import * as test from './test'
console.log('nonEnumerable (direct):', test.nonEnumerable)
console.log('nonEnumerable (indirect):', test[Math.random() < 2 && 'nonEnumerable'])
console.log('inherited (direct):', test.inherited)
console.log('inherited (indirect):', test[Math.random() < 2 && 'inherited'])// test.js
module.exports = Object.create({ inherited: true })
Object.defineProperty(module.exports, 'nonEnumerable', {value: true})Note that the code above uses test[Math.random() < 2 && 'property'] to represent a dynamic property access. It's not the intention of this issue to special-case that syntax to behave like test.property.
Expected Behavior
An import should either be always imported or never imported, regardless of the import syntax used.
Either this:
nonEnumerable (direct): undefined
nonEnumerable (indirect): undefined
inherited (direct): undefined
inherited (indirect): undefined
Or this:
nonEnumerable (direct): true
nonEnumerable (indirect): true
inherited (direct): true
inherited (indirect): true
Actual Behavior
Whether a property can be imported or not depends on the syntax used:
nonEnumerable (direct): true
nonEnumerable (indirect): undefined
inherited (direct): true
inherited (indirect): undefined
Additional Information
I'm working on improving esbuild's compatibility with other bundlers. This inconsistency tripped me up in the past when trying to figure out what forms of importing Rollup supports. Ideally it would be consistent. I'm guessing no one else has pointed this out yet so I figured I should log an issue. Here's the context: evanw/esbuild#532 (comment).