HaxeFoundation / HaxeFoundation/haxe

amount of code for js object iteration

Open
#9,867 1 comment 0 reactions 0 assignees View on GitHub
enhancement platform-javascript
Dominant language
Haxe
Stars
6.9k
Forks
715
Avg merge
2d 2h
Merged PRs (30d)
11

Description

Hi,

in haxe 4.1.3 (most likely other as well), unnecessary amount of code is generated for simple object iteration, for example:
```haxe
class Main {
static function main()
{
var set = new js.lib.Set();
for(key in set)
trace(key);
}
}
```
compiled by `haxe --main Main --js main.js -D js-es=6` results in:
```js
let set = new Set();
let jsIterator = set.values();
let _g_jsIterator = jsIterator;
let _g_lastStep = jsIterator.next();
while(!_g_lastStep.done) {
let v = _g_lastStep.value;
_g_lastStep = _g_jsIterator.next();
let key = v;
console.log("Main.hx:6:",key);
}
```
while runtime/browser would be happy with single line of code:
```js
let set = new Set();
for(let key of set)
console.log("Main.hx:6:",key);
```

Would it possible to optimize compiler to reduce the output. Or is there any existing compiler flag available?

thanks

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.