Skip to content
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

Question: Is there a recommended version of babel preset env to use when transpiling down ES2020 features? #661

Closed
swarajgiri opened this issue May 6, 2020 · 33 comments
Labels
docs Issues containing stuff that ought to be documented

Comments

@swarajgiri
Copy link

swarajgiri commented May 6, 2020

In case we have, can we add a recommendation in the documentation?
I am mostly interested in babel preset for rhino version 1.7.7.1

@gbrail
Copy link
Collaborator

gbrail commented Jun 1, 2020 via email

@phulin
Copy link
Contributor

phulin commented Nov 17, 2020

@gbrail do you have the code to run the compat table generation somewhere? I am currently trying to figure out whether we could somehow mash that together with babel's preset-env to get an automatically updating preset.

@gbrail
Copy link
Collaborator

gbrail commented Nov 18, 2020

Yes!

https://github.com/gbrail/node-compat-table

The "rhinotest.sh" script is the script that's adapted to run against Rhino, and "rhinoall.sh" builds the full table from scratch with all the versions.

It's probably a bit behind, and missing some docs, but if you are able to use it for something useful then that'd be great!

@gausie
Copy link
Contributor

gausie commented Nov 19, 2020

Yes!

https://github.com/gbrail/node-compat-table

The "rhinotest.sh" script is the script that's adapted to run against Rhino, and "rhinoall.sh" builds the full table from scratch with all the versions.

It's probably a bit behind, and missing some docs, but if you are able to use it for something useful then that'd be great!

Amazing!

In the root repository for that fork, they said they'd accept PRs for updated results for Rhino - would you be willing to provide those from your work here? That would mean that @babel/preset-env would work out of the box with Rhino!

EDIT: I spoke too soon. It seems that while compat-table would take the update, @babel/preset-env would need to be forked/monkeypatched anyway as they explicitly don't support Rhino. But it would still be fantastic to post the latest results upstream

@nicolo-ribaudo
Copy link

EDIT: I spoke too soon. It seems that while compat-table would take the update, @babel/preset-env would need to be forked/monkeypatched anyway as they explicitly don't support Rhino. But it would still be fantastic to post the latest results upstream

That document tells that Babel doesn't run in Rhino, but you can still use Babel to produce code that runs in Rhino. This is not going to change (you'll need Node.js to run Babel).

However, we can add Rhino as a valid @babel/preset-env target.

@gausie
Copy link
Contributor

gausie commented Nov 19, 2020

EDIT: I spoke too soon. It seems that while compat-table would take the update, @babel/preset-env would need to be forked/monkeypatched anyway as they explicitly don't support Rhino. But it would still be fantastic to post the latest results upstream

That document tells that Babel doesn't run in Rhino, but you can still use Babel to produce code that runs in Rhino. This is not going to change (you'll need Node.js to run Babel).

However, we can add Rhino as a valid @babel/preset-env target.

Oh that's fantastic, thank you so much for the clarification @nicolo-ribaudo. There is already compatibility information for rhino1_7 though so why is it not included in the list of targets used for validation? If I edit that in my local node_modules it seems to build for rhino (though I haven't yet tested actually running that code)

@phulin
Copy link
Contributor

phulin commented Nov 19, 2020

@nicolo-ribaudo is there anything you need help with on that? I've written a quick and dirty compat-table test runner script for rhino to update the compat-table data files if that's useful. (rhino 1.7, the latest with data in compat-table, is very out of date, but of course adding support for that would work for later versions).

@nicolo-ribaudo
Copy link

Updating the data in compat-table is the first step. Then, you can open a PR to Babel to:

  1. Update compat-table (here)
  2. Update the scripts to generate the compat data (somehwere here)
  3. Check if babel-helper-compilation-targets and/or babel-preset-env need to be updated.

@gausie
Copy link
Contributor

gausie commented Jun 10, 2021

I updated kangax/compat-table with the latest compatibility data for Rhino (compat-table/compat-table#1729) and am now waiting for babel/babel#13448 to be approved which will let you specify rhino as a target in babel and compile your esnext code for it

@gbrail this might be of interest to you!

@tonygermano
Copy link
Contributor

@gausie Nice work! Is it reasonable to assume that e4x will not be supported when compiling to Rhino with Babel?

https://www.ecma-international.org/publications-and-standards/standards/ecma-357/

React's JSX is based on e4x, but e4x has additional syntax and would need to remain unaltered in the compiled source.

For a long deprecated standard, it still gets heavily used in https://github.com/nextgenhealthcare/connect

@tonygermano
Copy link
Contributor

@gausie also not sure about calling the version 1.7. The latest release is 1.7.13. Rhino has been at 1.7.x for more than 10 years.

All of the versions in https://mozilla.github.io/rhino/compat/engines.html are different 1.7 releases.

@gausie
Copy link
Contributor

gausie commented Jun 11, 2021

@gausie Nice work! Is it reasonable to assume that e4x will not be supported when compiling to Rhino with Babel?

https://www.ecma-international.org/publications-and-standards/standards/ecma-357/

React's JSX is based on e4x, but e4x has additional syntax and would need to remain unaltered in the compiled source.

For a long deprecated standard, it still gets heavily used in https://github.com/nextgenhealthcare/connect

It looks like it can do so with an extra plugin!

Babel has a package called preset-env that tells Babel what it should and shouldn't transpile for each browser/engine and the changes I've made just explain to preset-env what Rhino can and can't do so that it can adjust accordingly when you specify Rhino as an engine.

@gausie also not sure about calling the version 1.7. The latest release is 1.7.13. Rhino has been at 1.7.x for more than 10 years.

All of the versions in https://mozilla.github.io/rhino/compat/engines.html are different 1.7 releases.

Very good point, this is just a follow-on from the small amount of Rhino support that already existed using 1.7. I've made some new PRs to include the patch number.

@tonygermano
Copy link
Contributor

tonygermano commented Jun 11, 2021

I just looked into the extra plugin you mentioned, but it looks like it's specifically for transpiling JSX compatible xml literals to code to be used with this library https://github.com/pikamachu/pika-simple-e4x. It even requires @babel/plugin-syntax-jsx to do most of the work.

The JSX syntax plugin might be a good starting point, but there would be quite a bit more to do. Just on the literal side, JSX does not support xml namespaces. The following are all valid syntax in true e4x.

var a = x.*; // wildcard support for all child elements
var a = x..b; // descendants operator
var a = x.(b == c); // filter syntax
var a = x.b::c; // explicit namespace syntax
var a = x.*::c; // also supports wildcards for namespaces
var a = x.@b; // attribute accessor
for each (var a in x) {} // xml list iteration
default xml namespace = 'uri:some/namespace'; // set default namespace

I've never used Babel before, but I assume all of that would cause the parser to choke, even with the JSX plugin.

@gausie
Copy link
Contributor

gausie commented Jun 11, 2021

I have no idea what e4x is or why what you've posted doesn't work sorry.

@tonygermano
Copy link
Contributor

@gausie That's ok. I wasn't expecting you to have an answer. I was mostly documenting what Babel would need to support if someone wanted to use it to compile javascript that contained e4x code. I just tested the code in the Babel repl online and the XMLList literal syntax actually did work with the @babel/plugin-syntax-jsx plugin, so I edited my previous comment to remove it. The rest of the code all causes unexpected token errors during compilation.

I included a link to the specification in a previous comment. https://en.wikipedia.org/wiki/ECMAScript_for_XML

@p-bakker
Copy link
Collaborator

p-bakker commented Jun 22, 2021

@gausie nice work!

Quick question: would this babel preset take into account the non-standard const implementation or the not fully spec-compliant let implementation and down-compile those all to vars?

BTW: once the Babel preset for Rhino is available, I think we should add its existence and how to use it somewhere in a README

@gausie
Copy link
Contributor

gausie commented Jun 22, 2021 via email

@gausie
Copy link
Contributor

gausie commented Jun 22, 2021

Looks like it just down-compiles them all to vars as you suggested

@p-bakker
Copy link
Collaborator

Nice!

@p-bakker
Copy link
Collaborator

@gausie I see babel/babel#13448 got merged.

What is the status of this case now? And what are the steps to take once v1.7.14 gets released?

@nicolo-ribaudo
Copy link

And what are the steps to take once v1.7.14 gets released?

Babel regularly pulls compatibility data from github.com/kangax/compat-table, so when Rhino has new features they should be marked there as supported.

@p-bakker
Copy link
Collaborator

Tnx @nicolo-ribaudo

So the question becomes: what is needed to update the compat-table with the results based on the upcoming release? Or does compat-table somehow automatically pick up the latest Rhino release?

@nicolo-ribaudo
Copy link

nicolo-ribaudo commented Oct 14, 2021

It needs to be done manually, but I think @gausie wrote a test runner to help doing it.

This is an example of what a "new engine version" PR looks like: compat-table/compat-table#1766

@gausie
Copy link
Contributor

gausie commented Oct 14, 2021

Yep! There's a rhino.js in the kangax repo. We'll need to have a change to babel/babel, kangax/compat-table and zloirock/core-js to get everything working. Once we release 1.17.14 I can work on doing all of that as soon as possible!

@gausie
Copy link
Contributor

gausie commented Oct 14, 2021

I think we can close this issue too as you just need to specify rhino: "1.7.13" as a target for preset-env now

@nicolo-ribaudo
Copy link

Note that even if we waited for a minor Babel release to add Rhino support, simple version updates can land in patches (which we release way more frequently).

@p-bakker
Copy link
Collaborator

So if I understand correctly:

  • Kangax compat table now shows the results for Rhino 1.7.3 and Babel has a preset for Rhino 1.7.13. And since that is the case, this case can be closed
  • As soon as 1.7.14 is released,@gausie can do some magic and then the kangax compat table will be updated and Babel will get a Rhino 1.7.14 preset?

If that is correct, I'll close this case, add something related to this to the 1.7.14 release notes and create a case to get it documented how to update the compat tbale and Babel after a new Rhino release

@p-bakker p-bakker added the docs Issues containing stuff that ought to be documented label Oct 14, 2021
@p-bakker p-bakker added this to To do in documentation Oct 14, 2021
@p-bakker
Copy link
Collaborator

@gausie Is my summary in the comment above correct?

@zloirock
Copy link
Contributor

@p-bakker don't forget updating core-js compat data.

@p-bakker
Copy link
Collaborator

@zloirock I have no insight into the process at all, so if you say 'core-js compat data' need to be updated, I gladly believe you, but have no idea what that entails :-)

Thats why I'm asking for clarification in #661 (comment).

Assume the updating of core-js compat data is part of what I referred to as "@gausie can do some magic"

@p-bakker
Copy link
Collaborator

p-bakker commented Jan 7, 2022

@gausie Rhino 1.7.14 has been released, so whatever needs updating can now be updated from 1.7.13 to 1.7.14.

Is that something you're willing to pick up?

Regardless of whether you can pick up that task or not, I think it would be benefitial for all if the required steps can be documented, so for future releases it can become part of the release steps.

Could you share the steps involved? Or even a PR to add the info to https://github.com/mozilla/rhino/blob/master/RELEASE-STEPS.md?

@gausie
Copy link
Contributor

gausie commented Jan 7, 2022

@p-bakker I'll look at doing that this weekend and I'll document the steps as I go.

@p-bakker
Copy link
Collaborator

Closing as the process how to update the babel & the compat table is now documented

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Issues containing stuff that ought to be documented
Projects
Development

Successfully merging a pull request may close this issue.

8 participants