-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Why skip "default" in GetExportedNames and ResolveExport? #948
Comments
I believe this was discussed and rejected in November: https://github.com/tc39/tc39-notes/blob/master/es7/2016-11/nov-29.md#12iid-proposal-to-reform-the-spec-to-include-default-export-in-export--from-module |
@domenic yup. And I believe a search of pre-ES6 release meeting notes would turn of earlier discussions about this. |
Of the other people who participated in that conversation (@caridy @dherman @wycats), has your thinking changed at all since November? It looks like my first two objections were discussed in that conversation. I still consider them legitimate, but at least they are not new. In particular, if this policy stands, Babel-compiled code will break, though I realize not everyone on the committee is moved by that argument. My second two objections may be mistaken (which is good news to me). Can anyone confirm that module.[[LocalExportEntries]] (as used here) contains |
Closes #184. Discussion: tc39/ecma262#948 Inspiration from @jdalton: standard-things/esm@19deff3 standard-things/esm@c4f2e8a
Thanks to everyone who took a look at this. I've implemented the existing policy in my own module compiler project now, so I'm not personally concerned about what Babel does. If the policy turns out to be a problem for Meteor users, I might reopen this issue, but at this point it doesn't sound like a productive use of TC39's time to re-litigate the policy (especially since @caridy tells me he was convinced by the discussion in November). |
Closes benjamn#184. Discussion: tc39/ecma262#948 Inspiration from @jdalton: standard-things/esm@19deff3 standard-things/esm@c4f2e8a
In section 15.2.1.16.2.7.c.i of the spec, in the implementation of the
GetExportedNames
method, @jdalton and I recently noticed that exports nameddefault
are deliberately skipped.Echoing this policy, the
ResolveExport
method also notes that "Adefault
export cannot be provided by anexport *
" (15.2.1.16.3.6.c).The git blame for these sections extends beyond the history of this repository, and I haven't been able to find a justification for this skippage on
es-discuss
(at least as long as I've been subscribed). If I should have looked harder/smarter, please feel free to tell me how.If I understand the implications of this policy, it seems problematic for several reasons:
export * from "./original"
to create a high-fidelity wrapper module whose export behavior matches the module it wraps. For comparison, in Node/CommonJS, the analogous (if not perfectly equivalent) idiom is to aliasmodule.exports
with the original module'sexports
object:In my experience, this idiom is relatively common in Node applications, and has the benefit of being easy to remember. Imagine a JS developer reading through a CommonJS-to-ECMAScript cheatsheet and stumbling across this ECMAScript equivalent:
To me, this feels like a surprising ergonomic regression.
The policy is currently at odds with what Babel does. While this inconsistency is certainly not the end of the world, it does mean that retracting the policy (if possible) could prevent many bugs that will be exposed in the transition from Babel-transpiled modules to native ES modules. If Babel needs to change its treatment of
default
exports to match this policy, that's going to be a pretty big deal, so we should make absolutely sure the policy is desirable and necessary—or that my reading of the policy is incorrect!Since module namespace objects (e.g.
import * as namespace from "./original"
) are created withGetModuleNamespace
, which callsGetExportedNames
, a strict interpretation of the policy would seem to excludedefault
exports from namespace objects, so you would have toimport OriginalDefault from "./original"
separately, becausenamepace.default
is not defined. If I'm missing some part of the spec that ensures namespace objects preserve the.default
property, I'd love to be set straight.Since the dynamic
import(...)
proposal also usesGetModuleNamespace
, and the proposal does not appear to alter anything about the policy in question, a strict interpretation would seem to excludedefault
exports from module namespace objects imported dynamically. I've separated this case from the previous case because theimport OriginalDefault from "./original"
trick from above does not help here. With any luck @domenic will have some insight (again, I would be happy if my interpretation is simply wrong).tl;dr My instinct is that we should consider retracting this policy, provided it does not provide some fundamental benefit that must be preserved.
I'm happy to submit a PR to fix this issue and/or bring it up for discussion at the next TC39 meeting.
Original issue/inspiration: benjamn/reify#184
The text was updated successfully, but these errors were encountered: