Skip to content

minifier: inline constant spread elements into arrays #17358

@armano2

Description

@armano2
var x = [a, b, ...[c, d]]

implies assumption that global Array.prototype[Symbol.iterator] has no side effects

arrays can be in-lined even if there are accessors as there is no behavior change

var x = {
  get b() { console.log('called b!'); return 2; },
  get c() { console.log('called c!'); return 3; }
};
console.log([1, x.b, ...[x.c, 4]]);

sparse arrays

elision in array spread is evaluated to undefined, this changes behavior of map and forEach

console.log([...[1, , 3]]) // [ 1, undefined, 3 ]
console.log([1, , 3]) // [ 1, <1 empty slot>, 3 ]

Metadata

Metadata

Assignees

No one assigned

    Labels

    Priority

    None yet

    Start date

    None yet

    Target date

    None yet

    Effort

    None yet

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions