@@ -774,13 +774,13 @@ public Finally(SourceLocation loc, BlockStatement body) {
774774 }
775775
776776 // associate statements with their (direct or indirect) labels
777- private final Map <Statement , Set <String >> loopLabels = new LinkedHashMap <Statement , Set <String >>();
777+ private Map <Statement , Set <String >> loopLabels = new LinkedHashMap <Statement , Set <String >>();
778778
779779 // cache the set of normal control flow successors
780- private final Map <Node , Object > followingCache = new LinkedHashMap <Node , Object >();
780+ private Map <Node , Object > followingCache = new LinkedHashMap <Node , Object >();
781781
782782 // map from a node in a chain of property accesses or calls to the successor info for the first node in the chain
783- private final Map <Chainable , SuccessorInfo > chainRootSuccessors = new LinkedHashMap <Chainable , SuccessorInfo >();
783+ private Map <Chainable , SuccessorInfo > chainRootSuccessors = new LinkedHashMap <Chainable , SuccessorInfo >();
784784
785785 /**
786786 * Generate entry node.
@@ -1031,6 +1031,16 @@ private void buildFunctionBody(IFunction nd) {
10311031
10321032 @ Override
10331033 public Void visit (IFunction nd , SuccessorInfo i ) {
1034+ // save per-function caches
1035+ Map <Statement , Set <String >> oldLoopLabels = loopLabels ;
1036+ Map <Node , Object > oldFollowingCache = followingCache ;
1037+ Map <Chainable , SuccessorInfo > oldChainRootSuccessors = chainRootSuccessors ;
1038+
1039+ // clear caches
1040+ loopLabels = new LinkedHashMap <>();
1041+ followingCache = new LinkedHashMap <>();
1042+ chainRootSuccessors = new LinkedHashMap <>();
1043+
10341044 if (nd instanceof FunctionDeclaration && nd .hasDeclareKeyword ()) {
10351045 // All 'declared' statements have a no-op CFG node, but their children should
10361046 // not be processed.
@@ -1039,6 +1049,12 @@ public Void visit(IFunction nd, SuccessorInfo i) {
10391049 }
10401050 buildFunctionCreation (nd , i );
10411051 buildFunctionBody (nd );
1052+
1053+ // restore caches
1054+ loopLabels = oldLoopLabels ;
1055+ followingCache = oldFollowingCache ;
1056+ chainRootSuccessors = oldChainRootSuccessors ;
1057+
10421058 return null ;
10431059 }
10441060
0 commit comments