-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
Copy getters and setters correctly in interopWildcard #6850
Merged
Merged
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
...babel-plugin-transform-modules-commonjs/test/fixtures/misc/copy-getters-setters/actual.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import Foo, { baz } from "./moduleWithGetter"; | ||
|
||
export { Foo, baz }; |
3 changes: 3 additions & 0 deletions
3
...s/babel-plugin-transform-modules-commonjs/test/fixtures/misc/copy-getters-setters/exec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import Foo, { baz } from "./moduleWithGetter"; | ||
|
||
// Should not execute the getter in the imported module which would throw |
21 changes: 21 additions & 0 deletions
21
...bel-plugin-transform-modules-commonjs/test/fixtures/misc/copy-getters-setters/expected.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
"use strict"; | ||
|
||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
Object.defineProperty(exports, "Foo", { | ||
enumerable: true, | ||
get: function () { | ||
return _moduleWithGetter.default; | ||
} | ||
}); | ||
Object.defineProperty(exports, "baz", { | ||
enumerable: true, | ||
get: function () { | ||
return _moduleWithGetter.baz; | ||
} | ||
}); | ||
|
||
var _moduleWithGetter = _interopRequireWildcard(require("./moduleWithGetter")); | ||
|
||
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.getOwnPropertyDescriptor(obj, key); if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } } |
6 changes: 6 additions & 0 deletions
6
...in-transform-modules-commonjs/test/fixtures/misc/copy-getters-setters/moduleWithGetter.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
var Obj = { | ||
baz: 123, | ||
get boo() { throw new Error('Should never be triggered'); } | ||
} | ||
|
||
module.exports = Obj; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I think if we're going to do this, we should check for the existence of
Object.defineProperty
, or we should finally expose a flag for modules to opt in or out ofObject.defineProperty
usage. Otherwise this is going to make things unusable for people targeting old environments.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.
I will add a check for
Object.defineProperty
, which I think should be enough here, because whenObject.defineProperty
is not there then getters and setters are also not supported.It is basically supported in all environments besides IE8 and older. But IE8 is also over 10years old now. 🕵️♀️
What if we change in babel 7 and state that generated code from babel needs at least ES5, like react does now (they even require Map and Set). Would be nice to have statistics to see what environments people support, but I guess that does not really exist. Or did we have already complains about this?
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.
And core-js also has a polyfill for it, so we could also link people there. And from my experience if you support IE8 or older, then you need polyfills anyway.