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
Create preset consisting solely of syntax plugins #7660
Comments
Hey @SimenB! We really appreciate you taking the time to report an issue. The collaborators If you need any help, or just have general Babel or JavaScript questions, we have a vibrant Slack |
/cc @bcoe |
Is this preset supposed to be used for tools only? And yeah the issue is about Stage X plugins. Otherwise they would be on by default already (and the only reason why they aren't is because we didn't update v6). You can already enable syntax via |
Yeah, I don't think just parsing and no transformation makes sense for non-tools, does it?
Then we'd have to manage the syntax modules ourselves, right? Not a terrible burden of course, but not ideal either. For my use case, just getting the plugins needed to parse whatever the current version of node supports would be enough, that should allow us to avoid the issue with stages, right? |
In Babel 7 you will be able to use |
Not really. There is no babelrc involved. We can keep a list of syntax plugins to apply of course, but I was hoping to avoid that source of truth living in Jest |
Is the case here specifically for syntax that has been accepted as stage 4? We should certainly make it parsed by default now since it has landed in stage 4. Are there cases other than newly-landed official syntax where you'd expect no |
This is specifically for syntax shipping in the currently running version of node (regardless of stage), so the user probably does not have the plugin in their config (if they even have a config, babel is an implementation detail of Jest). |
Gotcha. I could see an argument for us having a preset like
Doing this broadly is something we're unlikely to allow because Babel supports some syntax options that conflict with one-another, so opting into "all possible" is not an option available to us. |
Fair enough, let's keep this focused on the node runtime use case then, instead of all syntaxes (syntaxi?). A preset or a specific plugin sounds great! I think it'd need to support a target - I don't want it to enable object spread on node 6, for instance. For our purposes we'd say I think stages - for the purposes of a node-specific thing - should be disregarded. If it ships (unflagged) in Node it should be in, IMO. I'm sure there will be requests for features behind flags, but at that point I'm willing to say "add the babel plugin yourself" to the users. |
If we're only enabling the syntax plugin, the original code would still be passed through to Node and would throw there. It seems like it would complicate things to have a target on the preset and I'm not convinced it would be much more useful than just opting into anything that the most recent Node supports. |
That's a very good point! The syntax error from babel is prettier than the one from node (and could potentially say "add plugin x to fix it"), but I guess that doesn't really matter :p |
It should already do this 😄 |
This came up again now for |
And private class fields 😅 |
@nicolo-ribaudo any chance of reviving this? Came up yet again with numeric separators this time |
@SimenB I don't think that it fits in this repository, but I have published https://github.com/nicolo-ribaudo/babel-preset-current-node-syntax. It detects the features supported by the current Node.js version and enables the corresponding syntax plugins. So far it supports:
The following Stage 3 features aren't supported yet because I don't know how to test them, but any suggestion is welcome:
What do you think about it? |
Exciting, thanks! Only other I could think of that has caused issues would be bigint literals but that might have been enabled by default already? Thoughts on plugins enabled by default in newer versions of babel but not in older ones? Just teach users to upgrade their babel version? |
Yes, BigInts are enabled by default since v7.9.0.
I only added features not supported by 7.9.0 (which is the Do you think I should target an older version? Maybe 7.8.0 which is 3 months old? |
Aiming for 7.8 sounds good to me 👍 Then we can match that peer dependency in the next version of jest. Our current peer is just 7.0.0 |
I've landed that preset in Jest now, so I'll consider this solved (finally!). Thanks! |
And lastly, for anyone following this, Jest 25.3.0 has been released with that preset. Super happy this is solved now 😀 |
Choose one: is this a bug report or feature request?
Feature request
Expected Behavior
When creating tooling, there are multiple reasons to use babel as part of the pipeline. For instance there is an Istanbul plugin for coverage and Jest uses it for mock hoisting.
But since babel has to be able to parse the code in order to make changes to it, features working without Babel present will break when parsed by Babel if the syntax plugins are not present (see istanbuljs/babel-plugin-istanbul#141 and jestjs/jest#4519).
I expect to be able to run Babel on code that parses fine using Node. But just parsing all possible syntax makes sense to me, so that we can apply transformations to the parts we care about without Babel blowing up.
Current Behavior
Syntax error for e.g. Object spread
Possible Solution
A preset containing all syntax plugins. Not sure about stages...
Context
See "Expected Behavior"
Your Environment
The text was updated successfully, but these errors were encountered: