Skip to content

Commit

Permalink
bailout of aggressive inlining when destructuring params
Browse files Browse the repository at this point in the history
Fixes #4
  • Loading branch information
planttheidea committed Jun 15, 2019
1 parent 0bbc0fb commit b5a45a1
Show file tree
Hide file tree
Showing 20 changed files with 20 additions and 4 deletions.
5 changes: 5 additions & 0 deletions __tests__/__fixtures__/complex/destructured-params/code.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { forEach } from '../../../../src/inline-loops.macro';

forEach([], ([a, b]) => {
console.log(a, b);
});
11 changes: 11 additions & 0 deletions __tests__/__fixtures__/complex/destructured-params/output.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const _iterable = [];

const _fn = ([a, b]) => {
console.log(a, b);
};

for (let _key = 0, _length = _iterable.length, _value; _key < _length; ++_key) {
_value = _iterable[_key];

_fn(_value, _key, _iterable);
}
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions __tests__/transform.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ pluginTester({

pluginTester({
babelOptions: BABEL_OPTIONS,
fixtures: path.join(__dirname, '__fixtures__', 'nested'),
fixtures: path.join(__dirname, '__fixtures__', 'complex'),
filename: __filename,
plugin,
title: 'Nested references',
title: 'Complex references',
});
4 changes: 2 additions & 2 deletions src/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ function getReduceResultStatement(t, handler, fn, result, value, key, iterable,
// eslint-disable-next-line prefer-destructuring
body = body.body;

if (body.length === 1) {
if (body.length === 1 && handler.params.every(param => t.isIdentifier(param))) {
const [r, v, k, i] = handler.params;
const node = body[0];

Expand Down Expand Up @@ -153,7 +153,7 @@ function getResultStatement(t, handler, fn, value, key, iterable, path) {
// eslint-disable-next-line prefer-destructuring
body = body.body;

if (body.length === 1) {
if (body.length === 1 && handler.params.every(param => t.isIdentifier(param))) {
const [v, k, i] = handler.params;
const node = body[0];

Expand Down

0 comments on commit b5a45a1

Please sign in to comment.