5 ms·
Surely the compiler handles the case of anonymous functions referring to `this` or `arguments` and leaves them alone? edit: the original issue[5] specifically
by masklinn 11y ago
Surely the compiler handles the case of anonymous functions referring to `this` or `arguments` and leaves them alone?
edit: the original issue[5] specifically notes that the anonymous function shouldn't refer to `this` and the corresponding commit has a test case for that, though it doesn't talk about `arguments` so that might break.
[5] https://github.com/mohebifar/xto6/issues/5 https://github.com/mohebifar/xto6/issues/5
- davej 11y agoPerhaps it's fixed on the master branch but it's broken on the websites live transpile thing (which is where I tested it).
- masklinn 11y agoUnlikely, the same commit added it all, I can only assume the offline version behaves similarly (I haven't tested). The compiling seems very inconsistent and fragile: * it won't convert at all if a function literal is returned or assigned to a variable (but it will if the function literal is passed to an other function or for IIFE) * it will generate an incorrect conversion in case the `this` is deref'd for a method call or (directly or indirectly) passed to an other function: these are OK (will not convert) (function () { this; })(); (function () { this.foo; })(); (function () { this.bar + 1; })(); but these are not ok (will convert to incorrect code): (function () { this.foo(); })(); (function () { foo(this); })(); (function () { foo(this.bar); })();