-
Notifications
You must be signed in to change notification settings - Fork 18
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
Shorthand for module blocks default-exporting functions #6
Comments
I like this, but I wonder if we should see what kind of patterns emerge? Considering you can’t close over variables, I am not sure if 1-function-modules would actually appear that often. Haven’t thought about it that much tho |
This sounds like a good idea to me; we can categorize this as a potential follow-on proposal. |
The discussion in #21 moved in this direction and IMO ups the priority of this considerably, for the reasons explained there. I'd also suggest that further shorthand would be ideal, e.g. |
I think that "module arrow functions" would be really confusing. The difference between arrow functions and "normal functions" is that they capture |
Sure, but normal |
I like the idea of module arrow functions. We would probably want to support the full set of variants of function expressions, including generators, async functions, etc in "module" form. I am also sympathetic to arguments to make this shorthand post-MVP. |
I definitely agree with @domenic that these are desirable ergonomics, especially as libraries like greenlet have already somewhat established those ergonomics. I do feel like it’s something I’d rather tackle as an enhancement post-MVP. The benefits of I also wonder how often a single-function module will actually be used frequently. I could imagine that many use-cases require imports, which would require the full module syntax (unless you want to dynamically import them). I’d like to see module blocks in use for a bit before deciding on this. |
What I think we can do is make a separate Stage 1 proposal for this shorthand, with a concrete grammar and specification, and encourage its implementation in Babel. |
Thinking about this some more, I agree with @surma that it's not yet clear that import-free single-function modules are needed so frequently. You will probably usually want to import something, and dynamic import is just not an idiom that I want to encourage to get around this. That makes me see this as more of a post-MVP feature. |
or even just |
The FAQ in the README suggests that the short hand for a module block isn't part of the MVP
But the README also talks about adding syntax for it here: https://github.com/tc39/proposal-js-module-blocks#module-function-syntactic-sugar |
That’s an oversight by me. We went back and forth and, as of now, the shorthand is part of the proposal. |
I concur with @littledan that it would be good to defer module default export shorthand(s) to a future proposal. |
@surma I suggest we could reopen this issue (or create a new one?), and I also agree with @kriskowal that we'd better defer module function to a future proposal. @Jack-Works raised a concern about the syntax of it in yesterday meeting. module function (a = expr) { ... }
In the yesterday JSCIG meeting (a localized meeting of chinese TC39 delegates and the chinese JS community) some also raised another concern: if we have About |
I’ll open a new issue soon to talk about the concrete shorthand proposal. |
Module blocks are intended to make it more ergonomic to write context-free fragments of code, but there's still a bit of ceremony around making them a module. Maybe we could reduce this with a small amount of syntax sugar: enabling the
module
keyword to precede a function expression, to make it a module which default-exports that function. For example:would desugar to
I think we could enable async functions, arrow functions, generator functions, and functions with local name bindings the same way, even permitting function declarations (to set the external binding to the module) if desired. For each of these, there is some careful work to do to spell out the grammar details, make sure we're all OK with the edge cases (e.g., [no LineTerminator here]) and that parsing isn't too costly (e.g., for arrow functions).
The text was updated successfully, but these errors were encountered: