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

Support for Node 4 #109

Closed
Rich-Harris opened this issue Dec 4, 2016 · 6 comments
Closed

Support for Node 4 #109

Rich-Harris opened this issue Dec 4, 2016 · 6 comments
Labels
Milestone

Comments

@Rich-Harris
Copy link
Member

Due to laziness on my part, Svelte currently only runs in Node 6 and above. We should transpile it to ES5 using either Babel or Bublé (Bublé would be faster and require less config, but we would have to rewrite code that uses for ( const x of y ) {...})

@jacobmischka
Copy link
Contributor

I've seen you use dangerousForOf in projects before, what's different about the loops in svelte that doesn't allow that?

@Rich-Harris
Copy link
Member Author

Technically, for ( const x of y ) {...} assumes y is an Iterator. To transpile it correctly, you have to add a lot of code with nested try-catch statements which is less than ideal, and you have to polyfill the Symbol object.

Bublé is focused on generating lean code that runs fast, so it doesn't let you do that. The dangerousForOf transform is a half-way house that allows you to use for-of loops as syntactic sugar over array iteration:

for ( var i = 0, list = y; i < list.length; i += 1 ) {
  var x = list[i];
  // ...
}

In Svelte we're using for-of with a tokenizer that implements the Iterator protocol, rather than an array-like object. So dangerousForOf doesn't work. It'd be easy enough to rewrite those sections to not use for-of though.

@jacobmischka
Copy link
Contributor

Oh I see, interesting. When using buble I'd always just used it straightaway and it seemed to work, so I wasn't sure exactly its conditions. Maybe I should go back and check now though.

@leebyron
Copy link

leebyron commented Dec 7, 2016

Hey Rich - just stumbled on this issue - I had a fork of buble sitting around that I was using for node 4 support for some private project that fixed this issue - I just wrote up a PR for it at https://gitlab.com/Rich-Harris/buble/merge_requests/109

@PaulBGD
Copy link
Member

PaulBGD commented Mar 1, 2017

So what do you want to do for this? Just remove all cases of const x of y ?

@Rich-Harris
Copy link
Member Author

I think so, IIRC — there might be some other stuff that doesn't work in Node 4 (or older browsers), but it might be just that

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

No branches or pull requests

4 participants