Skip to content

Commit 1e5885e

Browse files
committed
JS: Remove hoisting code from functions
'buildFunctionBody' no longer needs to handle hoisting, because hoisting now happens when visiting the block statement that is the body of the function. Note that curly-brace functions contain a block statement as their body, not a list of statements.
1 parent 427e329 commit 1e5885e

File tree

1 file changed

+1
-11
lines changed

1 file changed

+1
-11
lines changed

javascript/extractor/src/com/semmle/js/extractor/CFGExtractor.java

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -586,14 +586,6 @@ private static List<Identifier> of(List<Statement> body) {
586586
public static List<Identifier> of(Program p) {
587587
return of(p.getBody());
588588
}
589-
590-
public static List<Identifier> of(IFunction fn) {
591-
Node body = fn.getBody();
592-
if (body instanceof BlockStatement) return of(((BlockStatement) body).getBody());
593-
// if the body of the function is missing or is an expression, then there are
594-
// no hoisted functions
595-
return Collections.emptyList();
596-
}
597589
}
598590

599591
/**
@@ -1096,8 +1088,6 @@ private void buildFunctionBody(IFunction nd) {
10961088
if (nd.hasRest()) paramsAndDefaults.add((Expression) nd.getRest());
10971089

10981090
Node entry = getEntryNode(nd);
1099-
List<Identifier> fns = HoistedFunDecls.of(nd);
1100-
hoistedFns.addAll(fns);
11011091

11021092
// if this is the constructor of a class without a superclass, we need to
11031093
// initialise all fields before running the body of the constructor
@@ -1117,7 +1107,7 @@ private void buildFunctionBody(IFunction nd) {
11171107
if (firstField != null) fst = Collections.singleton(First.of(firstField));
11181108
fst =
11191109
visitSequence(
1120-
nd instanceof FunctionDeclaration ? null : nd.getId(), paramsAndDefaults, fns, fst);
1110+
nd instanceof FunctionDeclaration ? null : nd.getId(), paramsAndDefaults, fst);
11211111
writeSuccessors(entry, fst);
11221112

11231113
this.ctxt.pop();

0 commit comments

Comments
 (0)