-
-
Notifications
You must be signed in to change notification settings - Fork 591
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(commonjs): set syntheticNamedExports for commonjs modules #149
Changes from all commits
daa718e
993be86
26ecf34
e4fd302
0940861
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,4 +2,3 @@ import * as x from './answer'; | |
|
||
t.truthy('answer' in x); | ||
t.truthy('default' in x); | ||
t.truthy(!('__esModule' in x)); | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import { named } from './x.js'; | ||
|
||
t.is(named, 'foo'); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
if (typeof someUnknownGlobal !== 'undefined') { | ||
module.exports = { named: 'bar' }; | ||
} else { | ||
module.exports = { named: 'foo' }; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module.exports = { | ||
context: { | ||
window: {} | ||
} | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { named } from './x.js'; | ||
|
||
t.is(named, undefined); | ||
|
||
window.addExport('named', 'foo'); | ||
|
||
t.is(named, 'foo'); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
window.addExport = (key, value) => { | ||
module.exports[key] = value; | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import { named } from './x.js'; | ||
|
||
t.is(named, 'foo'); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
Object.defineProperty(module.exports, 'named', { | ||
enumerable: true, | ||
get: function get() { | ||
return 'foo'; | ||
} | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
exports.named = 2; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import { named } from './reexport.js'; | ||
|
||
t.is(named, 2); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
const myModule = require('./export.js'); | ||
|
||
module.exports.named = myModule.named; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import { nonExisting } from './x.js'; | ||
|
||
t.is(nonExisting, undefined); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
exports.named = 2; |
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With this change,
__esModule
is available as a named import. In my opinion this is correct, since it's exported from the commonjs module. What do you think?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@lukastaegert this is something you'd have to approve. not speaking for the other maintainers, but I lack the knowledge to know if this is a good change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Usually the list of exports is detected via
Object.keys
which would skip the__esModule
property since it is defined to be non-enumerable. I would be interested in how this list is being gathered that it is including it.