@@ -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 ();
@@ -1255,9 +1245,12 @@ public Void visit(Literal nd, SuccessorInfo i) {
12551245
12561246 @ Override
12571247 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 ()));
12611254 return null ;
12621255 }
12631256
0 commit comments