diff --git a/__tests__/__fixtures__/nested/contrived/code.js b/__tests__/__fixtures__/complex/contrived/code.js similarity index 100% rename from __tests__/__fixtures__/nested/contrived/code.js rename to __tests__/__fixtures__/complex/contrived/code.js diff --git a/__tests__/__fixtures__/nested/contrived/output.js b/__tests__/__fixtures__/complex/contrived/output.js similarity index 100% rename from __tests__/__fixtures__/nested/contrived/output.js rename to __tests__/__fixtures__/complex/contrived/output.js diff --git a/__tests__/__fixtures__/nested/deep-every/code.js b/__tests__/__fixtures__/complex/deep-every/code.js similarity index 100% rename from __tests__/__fixtures__/nested/deep-every/code.js rename to __tests__/__fixtures__/complex/deep-every/code.js diff --git a/__tests__/__fixtures__/nested/deep-every/output.js b/__tests__/__fixtures__/complex/deep-every/output.js similarity index 100% rename from __tests__/__fixtures__/nested/deep-every/output.js rename to __tests__/__fixtures__/complex/deep-every/output.js diff --git a/__tests__/__fixtures__/nested/deep-iterable/code.js b/__tests__/__fixtures__/complex/deep-iterable/code.js similarity index 100% rename from __tests__/__fixtures__/nested/deep-iterable/code.js rename to __tests__/__fixtures__/complex/deep-iterable/code.js diff --git a/__tests__/__fixtures__/nested/deep-iterable/output.js b/__tests__/__fixtures__/complex/deep-iterable/output.js similarity index 100% rename from __tests__/__fixtures__/nested/deep-iterable/output.js rename to __tests__/__fixtures__/complex/deep-iterable/output.js diff --git a/__tests__/__fixtures__/nested/deep-map/code.js b/__tests__/__fixtures__/complex/deep-map/code.js similarity index 100% rename from __tests__/__fixtures__/nested/deep-map/code.js rename to __tests__/__fixtures__/complex/deep-map/code.js diff --git a/__tests__/__fixtures__/nested/deep-map/output.js b/__tests__/__fixtures__/complex/deep-map/output.js similarity index 100% rename from __tests__/__fixtures__/nested/deep-map/output.js rename to __tests__/__fixtures__/complex/deep-map/output.js diff --git a/__tests__/__fixtures__/complex/destructured-params/code.js b/__tests__/__fixtures__/complex/destructured-params/code.js new file mode 100644 index 00000000..c820b4f3 --- /dev/null +++ b/__tests__/__fixtures__/complex/destructured-params/code.js @@ -0,0 +1,5 @@ +import { forEach } from '../../../../src/inline-loops.macro'; + +forEach([], ([a, b]) => { + console.log(a, b); +}); diff --git a/__tests__/__fixtures__/complex/destructured-params/output.js b/__tests__/__fixtures__/complex/destructured-params/output.js new file mode 100644 index 00000000..c717f4ff --- /dev/null +++ b/__tests__/__fixtures__/complex/destructured-params/output.js @@ -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); +} diff --git a/__tests__/__fixtures__/nested/jsx/code.js b/__tests__/__fixtures__/complex/jsx/code.js similarity index 100% rename from __tests__/__fixtures__/nested/jsx/code.js rename to __tests__/__fixtures__/complex/jsx/code.js diff --git a/__tests__/__fixtures__/nested/jsx/output.js b/__tests__/__fixtures__/complex/jsx/output.js similarity index 100% rename from __tests__/__fixtures__/nested/jsx/output.js rename to __tests__/__fixtures__/complex/jsx/output.js diff --git a/__tests__/__fixtures__/nested/shallow-every/code.js b/__tests__/__fixtures__/complex/shallow-every/code.js similarity index 100% rename from __tests__/__fixtures__/nested/shallow-every/code.js rename to __tests__/__fixtures__/complex/shallow-every/code.js diff --git a/__tests__/__fixtures__/nested/shallow-every/output.js b/__tests__/__fixtures__/complex/shallow-every/output.js similarity index 100% rename from __tests__/__fixtures__/nested/shallow-every/output.js rename to __tests__/__fixtures__/complex/shallow-every/output.js diff --git a/__tests__/__fixtures__/nested/shallow-iterable/code.js b/__tests__/__fixtures__/complex/shallow-iterable/code.js similarity index 100% rename from __tests__/__fixtures__/nested/shallow-iterable/code.js rename to __tests__/__fixtures__/complex/shallow-iterable/code.js diff --git a/__tests__/__fixtures__/nested/shallow-iterable/output.js b/__tests__/__fixtures__/complex/shallow-iterable/output.js similarity index 100% rename from __tests__/__fixtures__/nested/shallow-iterable/output.js rename to __tests__/__fixtures__/complex/shallow-iterable/output.js diff --git a/__tests__/__fixtures__/nested/shallow-map/code.js b/__tests__/__fixtures__/complex/shallow-map/code.js similarity index 100% rename from __tests__/__fixtures__/nested/shallow-map/code.js rename to __tests__/__fixtures__/complex/shallow-map/code.js diff --git a/__tests__/__fixtures__/nested/shallow-map/output.js b/__tests__/__fixtures__/complex/shallow-map/output.js similarity index 100% rename from __tests__/__fixtures__/nested/shallow-map/output.js rename to __tests__/__fixtures__/complex/shallow-map/output.js diff --git a/__tests__/transform.test.js b/__tests__/transform.test.js index bf39d601..7e4d0807 100644 --- a/__tests__/transform.test.js +++ b/__tests__/transform.test.js @@ -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', }); diff --git a/src/helpers.js b/src/helpers.js index 97ea7efe..1067435c 100644 --- a/src/helpers.js +++ b/src/helpers.js @@ -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]; @@ -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];