-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Upgrade operation inliner to support larger function bodies - Only bailout scenarios involve conditional or multiple `return` statements - Support destructuring parameters - Improve documentation to show code style to avoid bailouts - Add tests for more use cases
- Loading branch information
1 parent
4e63cf3
commit 8502c19
Showing
54 changed files
with
1,130 additions
and
556 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { filter } from '../../../../src/inline-loops.macro'; | ||
|
||
const result = filter([1, 2, 3], (value) => { | ||
if (value === 2) { | ||
return true; | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
const _iterable = [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 result = _result; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { map } from '../../../../src/inline-loops.macro'; | ||
|
||
const result = map([1, 2, 3], (value) => { | ||
if (value === 2) { | ||
return 82; | ||
} | ||
|
||
return value; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
const _iterable = [1, 2, 3]; | ||
|
||
const _fn = value => { | ||
if (value === 2) { | ||
return 82; | ||
} | ||
|
||
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 result = _result; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { map } from '../../../../src/inline-loops.macro'; | ||
|
||
function getStuff() { | ||
if (foo === 'bar') { | ||
return map(array, v => v * 2); | ||
} | ||
|
||
return array; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
function getStuff() { | ||
if (foo === 'bar') { | ||
let _result = []; | ||
|
||
for (let _key = 0, _length = array.length, _value; _key < _length; ++_key) { | ||
_value = array[_key]; | ||
_result[_key] = _value * 2; | ||
} | ||
|
||
return _result; | ||
} | ||
|
||
return array; | ||
} |
2 changes: 1 addition & 1 deletion
2
...res__/complex/destructured-params/code.js → ...complex/destructured-params-array/code.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
import { forEach } from '../../../../src/inline-loops.macro'; | ||
|
||
forEach([], ([a, b]) => { | ||
forEach([], ([a, [b]]) => { | ||
console.log(a, b); | ||
}); |
8 changes: 2 additions & 6 deletions
8
...s__/complex/destructured-params/output.js → ...mplex/destructured-params-array/output.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,7 @@ | ||
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); | ||
const [_a, [_b]] = _value; | ||
console.log(_a, _b); | ||
} |
5 changes: 5 additions & 0 deletions
5
__tests__/__fixtures__/complex/destructured-params-object/code.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { forEach } from '../../../../src/inline-loops.macro'; | ||
|
||
forEach([], ({ a, b: { c } }) => { | ||
console.log(a, c); | ||
}); |
12 changes: 12 additions & 0 deletions
12
__tests__/__fixtures__/complex/destructured-params-object/output.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
const _iterable = []; | ||
|
||
for (let _key = 0, _length = _iterable.length, _value; _key < _length; ++_key) { | ||
_value = _iterable[_key]; | ||
const { | ||
a: _a, | ||
b: { | ||
c: _c | ||
} | ||
} = _value; | ||
console.log(_a, _c); | ||
} |
30 changes: 30 additions & 0 deletions
30
__tests__/__fixtures__/complex/inlined-large-function/code.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { filter, map, reduceObject } from '../../../../src/inline-loops.macro'; | ||
|
||
const result = filter(array, (value, index) => { | ||
// usage inside | ||
const mapped = map(array, value => value * 2); | ||
|
||
// custom for loop with let | ||
for (let i = 0; i < mapped.length; i++) { | ||
mapped[i] = mapped[i] ** 2; | ||
} | ||
|
||
// custom for loop with var | ||
for (var i = 0; i < mapped.length; i++) { | ||
mapped[i] = mapped[i] ** 2; | ||
} | ||
|
||
// another iteration, using the mapped values | ||
const reduced = reduceObject(object, value => ({ | ||
[value]: mapped, | ||
})); | ||
|
||
// custom for-in | ||
for (var key in reduced) { | ||
if (reduced[key] < 0) { | ||
delete reduced[key]; | ||
} | ||
} | ||
|
||
return reduced[100]; | ||
}); |
54 changes: 54 additions & 0 deletions
54
__tests__/__fixtures__/complex/inlined-large-function/output.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
let _result = []; | ||
|
||
for (let _key = 0, _length = array.length, _value; _key < _length; ++_key) { | ||
_value = array[_key]; | ||
let _result2 = []; | ||
|
||
for (let _key3 = 0, _length2 = array.length, _value2; _key3 < _length2; ++_key3) { | ||
_value2 = array[_key3]; | ||
_result2[_key3] = _value2 * 2; | ||
} | ||
|
||
// usage inside | ||
const _mapped = _result2; // custom for loop with let | ||
|
||
for (let i = 0; i < _mapped.length; i++) { | ||
_mapped[i] = _mapped[i] ** 2; | ||
} // custom for loop with var | ||
|
||
|
||
for (var _i2 = 0; _i2 < _mapped.length; _i2++) { | ||
_mapped[_i2] = _mapped[_i2] ** 2; | ||
} // another iteration, using the mapped values | ||
|
||
|
||
let _hasInitialValue = false; | ||
|
||
let _value3; | ||
|
||
let _result3; | ||
|
||
for (let _key4 in object) { | ||
if (_hasInitialValue) { | ||
_value3 = object[_key4]; | ||
_result3 = { | ||
[_result3]: _mapped | ||
}; | ||
} else { | ||
_hasInitialValue = true; | ||
_result3 = object[_key4]; | ||
} | ||
} | ||
|
||
const _reduced = _result3; // custom for-in | ||
|
||
for (var _key2 in _reduced) { | ||
if (_reduced[_key2] < 0) { | ||
delete _reduced[_key2]; | ||
} | ||
} | ||
|
||
if (_reduced[100]) _result.push(_value); | ||
} | ||
|
||
const result = _result; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { map } from '../../../../src/inline-loops.macro'; | ||
|
||
function foo(array) { | ||
return map(array, function (value) { | ||
return this && this.foo ? value : null; | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
function foo(array) { | ||
let _result = []; | ||
|
||
for (let _key = 0, _length = array.length, _value; _key < _length; ++_key) { | ||
_value = array[_key]; | ||
_result[_key] = this && this.foo ? _value : null; | ||
} | ||
|
||
return _result; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
import { everyRight } from "../../../../src/inline-loops.macro"; | ||
import { everyRight } from '../../../../src/inline-loops.macro'; | ||
|
||
const areAllEven = everyRight(array, value => value % 2 === 0); | ||
const areAllEven = everyRight([1, 2, 3, 4], (value) => { | ||
const isValueEven = value % 2 === 0; | ||
|
||
return isValueEven; | ||
}); |
Oops, something went wrong.