Skip to content

for-of output is suboptimal #394

@RReverser

Description

@RReverser

Not sure which particular project this issue belongs to, but I guess let's track it here for now.

Currently microbundle results in extra bytes in code using for-of (found this as part of dlv experiments).

Example:

export default function dlv(arr, x, sum) {
    sum = 0;
	for (x of arr) {
		sum += x;
	}
    return sum;
}

Currently results in:

export default function(r,t,e){e=0;for(var n=0,f=r;n<f.length;n+=1)e+=f[n];return e}

This is suboptimal for several reasons:

  1. When for-of is done over an existing variable, the result currently introduces yet another one - f - just to store the array again.
  2. t is completely unused in the result, when it could be reused for other purposes (e.g. the counter).
  3. n+=1 should be replaced with just f++.

An optimal output would instead look like:

export default function(r,t,e){for(t=0,e=0;t<r.length;t++)e+=r[t];return e}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions