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 arrow functions #206

Closed
bjrne opened this issue Dec 9, 2020 · 2 comments
Closed

Support for arrow functions #206

bjrne opened this issue Dec 9, 2020 · 2 comments

Comments

@bjrne
Copy link

bjrne commented Dec 9, 2020

I could not find an issue regarding arrow functions so far, so I hope this is the right place and no duplicate.
As a lot of Javascript example code works with functions using the arrow syntax, I was surprised to find out that this interpreter does not seem to be able to handle these.
Example that you can paste into the live demo:

// works:
alert((function(x){return x})(3));
// does not work:
alert((x => x)(3));

For my purposes I can use the longer variant, but it would be pretty neat if the shorter syntax was supported. At least a hint in the docs or a list of supportedd features would be very much appreciated. Thanks for the nice project!

@NeilFraser
Copy link
Owner

Arrow functions are a feature of ES6. See issue #186.

@raymonable
Copy link

I've written a transpiler specifically for arrow functions, and it simply converts them into regular functions. Hope this helps!

var _ = "() => {}"
var [__, ___] = [(/\s*\)\s*=\s*>\s*{/g)];
var ____ = [];
while (___ = __.exec(_)) {
    let __ = ___.index;
    while (_.substring(__, __ + 1) !== "(" || __ <= 0) {
        __ -= 1;
    }
    ____.push(__)
};
var __ = 0;
____.forEach((index) => {
    __ += index;
    _ = _.substring(0, __) + 'function' + _.substring(__)
    __ += ('function').length - 1
})
_ = _.replace((/\s*\)\s*=\s*>\s*{/g), ') {');
console.log(_) // _ is the output.

@NeilFraser NeilFraser closed this as not planned Won't fix, can't repro, duplicate, stale Aug 16, 2024
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