Skip to content

Commit

Permalink
initial implementation of working transform with existing unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
planttheidea committed Dec 15, 2023
1 parent 37cfee0 commit f847f0c
Show file tree
Hide file tree
Showing 166 changed files with 2,786 additions and 1,136 deletions.
23 changes: 15 additions & 8 deletions __tests__/__fixtures__/bailout/early-return/output.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
const _iterable = [1, 2, 3];
const _fn = (value) => {
if (value === 2) {
const _collection = [1, 2, 3];
const _fn = (_value) => {
if (_value === 2) {
return true;
}
};
let _result = [];
for (let _key = 0, _length = _iterable.length, _value; _key < _length; ++_key) {
_value = _iterable[_key];
if (_fn(_value, _key, _iterable)) _result.push(_value);
const _results = [];
for (
let _key = 0, _length = _collection.length, _value, _result;
_key < _length;
++_key
) {
_value = _collection[_key];
_result = _fn(_value, _key, _collection);
if (_result) {
_results.push(_value);
}
}
const result = _result;
const result = _results;
19 changes: 10 additions & 9 deletions __tests__/__fixtures__/bailout/multiple-returns/output.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
const _iterable = [1, 2, 3];
const _fn = (value) => {
if (value === 2) {
const _collection = [1, 2, 3];
const _fn = (_value) => {
if (_value === 2) {
return 82;
}
return value;
return _value;
};
let _result = [];
for (let _key = 0, _length = _iterable.length, _value; _key < _length; ++_key) {
_value = _iterable[_key];
_result[_key] = _fn(_value, _key, _iterable);
const _length = _collection.length;
const _results = Array(_length);
for (let _key = 0, _value; _key < _length; ++_key) {
_value = _collection[_key];
_results[_key] = _fn(_value, _key, _collection);
}
const result = _result;
const result = _results;
15 changes: 10 additions & 5 deletions __tests__/__fixtures__/cached/every/output.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
let _result = true;
for (let _key = 0, _length = array.length, _value; _key < _length; ++_key) {
let _determination = true;
for (
let _key = 0, _length = array.length, _value, _result;
_key < _length;
++_key
) {
_value = array[_key];
if (!fn(_value, _key, array)) {
_result = false;
_result = fn(_value, _key, array);
if (!_result) {
_determination = false;
break;
}
}
const areAllEven = _result;
const areAllEven = _determination;
14 changes: 8 additions & 6 deletions __tests__/__fixtures__/cached/everyObject/output.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
let _result = true;
let _value;
for (let _key in object) {
let _determination = true,
_value,
_result;
for (const _key in object) {
_value = object[_key];
if (!fn(_value, _key, object)) {
_result = false;
_result = fn(_value, _key, object);
if (!_result) {
_determination = false;
break;
}
}
const areAllEven = _result;
const areAllEven = _determination;
11 changes: 6 additions & 5 deletions __tests__/__fixtures__/cached/everyRight/output.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
let _result = true;
for (let _key = array.length - 1, _value; _key >= 0; --_key) {
let _determination = true;
for (let _key = array.length, _value, _result; --_key >= 0; ) {
_value = array[_key];
if (!fn(_value, _key, array)) {
_result = false;
_result = fn(_value, _key, array);
if (!_result) {
_determination = false;
break;
}
}
const areAllEven = _result;
const areAllEven = _determination;
15 changes: 11 additions & 4 deletions __tests__/__fixtures__/cached/filter/output.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
let _result = [];
for (let _key = 0, _length = array.length, _value; _key < _length; ++_key) {
const _results = [];
for (
let _key = 0, _length = array.length, _value, _result;
_key < _length;
++_key
) {
_value = array[_key];
if (fn(_value, _key, array)) _result.push(_value);
_result = fn(_value, _key, array);
if (_result) {
_results.push(_value);
}
}
const onlyEven = _result;
const onlyEven = _results;
13 changes: 8 additions & 5 deletions __tests__/__fixtures__/cached/filterObject/output.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
let _result = {};
let _value;
for (let _key in object) {
const _results = {};
let _result, _value;
for (const _key in object) {
_value = object[_key];
if (fn(_value, _key, object)) _result[_key] = _value;
_result = fn(_value, _key, object);
if (_result) {
_results[_key] = _value;
}
}
const onlyEven = _result;
const onlyEven = _results;
12 changes: 8 additions & 4 deletions __tests__/__fixtures__/cached/filterRight/output.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
let _result = [];
for (let _key = array.length - 1, _value; _key >= 0; --_key) {
const _results = [];
let _result, _value;
for (let _key = array.length, _value, _result; --_key >= 0; ) {
_value = array[_key];
if (fn(_value, _key, array)) _result.push(_value);
_result = fn(_value, _key, array);
if (_result) {
_results.push(_value);
}
}
const onlyEven = _result;
const onlyEven = _results;
15 changes: 10 additions & 5 deletions __tests__/__fixtures__/cached/find/output.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
let _result;
for (let _key = 0, _length = array.length, _value; _key < _length; ++_key) {
let _match;
for (
let _key = 0, _length = array.length, _value, _result;
_key < _length;
++_key
) {
_value = array[_key];
if (fn(_value, _key, array)) {
_result = _value;
_result = fn(_value, _key, array);
if (_result) {
_match = _value;
break;
}
}
const firstEven = _result;
const firstEven = _match;
15 changes: 10 additions & 5 deletions __tests__/__fixtures__/cached/findIndex/output.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
let _result = -1;
for (let _key = 0, _length = array.length, _value; _key < _length; ++_key) {
let _match = -1;
for (
let _key = 0, _length = array.length, _value, _result;
_key < _length;
++_key
) {
_value = array[_key];
if (fn(_value, _key, array)) {
_result = _key;
_result = fn(_value, _key, array);
if (_result) {
_match = _key;
break;
}
}
const firstEven = _result;
const firstEven = _match;
10 changes: 1 addition & 9 deletions __tests__/__fixtures__/cached/findIndexRight/output.js
Original file line number Diff line number Diff line change
@@ -1,9 +1 @@
let _result = -1;
for (let _key = array.length - 1, _value; _key >= 0; --_key) {
_value = array[_key];
if (fn(_value, _key, array)) {
_result = _key;
break;
}
}
const firstEven = _result;
const firstEven = findIndexRight(array, fn);
14 changes: 8 additions & 6 deletions __tests__/__fixtures__/cached/findKey/output.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
let _result;
let _value;
for (let _key in object) {
let _match = -1,
_value,
_result;
for (const _key in object) {
_value = object[_key];
if (fn(_value, _key, object)) {
_result = _key;
_result = fn(_value, _key, object);
if (_result) {
_match = _key;
break;
}
}
const firstEven = _result;
const firstEven = _match;
12 changes: 6 additions & 6 deletions __tests__/__fixtures__/cached/findObject/output.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
let _result;
let _value;
for (let _key in object) {
let _match, _value, _result;
for (const _key in object) {
_value = object[_key];
if (fn(_value, _key, object)) {
_result = _value;
_result = fn(_value, _key, object);
if (_result) {
_match = _value;
break;
}
}
const firstEven = _result;
const firstEven = _match;
10 changes: 1 addition & 9 deletions __tests__/__fixtures__/cached/findRight/output.js
Original file line number Diff line number Diff line change
@@ -1,9 +1 @@
let _result;
for (let _key = array.length - 1, _value; _key >= 0; --_key) {
_value = array[_key];
if (fn(_value, _key, array)) {
_result = _value;
break;
}
}
const lastEven = _result;
const lastEven = findRight(array, fn);
13 changes: 9 additions & 4 deletions __tests__/__fixtures__/cached/flatMap/output.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
let _result = [];
for (let _key = 0, _length = array.length, _value; _key < _length; ++_key) {
let _results = [];
for (
let _key = 0, _length = array.length, _value, _result;
_key < _length;
++_key
) {
_value = array[_key];
_result.push.apply(_result, fn(_value, _key, array));
_result = fn(_value, _key, array);
_results = _results.concat(_result);
}
const flattened = _result;
const flattened = _results;
9 changes: 5 additions & 4 deletions __tests__/__fixtures__/cached/flatMapRight/output.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
let _result = [];
for (let _key = array.length - 1, _value; _key >= 0; --_key) {
let _results = [];
for (let _key = array.length, _value, _result; --_key >= 0; ) {
_value = array[_key];
_result.push.apply(_result, fn(_value, _key, array));
_result = fn(_value, _key, array);
_results = _results.concat(_result);
}
const flattened = _result;
const flattened = _results;
2 changes: 1 addition & 1 deletion __tests__/__fixtures__/cached/forEachObject/output.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
let _value;
for (let _key in object) {
for (const _key in object) {
_value = object[_key];
fn(_value, _key, object);
}
2 changes: 1 addition & 1 deletion __tests__/__fixtures__/cached/forEachRight/output.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
for (let _key = array.length - 1, _value; _key >= 0; --_key) {
for (let _key = array.length, _value; --_key >= 0; ) {
_value = array[_key];
fn(_value, _key, array);
}
9 changes: 5 additions & 4 deletions __tests__/__fixtures__/cached/map/output.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
let _result = [];
for (let _key = 0, _length = array.length, _value; _key < _length; ++_key) {
const _length = array.length;
const _results = Array(_length);
for (let _key = 0, _value; _key < _length; ++_key) {
_value = array[_key];
_result[_key] = fn(_value, _key, array);
_results[_key] = fn(_value, _key, array);
}
const doubledValues = _result;
const doubledValues = _results;
10 changes: 5 additions & 5 deletions __tests__/__fixtures__/cached/mapObject/output.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
let _result = {};
let _value;
for (let _key in object) {
const _results = {};
let _value, _result;
for (const _key in object) {
_value = object[_key];
_result[_key] = fn(_value, _key, object);
_results[_key] = fn(_value, _key, object);
}
const doubledValues = _result;
const doubledValues = _results;
10 changes: 6 additions & 4 deletions __tests__/__fixtures__/cached/mapRight/output.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
let _result = [];
for (let _key = array.length - 1, _value; _key >= 0; --_key) {
const _length = array.length;
let _key = _length;
const _results = Array(_length);
for (let _value; --_key >= 0; ) {
_value = array[_key];
_result[_result.length] = fn(_value, _key, array);
_results[_length - _key - 1] = fn(_value, _key, array);
}
const doubledValues = _result;
const doubledValues = _results;
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
let _result = array[0];
let _accumulated = array[0];
for (let _key = 1, _length = array.length, _value; _key < _length; ++_key) {
_value = array[_key];
_result = fn(_result, _value, _key, array);
_accumulated = fn(_accumulated, _value, _key, array);
}
const doubledValues = _result;
const doubledValues = _accumulated;
6 changes: 3 additions & 3 deletions __tests__/__fixtures__/cached/reduce/output.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
let _result = {};
let _accumulated = {};
for (let _key = 0, _length = array.length, _value; _key < _length; ++_key) {
_value = array[_key];
_result = fn(_result, _value, _key, array);
_accumulated = fn(_accumulated, _value, _key, array);
}
const doubledValues = _result;
const doubledValues = _accumulated;
Loading

0 comments on commit f847f0c

Please sign in to comment.