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

[Iced3] ES2015 modules support #198

Open
laurentpayot opened this issue Nov 15, 2016 · 20 comments
Open

[Iced3] ES2015 modules support #198

laurentpayot opened this issue Nov 15, 2016 · 20 comments

Comments

@laurentpayot
Copy link

laurentpayot commented Nov 15, 2016

Hello there, a little question.

Since version 1.11 CoffeeScript supports ES2015 import and export syntax by producing an import or export statement in the resulting output. We have to add a layer of transpiler like babel or target ES6 to make it work, just like Iced3. But in Iced3, with babel, when I use the import syntax I get error: reserved word 'import'.

Is the IcedCoffeeScript codebase moving away from CoffeeScript on this point ?

@laurentpayot
Copy link
Author

I've just noticed #194 but it doesn't seem to work…

@maxtaco
Copy link
Owner

maxtaco commented Nov 15, 2016

I'll try to cut a release today. We just haven't released in a bit. Thanks!

@laurentpayot
Copy link
Author

laurentpayot commented Nov 15, 2016

Ah yes it has not been released yet and I have issues building it (Error: Cannot find module 'iced-runtime-3'). Thanks @maxtaco!

@maxtaco
Copy link
Owner

maxtaco commented Nov 15, 2016

Ok, should be live in v111.1.1

That's a lot of 1s!

Big thanks to @zapu who did all of the work.

@laurentpayot
Copy link
Author

ES2015 imports are now working when using promises.
In order to use use async/defer, I have to install the iced-runtime-3 module. But once this module installed ES2015 imports are not working anymore.

@maxtaco Is a new release also needed for iced-runtime-3?

@maxtaco
Copy link
Owner

maxtaco commented Nov 15, 2016

I didn't think so. I wonder what is up.

On Tuesday, November 15, 2016, Laurent Payot [email protected]
wrote:

ES2015 imports are now working when using promises.
In order to use use async/defer, I have to install the iced-runtime-3
module. But once this module installed ES2015 imports are not working
anymore.

@maxtaco https://github.com/maxtaco Is a new release also needed for
iced-runtime-3?


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
#198 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AA05__2SAvupqM8_Tgft5-WMOSghQ5NVks5q-d3TgaJpZM4Kyo5f
.

@zapu
Copy link
Collaborator

zapu commented Nov 15, 2016

Weird, maybe installing iced-runtime-3 overwrites iced-coffee-script with a different version?

@maxtaco
Copy link
Owner

maxtaco commented Nov 15, 2016

It really shouldn't. I am st a conference today so might not get a chance
to look right away.

On Tuesday, November 15, 2016, Michał Zochniak [email protected]
wrote:

Weird, maybe installing iced-runtime-3 overwrites iced-coffee-script with
a different version?


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
#198 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AA05_8vsoasmmwiYbKOcVtBG_5-OA_Vfks5q-d5TgaJpZM4Kyo5f
.

@laurentpayot
Copy link
Author

By the way I'm using iced3 -c script.coffee && babel-node script.js for my tests...

@zapu
Copy link
Collaborator

zapu commented Nov 15, 2016

Hm, but won't iced3 -c compile just the script.coffee, so anything that script.js tries to import might not be compiled?

@laurentpayot
Copy link
Author

laurentpayot commented Nov 15, 2016

I'm importing "standard" js (Firebase modules). And I'm also struggling to get any result from Firebase createUser() (that returns a promise) with the await/defer syntax. Not to mention catching errors…

@zapu
Copy link
Collaborator

zapu commented Nov 15, 2016

async/defer is "just" a syntactic sugar for callback based asynchronous functions. So in theory you could try to do something like await promise_obj.then defer result but I'm not sure how this would turn out in your code. It might make more sense to just use the promise normally and pass anonymous functions as arguments to then.

@zapu
Copy link
Collaborator

zapu commented Nov 15, 2016

I will try to experiment with iced3 -c and babel-node once I get off work, in few hours.

@laurentpayot
Copy link
Author

Thank you so much @zapu, it really helped!
Now I'm using something like
await promise_obj.then(defer result).catch((error) -> console.log(error.message))
in a synchronous-like way of coding. Amazing 😃

@laurentpayot
Copy link
Author

I still have the ES2015 import issue with await/defer, I get error: import statements must be at top-level scope, if it helps you…
Thanks again for your time!

@zapu
Copy link
Collaborator

zapu commented Nov 15, 2016

If you have top-level await/defer, it has to wrap your entire file in a function, which probably causes this error. Iced should probably handle this better, I overlooked the fact that this may be an issue. Is this the case here?

@laurentpayot
Copy link
Author

laurentpayot commented Nov 15, 2016

Spot on. Yes after wrapping my await/defer in a function the imports issues are gone.

But now if using ES2015 imports when I call my function I get:

   __iced_passed_deferral = iced.findDeferral(arguments);
                           ^

ReferenceError: iced is not defined

@zapu
Copy link
Collaborator

zapu commented Nov 15, 2016

What are your compile flags right now?

Can you try something like iced3 -b -c -I node script.coffee?

@laurentpayot
Copy link
Author

I tried and it worked! The -I node option was missing. That's strange because the node mode is supposed to be the default, isn't it?

@zapu
Copy link
Collaborator

zapu commented Nov 15, 2016

Yes, but I just remembered that ES6 modules in CoffeeScript forces the bare option, because otherwise the whole code is wrapped in a top-level function anyways. So by doing ES6 import/export, it has to "undo" that behavior. I think there was even a discussion about this in CoffeeScript repo on GitHub. In our case, forcing bare also makes it not include the require('iced-runtime') in the code.

Thank you for going through all of this, I think there are few places that we can make improvements in Iced.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants