js_of_ocaml icon indicating copy to clipboard operation
js_of_ocaml copied to clipboard

ES6 Support

Open hhugo opened this issue 9 years ago • 13 comments

http://es6-features.org

related to

  • #1031
  • #1017
  • #989
  • #972

hhugo avatar Jul 31 '16 10:07 hhugo

Something new about ES6 support?

dannywillems avatar Sep 12 '16 09:09 dannywillems

no. I don't have time to work on this now. What's your use case ?

hhugo avatar Sep 12 '16 10:09 hhugo

No real use case for the moment but as lots of popular JavaScript frameworks switch to ES6 (like React and ReactNative), it would be great to have ES6 support. I would like to begin a binding to ReactNative and use the ES6 interface is easier.

dannywillems avatar Sep 12 '16 10:09 dannywillems

One way would be to rely on some external javascript parser (https://github.com/facebook/flow ?)

hhugo avatar Dec 11 '18 16:12 hhugo

Just for comparison: BuckleScript also compiles to ES5, but supports ES6 modules.

kevinji avatar Mar 23 '19 21:03 kevinji

WeakSet and WeakMap seem exciting to me.

jmcarthur avatar Nov 01 '20 12:11 jmcarthur

How are WeakSet and WeakMap related to this issue ? My understanding is that one can already use them to write bindings.

hhugo avatar Nov 01 '20 20:11 hhugo

I'm fact, they are already used in the jsoo runtime. See https://github.com/ocsigen/js_of_ocaml/blob/09d5731241917577e9c16b6a0063c23baae00df8/runtime/marshal.js#L435

hhugo avatar Nov 01 '20 20:11 hhugo

Ah, I had thought the reason js_of_ocaml didn't support Weak was just because JavaScript doesn't support any form of weak references, but maybe I'm just wrong. Maybe it's just that either (1) things were different in the past or (2) WeakMap/WeakSet are somehow not sufficiently powerful.

jmcarthur avatar Nov 02 '20 19:11 jmcarthur

Indeed, the ocaml weak reference semantic cannot be implemented using weak map / weak set

hhugo avatar Nov 02 '20 19:11 hhugo

Oh, I see, WeakMap and WeakSet are not what I expected them to be. Their keys are weak!

I have now also learned about WeakRef, but it looks like browser support is still quite limited.

jmcarthur avatar Nov 02 '20 20:11 jmcarthur

It might be worth revisiting this in 2021.

Because the output uses Common JS, it can be difficult to integrate with existing projects that use modern, ES6 style JavaScript. ES6 would also allow the JS to work client-side or server-side by default, since browsers now have broad ES6 support.

jasongitmail avatar Aug 11 '21 18:08 jasongitmail

One could try to port new js feature implemented in https://github.com/returntocorp/pfff/blob/develop/lang_js/parsing/parser_js.mly

hhugo avatar Sep 22 '21 11:09 hhugo

Oh, I see, WeakMap and WeakSet are not what I expected them to be. Their keys are weak!

I have now also learned about WeakRef, but it looks like browser support is still quite limited.

WeakRef are now used to implement the ocaml weak semantic.

hhugo avatar Jan 18 '23 12:01 hhugo

#1386 allows to parse utf8 identifier.

hhugo avatar Jan 18 '23 12:01 hhugo