A Babel plugin to inline methods on array literals.
Warning: If you have getters on objects in arrays, this could be lossy.
Example:const x = { get a () { someSideEffect(); return 2 } }; [x.a].length; // transforms to const x = { get a () { someSideEffect(); return 2 } }; 1;
In:
[1, 2, 3].concat([4, 5, 6]);
[a, b, c].concat([d, e], f, g, [h]);
[1, 2, 3]['concat']([4, 5, 6]);
[1, 2, 3][`conc${"a"}t`]([4, 5, 6]);
[1, 2, 3][concat]([4, 5, 6]);
[1, 2, 3].push([4, 5, 6]);
[1, 2, 3].join();
[a, 'b', 'c'].join();
['a', 'b', 'c'].join();
['a', 'b', 'c'].join(a);
['a', 'b', 'c'].join('@');
[1, 2, 3].length;
[1, 2, 3][1];
[1, 2, 3]['1'];
[].shift();
[1, 2, 3].shift();
[1, 2, 3].slice();
[1, 2, 3].slice(1);
[1, 2, 3].slice(0, 2);
[1, 2, 3].slice(0, -1);
[1, 2, 3].pop();
[a, b, c].pop();
[].pop();
[a, b, c].reverse();
[1, 2, 3].reverse();
[1, 2, 3].splice(1);
Out:
[1, 2, 3, 4, 5, 6];
[a, b, c, d, e, f, g, h];
[1, 2, 3, 4, 5, 6];
[1, 2, 3][`conc${"a"}t`]([4, 5, 6]);
[1, 2, 3][concat]([4, 5, 6]);
4;
"1,2,3";
[a, 'b', 'c'].join();
"a,b,c";
['a', 'b', 'c'].join(a);
"a@b@c";
3;
2;
2;
undefined;
2;
[1, 2, 3];
[2, 3];
[1, 2];
[1, 2, 3].slice(0, -1);
3;
c;
undefined;
[c, b, a];
[3, 2, 1];
[2, 3];
Why not?
$ npm install -D b̟̞͎̙̽̉͗͗a̭͇̻̥͗̀̾̕b̧̨͇̥̀̒̀͘e͚̞̬͑́̊͑ͅḹ̼̠̫̏́͗-̧̘̖̣̇̒͌͌p̧͍̬̫͒̔͂͝l̠̙̻̘̓̾̃̏ṳ̜̥̺̉́͒͝g̗͉̖̝̒̄̊̈́ì̺̩͎͓́̄͝n̻̮̖̟̋̿̌̕-̡̨̫̟̾̓̃̕ȕ͈̼̝̯̂̊͠ṉ̞͚̭͂͑̿̾d̦̥̞̘̿͌͌̌ě͎͓̼̲̄̾̎f̡̬̝͌̆̇͜͝ị̬̗̑̎̓̍͜n̡̲̻̞̎̉͠͝e̼̭̦̹͊̄̀͌d͎̩̪͊̀͘̕͜