Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove conditional expressions if they have no effect.
- if the test evaluation produces an effect, keep the whole expression - if the test evaluation is unkown but has no effect, remove the expression unless any branch has an effect - if the test evaluation is known, replace the expression with the resulting branch (as before)
- Loading branch information
Cornelius Weig
committed
Sep 23, 2017
1 parent
b949eb0
commit ce0ceb8
Showing
8 changed files
with
121 additions
and
15 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,3 @@ | ||
module.exports = { | ||
description: 'only retain branches with side-effects' | ||
}; |
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 @@ | ||
define(function () { 'use strict'; | ||
|
||
// side-effect in condition | ||
var a = foo() ? 1 : 2; | ||
|
||
var unknownValue = bar(); | ||
|
||
// unknown branch with side-effect | ||
var c = unknownValue ? foo() : 2; | ||
var d = unknownValue ? 1 : foo(); | ||
|
||
// known side-effect | ||
var h = foo(); | ||
var i = foo(); | ||
|
||
}); |
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 @@ | ||
'use strict'; | ||
|
||
// side-effect in condition | ||
var a = foo() ? 1 : 2; | ||
|
||
var unknownValue = bar(); | ||
|
||
// unknown branch with side-effect | ||
var c = unknownValue ? foo() : 2; | ||
var d = unknownValue ? 1 : foo(); | ||
|
||
// known side-effect | ||
var h = foo(); | ||
var i = foo(); |
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 @@ | ||
// side-effect in condition | ||
var a = foo() ? 1 : 2; | ||
|
||
var unknownValue = bar(); | ||
|
||
// unknown branch with side-effect | ||
var c = unknownValue ? foo() : 2; | ||
var d = unknownValue ? 1 : foo(); | ||
|
||
// known side-effect | ||
var h = foo(); | ||
var i = foo(); |
17 changes: 17 additions & 0 deletions
17
test/form/samples/conditional-expression/_expected/iife.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,17 @@ | ||
(function () { | ||
'use strict'; | ||
|
||
// side-effect in condition | ||
var a = foo() ? 1 : 2; | ||
|
||
var unknownValue = bar(); | ||
|
||
// unknown branch with side-effect | ||
var c = unknownValue ? foo() : 2; | ||
var d = unknownValue ? 1 : foo(); | ||
|
||
// known side-effect | ||
var h = foo(); | ||
var i = foo(); | ||
|
||
}()); |
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,20 @@ | ||
(function (global, factory) { | ||
typeof exports === 'object' && typeof module !== 'undefined' ? factory() : | ||
typeof define === 'function' && define.amd ? define(factory) : | ||
(factory()); | ||
}(this, (function () { 'use strict'; | ||
|
||
// side-effect in condition | ||
var a = foo() ? 1 : 2; | ||
|
||
var unknownValue = bar(); | ||
|
||
// unknown branch with side-effect | ||
var c = unknownValue ? foo() : 2; | ||
var d = unknownValue ? 1 : foo(); | ||
|
||
// known side-effect | ||
var h = foo(); | ||
var i = foo(); | ||
|
||
}))); |
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,21 @@ | ||
// side-effect in condition | ||
var a = foo() ? 1 : 2; | ||
|
||
var unknownValue = bar(); | ||
|
||
// unknown branch without side-effects | ||
var b = unknownValue ? 1 : 2; | ||
|
||
// unknown branch with side-effect | ||
var c = unknownValue ? foo() : 2; | ||
var d = unknownValue ? 1 : foo(); | ||
|
||
// no side-effects | ||
var e = true ? 1 : foo(); | ||
var f = false ? foo() : 2; | ||
var g = true ? 1 : 2; | ||
|
||
// known side-effect | ||
var h = true ? foo() : 2; | ||
var i = false ? 1 : foo(); | ||
|