@@ -23,7 +23,10 @@ import {
23
23
} from '../HIR/HIR' ;
24
24
import { ReactiveFunctionVisitor , visitReactiveFunction } from './visitors' ;
25
25
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 > {
27
30
override visitScope ( scopeBlock : ReactiveScopeBlock , state : State ) : void {
28
31
for ( const dep of scopeBlock . scope . dependencies ) {
29
32
const { identifier} = dep ;
@@ -95,7 +98,11 @@ class Visitor extends ReactiveFunctionVisitor<State> {
95
98
}
96
99
}
97
100
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 > {
99
106
override visitPlace ( _id : InstructionId , place : Place , state : State ) : void {
100
107
if (
101
108
place . identifier . name === null &&
@@ -168,6 +175,10 @@ type State = {
168
175
> ; // true if referenced within another scope, false if only accessed outside of scopes
169
176
} ;
170
177
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
+ */
171
182
class CollectPromotableTemporaries extends ReactiveFunctionVisitor < State > {
172
183
activeScopes : Array < ScopeId > = [ ] ;
173
184
@@ -227,8 +238,12 @@ export function promoteUsedTemporaries(fn: ReactiveFunction): void {
227
238
promoteIdentifier ( place . identifier , state ) ;
228
239
}
229
240
}
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
+ ) ;
232
247
}
233
248
234
249
function promoteIdentifier ( identifier : Identifier , state : State ) : void {
0 commit comments