Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript snippet runner supporting ES 6 (like jsFiddle)

Apparently, neither jsFiddle, nor codepen.io support ES6 syntax (e.g. running let x = 10 will throw an error - see for yourself).

Obvious choice would be es6fiddle, but it produces clearly false results (block-scoped variable i stays defined out of scope).

Is there any snippet runner at all, supporting ES6?

like image 506
Arnthor Avatar asked Oct 19 '22 22:10

Arnthor


2 Answers

You could try Babel. I don't know how it works under the hood, but Ember.js is using it as an ES6 polyfill, so it should be pretty reliable. They provide a web-based console for you to play around with. It shows you what your ES6 code ends up being transformed into: https://babeljs.io/repl/

like image 148
MarkPlewis Avatar answered Oct 22 '22 12:10

MarkPlewis


The particular problem you are seeing is due to a bug in Traceur, the ES6 to ES5 transpiler that many snippet runners use to add "ES6 support." You'll find that such runners are generally limited by the software running them, and in the case of Traceur, that means usually-excellent, but sometimes-buggy, ES6 support.

like image 36
Domenic Avatar answered Oct 22 '22 11:10

Domenic