codemix / codemix/babel-plugin-closure-elimination
Closures that are modified (like objects) are mistaken for static functions
- Dominant language
- JavaScript
- Stars
- 364
- Forks
- 15
- PR merge metrics
- No merged PRs in 30d
Description
In general plugin speeds up my code-base quite a bit, but in one crucial part it breaks my (admittedly quite unusual) code: [the part where I generates a recursive tree of functions](https://gist.github.com/JobLeonard/a47692a1f77bebc06c2518f321fa7efc). ~~I found a work-around~~, but I _think_ this counts as a bug.
The part of the code in question that breaks is this:
```js
//== INPUT
export function vectorOf(patternArr){
let retVal= function(){};
retVal.encoder = encodeVector(patternArr);
retVal.decoder = decodeVector(patternArr);
return retVal;
}
//== OUTPUT, functionally different:
function _retVal2() {}
function vectorOf(patternArr) {
var retVal = _retVal2;
retVal.encoder = encodeVector(patternArr);
retVal.decoder = decodeVector(patternArr);
return retVal;
}
```
(note that I have already removed the fat arrow syntax, but the problem remains)
The problem is that `vectorOf` should return newly instantiated function object whenever it is called, instead of modifying a static one. I understand that the whole point of this plugin is turn closures into the latter, but the part where I modify the function object breaks that :P
EDIT: my workaround didn't work, turns out I forgot to turn on the `closure-elimination` plugin while testing.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.