Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extract hoisted variables from dead branches (#3752)
* Extract hoisted variables from dead branches * Improve coverage
- Loading branch information
1 parent
7bc7c90
commit c6c939f
Showing
34 changed files
with
152 additions
and
847 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
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 |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { AstContext } from '../../Module'; | ||
import Identifier from '../nodes/Identifier'; | ||
import { ExpressionEntity } from '../nodes/shared/Expression'; | ||
import LocalVariable from '../variables/LocalVariable'; | ||
import BlockScope from './BlockScope'; | ||
|
||
export default class TrackingScope extends BlockScope { | ||
public hoistedDeclarations: Identifier[] = []; | ||
|
||
addDeclaration( | ||
identifier: Identifier, | ||
context: AstContext, | ||
init: ExpressionEntity | null, | ||
isHoisted: boolean | ||
): LocalVariable { | ||
this.hoistedDeclarations.push(identifier); | ||
return this.parent.addDeclaration(identifier, context, init, isHoisted); | ||
} | ||
} |
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 @@ | ||
if (false) { | ||
var deadVariable, otherDeadVariable; | ||
} | ||
var deadVariable, otherDeadVariable; | ||
|
||
console.log(deadVariable, otherDeadVariable); |
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,6 +1,4 @@ | ||
if (false) { | ||
var foo; | ||
} | ||
var foo; | ||
|
||
if (foo) { | ||
console.log("nope"); | ||
|
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: 'renders hoisted variables in dead branches' | ||
}; |
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,6 @@ | ||
var a, b; { | ||
console.log(a, b); | ||
} | ||
|
||
var c, d; if (((() => console.log('effect'))(), true)) ; | ||
console.log(c, d); |
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 @@ | ||
if (false) { | ||
for (var a; unknownGlobal && true; unknownGlobal && true) var b; | ||
} else { | ||
console.log(a, b); | ||
} | ||
|
||
if (((() => console.log('effect'))(), true)) { | ||
} else { | ||
var c = 1; | ||
for (var c; unknownGlobal && true; unknownGlobal && true) var d; | ||
} | ||
console.log(c, d); |
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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.