Skip to content
This repository was archived by the owner on Jun 4, 2024. It is now read-only.

[breaking][do-not-merge] CJS interop changes #13

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

bmeck
Copy link

@bmeck bmeck commented Dec 7, 2016

Relates to #12

Has breaking change, unclear on intent here so marked as do not merge until discussion.

src/index.js Outdated
if (ns && ns.__esModule) {
resolve(ns);
} else {
var wrap = Object.create(null);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to have a fallback for pre-ES5 environments that lack Object.create(null) (Promises are shimmable; Object.create is not)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is

function X() {};
X.prototype = null;
new X();

correct in older browsers? we just need a nulled proto

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right - pre-ES5 and pre-__proto__, it's impossible to have a null prototype object, so it'd need to just be a normal object there.

src/index.js Outdated
resolve(ns);
} else {
var wrap = Object.create(null);
wrap.__esModule = true;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this for babel interop alone? Is __esModule supposed to be enumerable?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unspecified, transpilers tend not to check enumerability

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like it'd be better to make it non-enumerable then (when Object.defineProperty is available)

src/index.js Outdated
var wrap = Object.create(null);
wrap.__esModule = true;
wrap.default = ns;
Object.freeze(wrap);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

similarly this needs to have a fallback for when Object.freeze is not available.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if it does not exist I guess we can just not call that fn?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good to me.

src/index.js Outdated
} else {
var wrap = Object.create(null);
wrap.__esModule = true;
wrap.default = ns;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

similarly, is default supposed to be enumerable?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's for it being an own property - where's it specify the descriptor?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bmeck
Copy link
Author

bmeck commented Dec 7, 2016

@ljharb fixed up, can move the proto to be the module.exports value if desired, but using named property access is still up in the air, using .default is the future safe option.

enumerable: false,
configurable: false
});
Object.defineProperty(wrap, 'default', {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think we can assign default unconditionally, since anything with defineProperty will also have freeze, and [[Put]] + freeze results in this descriptor.

@bmeck
Copy link
Author

bmeck commented Dec 8, 2016

@ljharb with potential change to _interopRequireWildcard, going to change recommendation to just use _interopRequireWildcard rather than a custom interop boilerplate

@gdborton
Copy link

gdborton commented May 4, 2017

@bmeck Can you clarify what you mean by "potential change to _interopRequireWildcard"? As of today the helper hasn't changed in > 2 years.

Do we know yet whether import() will allow access to named exports?

@ljharb
Copy link
Collaborator

ljharb commented May 4, 2017

@gdborton we do know that; import() will provide a ModuleRecord, which will provide (i believe) a .default, and definitely .foo for all named exports.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants