@@ -23,7 +23,10 @@ import {
2323} from '../HIR/HIR' ;
2424import { ReactiveFunctionVisitor , visitReactiveFunction } from './visitors' ;
2525
26- class Visitor extends ReactiveFunctionVisitor < State > {
26+ /**
27+ * Phase 2: Promote identifiers which are used in a place that requires a named variable.
28+ */
29+ class PromoteTemporaries extends ReactiveFunctionVisitor < State > {
2730 override visitScope ( scopeBlock : ReactiveScopeBlock , state : State ) : void {
2831 for ( const dep of scopeBlock . scope . dependencies ) {
2932 const { identifier} = dep ;
@@ -95,7 +98,11 @@ class Visitor extends ReactiveFunctionVisitor<State> {
9598 }
9699}
97100
98- class Visitor2 extends ReactiveFunctionVisitor < State > {
101+ /**
102+ * Phase 3: Now that identifiers which need promotion are promoted, find and promote
103+ * all other Identifier instances of each promoted DeclarationId.
104+ */
105+ class PromoteAllInstancedOfPromotedTemporaries extends ReactiveFunctionVisitor < State > {
99106 override visitPlace ( _id : InstructionId , place : Place , state : State ) : void {
100107 if (
101108 place . identifier . name === null &&
@@ -168,6 +175,10 @@ type State = {
168175 > ; // true if referenced within another scope, false if only accessed outside of scopes
169176} ;
170177
178+ /**
179+ * Phase 1: checks for pruned variables which need to be promoted, as well as
180+ * usage of identifiers as jsx tags, which need to be promoted differently
181+ */
171182class CollectPromotableTemporaries extends ReactiveFunctionVisitor < State > {
172183 activeScopes : Array < ScopeId > = [ ] ;
173184
@@ -227,8 +238,12 @@ export function promoteUsedTemporaries(fn: ReactiveFunction): void {
227238 promoteIdentifier ( place . identifier , state ) ;
228239 }
229240 }
230- visitReactiveFunction ( fn , new Visitor ( ) , state ) ;
231- visitReactiveFunction ( fn , new Visitor2 ( ) , state ) ;
241+ visitReactiveFunction ( fn , new PromoteTemporaries ( ) , state ) ;
242+ visitReactiveFunction (
243+ fn ,
244+ new PromoteAllInstancedOfPromotedTemporaries ( ) ,
245+ state ,
246+ ) ;
232247}
233248
234249function promoteIdentifier ( identifier : Identifier , state : State ) : void {
0 commit comments