mirror of
https://github.com/github/codeql.git
synced 2026-04-30 03:05:15 +02:00
JS: Hoist function decls in a block to the top of the block
This commit is contained in:
@@ -1255,9 +1255,12 @@ public class CFGExtractor {
|
||||
|
||||
@Override
|
||||
public Void visit(BlockStatement nd, SuccessorInfo i) {
|
||||
if (nd.getBody().isEmpty()) writeSuccessors(nd, i.getAllSuccessors());
|
||||
else writeSuccessor(nd, First.of(nd.getBody().get(0)));
|
||||
visitSequence(nd.getBody(), i.getAllSuccessors());
|
||||
// Hoist function declarations in a block statement to the top of the block.
|
||||
// This reflects non-standard behaviour implemented by most engines.
|
||||
// See also: EcmaScript "B.3.2 Block-Level Function Declarations Web Legacy Compatibility Semantics".
|
||||
List<Identifier> hoisted = HoistedFunDecls.of(nd.getBody());
|
||||
hoistedFns.addAll(hoisted);
|
||||
writeSuccessors(nd, visitSequence(hoisted, nd.getBody(), i.getAllSuccessors()));
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user