-
Notifications
You must be signed in to change notification settings - Fork 66
Replace section 5.1 with unambiguous JavaScript grammar. #33
Conversation
Let me know if you'd like more of the UJSG proposal brought over, things regrouped, or split out. |
A package opts-in to the Module goal by specifying `"module"` as the parse goal | ||
field *(name not final)* in its `package.json`. Package dependencies are not | ||
affected by the opt-in and may be a mix of CJS and ES module packages. If a parse | ||
goal is not specified, then attempt to parse source text as the preferred goal. |
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.
probably need to be specific that CJS (I think) is the preferred goal
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.
err .. Script "goal" that would be I suppose
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.
Yes, you're correct. I'll update that.
So I guess there are a couple of ways forward here:
The only problem with the second option is that we'd have to build the detection code ourselves without being able to rely on V8, I assume, perhaps that would be as simple (?) as doing a Module parse, which, if successful, could be inspected for Also, this doesn't include the /cc @nodejs/collaborators - please chime in on this, it'd be great to have more than just the CTC engaged on the modules questions, I think we'd all appreciate more core team minds being applied to this than we currently have. |
Since you're asking (and I'll keep it short), I would definitely wait for TC39's position on this. If an alternative solution comes out of this (again), we should probably re-evaluate. I see absolutely no reason to rush here. It's not like CommonJS is broken. |
I don't think that parsing ourselves is a great idea, so detection part needs to be implemented in v8 first |
@ronkorving even if we opt for waiting for TC39 to pass judgement, they may be looking to us to provide a signal wrt whether this is going to be something we'd even end up using. While the unambiguous grammar proposal serves more than just Node, we are the primary beneficiary and target of it. TC39 are obviously not so comfortable with the idea of changing a spec that they've already signed off on, but given the consternation around Node's preference for |
I wasn't gonna touch the topic of preference of the actual solution, but I for one much prefer this over a new file extension. |
I'm -1. This is solution is not significantly better (or not better at all), but is much harder to implement and affects performance |
@vkurchatkin How does it effect performance? It doesn't seem like this would actually significantly impact startup time, but we'd have to benchmark to say that it would, which is pretty much impossible without V8 implementing it. |
@Fishrock123 I wonder then how
is achieved |
@Fishrock123 it'll require a full double-parse unless the module type being loaded is the same as the default goal being parsed by the version of Node.js being used, and we can't really cache that between processes, only within a process. The |
This really depends on the implementation. It's totally possible not to drop away all the parsing results, but only to delay strict early errors + things like octal literals until the end of the parsing (and, because V8 already uses lazy parsing, it should result in pretty small if no overhead). |
I guess that's a call for V8 to make re optimisation, my understanding was that the two goals are handled completely separately in the current incarnation of Modules that V8 has implemented (but not shipped). It'd be nice if this was all handled upstream from Node but I doubt we'll get such a free ride. @jdalton @joshgav can we pull in some ChakraCore folks in here as well to have them comment on where this might be implemented in a ChakraCore-backed Node and how much Node could get for free if this became part of the spec? |
Note that e.g. a top-level |
Sure, but I guess you're talking about runtime semantics here, not parsing? Note that for distinguishing modules only parsing stage is important. |
@RReverser In that example, |
Ah right. Another one to the list of delayed elements (like octal literals), although I agree it's somewhat trickier. (Btw, AFAIR it's not even part of the current proposal, only a future consideration?) |
It can't be done outside of engine, and engines will probably do it only if it's a part of Ecma-262 |
Just saying that it can be done efficiently on the level of engine, but if not, we can just rely on own parsing pass, which will be less efficient, but still work. Personally, I really like this idea independently of specific implementation details. |
@rvagg We do need v8 buy in for the case of We have a few contacts at ChakraCode we have talked to in private about the steps necessary for this, I had a very specific call with @bterlson about parsing and bytecode caching. It was held under the idea of a grammar change, but they seemed pretty unfazed by things. @RReverser v8 has said it would be non-trivial for us to get a parser that does both modes. It may be possible to get them to provide it, but not in the near future. A key part to understanding the way to get max perf is:
All this said, I am heavily on the side of a file extensions unless this removal of ambiguity lands in spec. File extensions do not scale like parsing does; but, extending the spec has gotten us arguments about doing things not to spec in the past. I fear we will get bitten in some way where the spec does not consider the implications outside of browsers like "uncaughtRejection" is currently dealing with. |
To echo a bit of @bmeck, after meeting with the CTC it became clear that Performance is not a big concern. Investigations were had, benchmarks run (@trevnorris), and the numbers showed that even without caching, and worse case double parsing many many files, that the performance impact was not a blocker. I can't see a future in which engines don't help Node achieve its goals. V8 and Chakra are already optimizing specifically for Node and are invested in Node on several fronts. SpiderMonkey has experiments in the Node space as well. As for the TC39, I'm optimistic. This July will be @bmeck's first meeting with them as a TC39 member. It's going to be great to have Node represented there. I'm sure something can come out of the meeting to avoid the "doing things not to spec" arguments. While iterating on this proposal @bmeck and I kept coming back to keeping it simple. What came out was something that can scale as more parse goals are added, something that supports stdin, something that doesn't require lots of metadata, and something that "just works" for developers without the ecosystem concerns of the current proposal. |
Non-module code is allowed top-level await? |
@trevnorris |
@jdalton is working on it, in the meantime /cc @aruneshchandra @nodejs/chakracore |
@rvagg |
🤘 I pinged @ajklein (V8) who echoed that providing an API for Node would be doable. From chatting with both Chakra/V8 folks it looks like the new API would not have the ES spec change as a hard requirement either. An engine API like this could be useful beyond Module detection too, e.g. detecting something like asm.js as a goal. |
@jdalton So wait, do we not need to change the spec then, or does changing the spec just make the parseability faster? |
@Fishrock123 |
@rvagg @Fishrock123: Is this all Node.js needs? Or do we want to know that Chakra and V8 will parse a module without import/export keywords as a script? I think that would be the spec change. |
@joshgav I am heavily, and I do stress heavily, against doing parsing while ambiguity remains in the spec. It leads to surprises for developers in non-Node environments, and lovely comments about how Node is non-standard by spec developers. It also has led to situations where spec has not considered implication on Node since behavior is seen as non-standard. We can take the parsing approach if given an API, but I will fight it will all my might if it is not endorsed by TC39 / spec. |
Code moving from node to the browser (current npm workflow) will continue to work regardless of spec change, so that's nice.
I think having you on on the TC39, representing Node, will help avoid issues like that going forward :)
🙌 |
Reading through this, some reactions:
|
Correct, I think it should be merged in order to show commitment (just like the file extension was). I doubt we can make easy progress without a vote of confidence prior to getting support. We are not moving to |
To rephrase: I agree with @bmeck that committing to this approach should be contingent on TC39 blessing the approach (by recommendation or spec change) and V8 giving us a That said, assuming that this EP represents the CTC's intent with regards to modules, we should either re-include the |
As requested from today's CTC meeting, I moved a bit of the ecma262-solution section over to this PR. |
Thanks to @jdalton for his comments today at the CTC meeting about @nodejs/collaborators if possible, we'd like to have a vote at the next @nodejs/ctc meeting and we'd like input from the broader group before that can happen. Please review the change this PR makes, and comment here if you have any questions or have any concerns that we should hold up the process to resolve. A The basic question here goes something like this: If TC39 agrees to revisiting the Modules spec to accommodate the needs spelled out in https://github.com/bmeck/UnambiguousJavaScriptGrammar and the ability to detect filetype is made possible by our JS engine(s) then we would use such a mechanism to load, detect and run As for how to reflect this conditionality in the doc, I like @chrisdickinson's suggestion of including the |
I can't say I understand at the current time what |
Cool. I can add a link to the current
We should clarify why the fork, Node restricting ES modules to having at least one import/export and browsers not, is an issue. Especially because:
I've been a bit wiggly with the proposal text:
It's wiggly because at the time the root concern seemed to be upset emails/tweets about not following the spec, so a 👍 of some kind from TC39 would provide a way to avoid that. I think clarifying the issue would help the wiggles :) |
I am more concerned with things progressing in spec without consideration to the approach taken by Node to things, unhandledRejection is something that falls in that category of having to deal with things because it was not well understood that Node had a different set of expectations. The emails and discussions are also a concern, but show deeper problem of "non-standard" behavior not being taken into as much consideration as spec progresses. |
@bmeck |
TC39 is consensus based, I could influence things but not guarantee that any non-standard behavior would be respected in the future. |
I think Node representation at the TC39 goes a long way. I'm not sure guarantees are guaranteed. For example, I relied on a the spec'ed If design choices that effect Node are a concern, having friends like Chakra/V8 can help. Node/Microsoft/Google/jQuery-Foundation should be able to elevate concerns. I see Node being a part of the TC39 as a way to get things like the Node package ecosystem taken into account when new built-in APIs are proposed, in much the same way folks look to browsers for API conflict investigations. |
Noting here for clarity that this was added in response to the request above:
We'll try and move for a vote at the CTC meeting today unless anyone has reason to hold it up further. |
🎉 |
PR-URL: #33 Reviewed-By: CTC
Thanks much! Landed in 86e0241. |
This PR replaces section 5.1 of the ES6 Module Interoperability proposal with the UnambiguousJavaScriptGrammar proposal.
TL;DR
excessive scaffolding
.js
files by parsing as one grammar and falling back to others