Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[hack pipes] Inline topic token when possible (#14278)
* Optimize away `|> #` pipes * Inline topic token when it's used once and there are no side effects * Fix deferred topic evaluation * Update standalone tests
- Loading branch information
1 parent
1937284
commit a35af3e
Showing
158 changed files
with
459 additions
and
386 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
4 changes: 1 addition & 3 deletions
4
...ges/babel-plugin-proposal-pipeline-operator/test/fixtures/hack-caret/hash-tuple/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,4 +1,2 @@ | ||
var _ref; | ||
|
||
Tuple(0); | ||
_ref = 1, Tuple(0, _ref); | ||
Tuple(0, 1); |
4 changes: 1 addition & 3 deletions
4
...l-plugin-proposal-pipeline-operator/test/fixtures/hack-caret/pipe-body-identity/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,4 +1,2 @@ | ||
var _ref; | ||
|
||
const result = (_ref = 5, _ref); | ||
const result = 5; | ||
expect(result).toBe(5); |
2 changes: 1 addition & 1 deletion
2
...ugin-proposal-pipeline-operator/test/fixtures/hack-caret/pipe-body-with-addition/input.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,3 +1,3 @@ | ||
const result = 5 |> ^ + 1 |> ^ + ^; | ||
const result = 5 |> ^ + 1 |> 2 + ^ |> ^ + ^; | ||
|
||
expect(result).toBe(12); |
4 changes: 2 additions & 2 deletions
4
...gin-proposal-pipeline-operator/test/fixtures/hack-caret/pipe-body-with-addition/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,4 +1,4 @@ | ||
var _ref, _ref2; | ||
var _ref; | ||
|
||
const result = (_ref2 = 5, (_ref = _ref2 + 1, _ref + _ref)); | ||
const result = (_ref = 2 + (5 + 1), _ref + _ref); | ||
expect(result).toBe(12); |
10 changes: 5 additions & 5 deletions
10
...operator/test/fixtures/hack-caret/pipe-body-with-arrow-function-and-nested-pipe/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,8 +1,8 @@ | ||
var _ref4, _ref5, _ref6; | ||
var _ref2; | ||
|
||
const result = (_ref6 = 5, (_ref5 = Math.pow(_ref6, 2), (_ref4 = [1, 2, 3].map(n => { | ||
var _ref, _ref2, _ref3; | ||
const result = (_ref2 = Math.pow(5, 2), [1, 2, 3].map(n => { | ||
var _ref; | ||
|
||
return _ref3 = n + _ref5, (_ref2 = _ref3 * 2, (_ref = `${_ref2} apples`, _ref.toUpperCase())); | ||
}), _ref4.join()))); | ||
return _ref = (n + _ref2) * 2, `${_ref} apples`.toUpperCase(); | ||
}).join()); | ||
expect(result).toEqual('52 APPLES,54 APPLES,56 APPLES'); |
10 changes: 5 additions & 5 deletions
10
...oposal-pipeline-operator/test/fixtures/hack-caret/pipe-body-with-arrow-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 |
---|---|---|
@@ -1,8 +1,8 @@ | ||
var _ref, _ref2, _ref3; | ||
var _ref; | ||
|
||
const result = (_ref3 = -2.2 // -2.2 | ||
, (_ref2 = Math.floor(_ref3) // -3 | ||
, (_ref = () => Math.pow(_ref2, 5) // () => -243 | ||
, _ref()))); // -243 | ||
const result = (_ref = Math.floor(-2.2 // -2.2 | ||
) // -3 | ||
, (() => Math.pow(_ref, 5) // () => -243 | ||
)()); // -243 | ||
|
||
expect(result).toBe(-243); |
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
4 changes: 1 addition & 3 deletions
4
...-plugin-proposal-pipeline-operator/test/fixtures/hack-caret/pipe-body-with-eval/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,5 +1,3 @@ | ||
var _ref; | ||
|
||
const program = '(function() { return this; })()'; | ||
const result = (_ref = program, eval(_ref)); | ||
const result = eval(program); | ||
expect(result).not.toBeUndefined(); |
4 changes: 2 additions & 2 deletions
4
...-proposal-pipeline-operator/test/fixtures/hack-caret/pipe-body-with-nested-pipe/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,4 +1,4 @@ | ||
var _ref, _ref2, _ref3, _ref4; | ||
var _ref; | ||
|
||
const result = (_ref4 = 5, (_ref3 = Math.pow(_ref4, 2), (_ref2 = _ref3 + 1, (_ref = `${_ref2} apples`, _ref.toUpperCase())))); | ||
const result = (_ref = Math.pow(5, 2) + 1, `${_ref} apples`.toUpperCase()); | ||
expect(result).toEqual('26 APPLES'); |
10 changes: 5 additions & 5 deletions
10
...oposal-pipeline-operator/test/fixtures/hack-caret/pipe-body-with-object-literal/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,11 @@ | ||
var _ref, _ref2, _ref3; | ||
var _ref; | ||
|
||
function area(rect) { | ||
return rect.width * rect.height; | ||
} | ||
|
||
const result = (_ref3 = -5, (_ref2 = Math.abs(_ref3), (_ref = { | ||
width: _ref2, | ||
height: _ref2 + 3 | ||
}, area(_ref)))); | ||
const result = (_ref = Math.abs(-5), area({ | ||
width: _ref, | ||
height: _ref + 3 | ||
})); | ||
expect(result).toBe(40); |
4 changes: 1 addition & 3 deletions
4
...sal-pipeline-operator/test/fixtures/hack-caret/pipe-body-with-topic-method-call/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,4 +1,2 @@ | ||
var _ref; | ||
|
||
const result = (_ref = 'Hello', _ref.toUpperCase()); | ||
const result = 'Hello'.toUpperCase(); | ||
expect(result).toBe('HELLO'); |
4 changes: 2 additions & 2 deletions
4
...plugin-proposal-pipeline-operator/test/fixtures/hack-caret/pipe-body-with-yield/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
4 changes: 1 addition & 3 deletions
4
...-proposal-pipeline-operator/test/fixtures/hack-caret/pipe-head-with-nested-pipe/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,4 +1,2 @@ | ||
var _ref, _ref2; | ||
|
||
const result = (_ref2 = (_ref = 5, Math.pow(_ref, 2)), _ref2 + 1); | ||
const result = Math.pow(5, 2) + 1; | ||
expect(result).toEqual(26); |
10 changes: 5 additions & 5 deletions
10
...ugin-proposal-pipeline-operator/test/fixtures/hack-caret/pipe-in-arrow-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
9 changes: 9 additions & 0 deletions
9
...lugin-proposal-pipeline-operator/test/fixtures/hack-caret/topic-token-in-function/exec.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,9 @@ | ||
let x = 0; | ||
|
||
let fnA = x++ |> (() => ^); | ||
let fnB = x++ |> (0, () => ^); | ||
|
||
expect(x).toBe(2); | ||
expect(fnA()).toBe(0); | ||
expect(fnB()).toBe(1); | ||
expect(x).toBe(2); |
9 changes: 9 additions & 0 deletions
9
...ugin-proposal-pipeline-operator/test/fixtures/hack-caret/topic-token-in-function/input.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,9 @@ | ||
let x = 0; | ||
|
||
let fnA = x++ |> (() => ^); | ||
let fnB = x++ |> (0, () => ^); | ||
|
||
expect(x).toBe(2); | ||
expect(fnA()).toBe(0); | ||
expect(fnB()).toBe(1); | ||
expect(x).toBe(2); |
9 changes: 9 additions & 0 deletions
9
...gin-proposal-pipeline-operator/test/fixtures/hack-caret/topic-token-in-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,9 @@ | ||
var _ref, _ref2; | ||
|
||
let x = 0; | ||
let fnA = (_ref = x++, () => _ref); | ||
let fnB = (_ref2 = x++, (0, () => _ref2)); | ||
expect(x).toBe(2); | ||
expect(fnA()).toBe(0); | ||
expect(fnB()).toBe(1); | ||
expect(x).toBe(2); |
4 changes: 1 addition & 3 deletions
4
...n-proposal-pipeline-operator/test/fixtures/hack-caret/transform-arrow-functions/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,8 +1,6 @@ | ||
var _ref, _ref2; | ||
|
||
const triple = function (x) { | ||
return x * 3; | ||
}; | ||
|
||
const result = (_ref2 = -7, (_ref = Math.abs(_ref2), triple(_ref))); | ||
const result = triple(Math.abs(-7)); | ||
return expect(result).toBe(21); |
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
2 changes: 1 addition & 1 deletion
2
...pipeline-operator/test/fixtures/hack-caret/while-statement-with-pipe-in-condition/exec.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,7 +1,7 @@ | ||
let i = 0; | ||
let sum = 0; | ||
|
||
while (i |> (i = ^ + 1) |> ^ <= 10) | ||
while (i |> (i = 2 * ^ - ^ + 1) |> ^ <= 10) | ||
sum += i; | ||
|
||
expect(sum).toBe(10 + 9 + 8 + 7 + 6 + 5 + 4 + 3 + 2 + 1); |
2 changes: 1 addition & 1 deletion
2
...ipeline-operator/test/fixtures/hack-caret/while-statement-with-pipe-in-condition/input.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,7 +1,7 @@ | ||
let i = 0; | ||
let sum = 0; | ||
|
||
while (i |> (i = ^ + 1) |> ^ <= 10) | ||
while (i |> (i = 2 * ^ - ^ + 1) |> ^ <= 10) | ||
sum += i; | ||
|
||
expect(sum).toBe(10 + 9 + 8 + 7 + 6 + 5 + 4 + 3 + 2 + 1); |
4 changes: 2 additions & 2 deletions
4
...peline-operator/test/fixtures/hack-caret/while-statement-with-pipe-in-condition/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
4 changes: 1 addition & 3 deletions
4
...el-plugin-proposal-pipeline-operator/test/fixtures/hack-caret/within-assignment/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,4 +1,2 @@ | ||
var _ref; | ||
|
||
const x = (_ref = 0, _ref + 1); | ||
const x = 0 + 1; | ||
expect(x).toBe(1); |
2 changes: 1 addition & 1 deletion
2
...sal-pipeline-operator/test/fixtures/hack-caret/within-for-classic-statement-init/input.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 @@ | ||
let sum = 0; | ||
for (var i = 0 |> ^; i <= 10; i++) | ||
for (var i = 0 |> ^*^; i <= 10; i++) | ||
sum += i; | ||
|
||
expect(sum).toBe(10 + 9 + 8 + 7 + 6 + 5 + 4 + 3 + 2 + 1); |
2 changes: 1 addition & 1 deletion
2
...al-pipeline-operator/test/fixtures/hack-caret/within-for-classic-statement-init/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
2 changes: 1 addition & 1 deletion
2
...osal-pipeline-operator/test/fixtures/hack-caret/within-for-classic-statement-test/exec.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 @@ | ||
let sum = 0; | ||
for (var i = 0; i |> ^ <= 10; i++) | ||
for (var i = 0; i |> ^ + ^ <= 20; i++) | ||
sum = sum + i; | ||
|
||
expect(sum).toBe(10 + 9 + 8 + 7 + 6 + 5 + 4 + 3 + 2 + 1) |
2 changes: 1 addition & 1 deletion
2
...sal-pipeline-operator/test/fixtures/hack-caret/within-for-classic-statement-test/input.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 @@ | ||
let sum = 0; | ||
for (var i = 0; i |> ^ <= 10; i++) | ||
for (var i = 0; i |> ^ + ^ <= 20; i++) | ||
sum = sum + i; | ||
|
||
expect(sum).toBe(10 + 9 + 8 + 7 + 6 + 5 + 4 + 3 + 2 + 1) |
2 changes: 1 addition & 1 deletion
2
...al-pipeline-operator/test/fixtures/hack-caret/within-for-classic-statement-test/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
4 changes: 1 addition & 3 deletions
4
...-pipeline-operator/test/fixtures/hack-caret/within-for-classic-statement-update/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
4 changes: 2 additions & 2 deletions
4
...proposal-pipeline-operator/test/fixtures/hack-caret/within-generator-with-yield/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,5 +1,5 @@ | ||
function* myGenerator(n) { | ||
var _ref, _ref2; | ||
var _ref; | ||
|
||
return _ref2 = n, (_ref = yield _ref2, Math.abs(_ref)); | ||
return _ref = yield n, Math.abs(_ref); | ||
} |
Oops, something went wrong.