@@ -586,14 +586,6 @@ private static List<Identifier> of(List<Statement> body) {
586
586
public static List <Identifier > of (Program p ) {
587
587
return of (p .getBody ());
588
588
}
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
- }
597
589
}
598
590
599
591
/**
@@ -1096,8 +1088,6 @@ private void buildFunctionBody(IFunction nd) {
1096
1088
if (nd .hasRest ()) paramsAndDefaults .add ((Expression ) nd .getRest ());
1097
1089
1098
1090
Node entry = getEntryNode (nd );
1099
- List <Identifier > fns = HoistedFunDecls .of (nd );
1100
- hoistedFns .addAll (fns );
1101
1091
1102
1092
// if this is the constructor of a class without a superclass, we need to
1103
1093
// initialise all fields before running the body of the constructor
@@ -1117,7 +1107,7 @@ private void buildFunctionBody(IFunction nd) {
1117
1107
if (firstField != null ) fst = Collections .singleton (First .of (firstField ));
1118
1108
fst =
1119
1109
visitSequence (
1120
- nd instanceof FunctionDeclaration ? null : nd .getId (), paramsAndDefaults , fns , fst );
1110
+ nd instanceof FunctionDeclaration ? null : nd .getId (), paramsAndDefaults , fst );
1121
1111
writeSuccessors (entry , fst );
1122
1112
1123
1113
this .ctxt .pop ();
@@ -1255,9 +1245,12 @@ public Void visit(Literal nd, SuccessorInfo i) {
1255
1245
1256
1246
@ Override
1257
1247
public Void visit (BlockStatement nd , SuccessorInfo i ) {
1258
- if (nd .getBody ().isEmpty ()) writeSuccessors (nd , i .getAllSuccessors ());
1259
- else writeSuccessor (nd , First .of (nd .getBody ().get (0 )));
1260
- visitSequence (nd .getBody (), i .getAllSuccessors ());
1248
+ // Hoist function declarations in a block statement to the top of the block.
1249
+ // This reflects non-standard behaviour implemented by most engines.
1250
+ // See also: ECMAScript "B.3.2 Block-Level Function Declarations Web Legacy Compatibility Semantics".
1251
+ List <Identifier > hoisted = HoistedFunDecls .of (nd .getBody ());
1252
+ hoistedFns .addAll (hoisted );
1253
+ writeSuccessors (nd , visitSequence (hoisted , nd .getBody (), i .getAllSuccessors ()));
1261
1254
return null ;
1262
1255
}
1263
1256
0 commit comments