maxtaco / tamejs

JavaScript code rewriter for taming async-callback-style code

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

arguments array doesn't work before defer

sixcircuit opened this issue · comments

Don't know if this is an easy one or not:

function argumentsDoNotWork(){
    console.dir(arguments);
    await{ setTimeout(defer(), 100);
}

argumentsDoNotWork("foo", "bar");

It's because the arguments array gets wrapped in an inner function by the parser. It makes sense to me I can't use arguments after the defer, but I'd expect I could use it before the defer. I can work around it by having a function without defer call the function with defer, but it's problematic because the code doesn't do what you'd expect. I ran around with this for a couple hours before I figured it out. If it's easy, a fix would be great. I'd do it but I don't understand the parser well enough. I figure you could do it quickly, or not at all. I imagine the fix might also allow you to do returns from the function before you hit the defer as well. For example:

function ret(){
    return(10);
    setTimeout(defer(), 100);
}

var ten = ret();

Best,

Kendrick