Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Do not include unused return expressions (#4573)
* Add test * Do not include unused return expressions * Improve coverage
- Loading branch information
1 parent
f019fae
commit 01e2461
Showing
15 changed files
with
233 additions
and
95 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
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
5 changes: 5 additions & 0 deletions
5
test/form/samples/builtin-prototypes/template-literal/_expected.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
6 changes: 6 additions & 0 deletions
6
test/form/samples/builtin-prototypes/template-literal/main.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
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 @@ | ||
const path = require('path'); | ||
|
||
module.exports = { | ||
description: 'tree-shakes entities referenced in a return statement after an error' | ||
}; |
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 @@ | ||
function getInstance() { | ||
throw new Error('error'); | ||
} | ||
|
||
console.log(getInstance()); | ||
|
||
export { getInstance }; |
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,8 @@ | ||
class Removed {} | ||
|
||
export function getInstance() { | ||
throw new Error('error'); | ||
return new Removed(); | ||
} | ||
|
||
console.log(getInstance()); |
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,22 @@ | ||
const assert = require('assert'); | ||
|
||
module.exports = { | ||
description: 'does not remove calls to props without value', | ||
minNodeVersion: 12, | ||
exports({ callProp, callStaticProp }) { | ||
let hasError = false; | ||
try { | ||
callStaticProp(); | ||
} catch { | ||
hasError = true; | ||
} | ||
assert.ok(hasError); | ||
hasError = false; | ||
try { | ||
callProp(); | ||
} catch { | ||
hasError = true; | ||
} | ||
assert.ok(hasError); | ||
} | ||
}; |
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,11 @@ | ||
class Foo { | ||
static staticProp; | ||
prop; | ||
} | ||
|
||
export const callStaticProp = () => Foo.staticProp() || false; | ||
|
||
export const callProp = () => { | ||
const foo = new Foo(); | ||
return foo.prop() || false; | ||
}; |
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
46 changes: 32 additions & 14 deletions
46
test/function/samples/conditionals-deoptimization/main.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,21 +1,39 @@ | ||
export let first = false; | ||
export let second = false; | ||
export let third = false; | ||
export let fourth = false; | ||
export let cond1a = false; | ||
export let cond1b = false; | ||
export let cond2a = false; | ||
export let cond2b = false; | ||
export let log1a = false; | ||
export let log1b = false; | ||
export let log2a = false; | ||
export let log2b = false; | ||
|
||
let flag = false; | ||
checkConditional(); | ||
checkLogical(); | ||
checkConditional1(); | ||
checkConditional2(); | ||
checkLogical1(); | ||
checkLogical2(); | ||
flag = true; | ||
checkConditional(); | ||
checkLogical(); | ||
checkConditional1(); | ||
checkConditional2(); | ||
checkLogical1(); | ||
checkLogical2(); | ||
|
||
function checkConditional() { | ||
if (flag ? true : false) first = true; | ||
else second = true; | ||
function checkConditional1() { | ||
if (flag ? true : false) cond1a = true; | ||
else cond1b = true; | ||
} | ||
|
||
function checkLogical() { | ||
if (flag && true) third = true; | ||
else fourth = true; | ||
function checkConditional2() { | ||
if (!flag ? true : false) cond2a = true; | ||
else cond2b = true; | ||
} | ||
|
||
function checkLogical1() { | ||
if (flag && true) log1a = true; | ||
else log1b = true; | ||
} | ||
|
||
function checkLogical2() { | ||
if (!flag && true) log2a = true; | ||
else log2b = 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,3 @@ | ||
module.exports = { | ||
description: 'deoptimizes getting return expression for long property paths' | ||
}; |
Oops, something went wrong.