1
1
import type {
2
2
CapturedRenderNode ,
3
- CompileTimeCompilationContext ,
4
3
Cursor ,
5
4
Dict ,
6
5
DynamicScope ,
7
- ElementBuilder ,
8
6
ElementNamespace ,
9
7
Environment ,
8
+ EvaluationContext ,
10
9
HandleResult ,
11
10
Helper ,
12
11
Nullable ,
13
12
RenderResult ,
14
- RuntimeContext ,
15
13
SimpleDocument ,
16
14
SimpleDocumentFragment ,
17
15
SimpleElement ,
18
16
SimpleText ,
17
+ TreeBuilder ,
19
18
} from '@glimmer/interfaces' ;
20
19
import type { Reference } from '@glimmer/reference' ;
21
20
import type { CurriedValue , EnvironmentDelegate } from '@glimmer/runtime' ;
22
21
import type { ASTPluginBuilder , PrecompileOptions } from '@glimmer/syntax' ;
23
22
import { castToBrowser , castToSimple , expect , unwrapTemplate } from '@glimmer/debug-util' ;
24
- import { programCompilationContext } from '@glimmer/opcode-compiler' ;
23
+ import { EvaluationContextImpl } from '@glimmer/opcode-compiler' ;
25
24
import { artifacts , RuntimeOpImpl } from '@glimmer/program' ;
26
25
import { createConstRef } from '@glimmer/reference' ;
27
26
import {
@@ -58,24 +57,20 @@ import { TestJitRegistry } from './registry';
58
57
import { renderTemplate } from './render' ;
59
58
import { TestJitRuntimeResolver } from './resolver' ;
60
59
61
- export interface JitTestDelegateContext {
62
- runtime : RuntimeContext ;
63
- program : CompileTimeCompilationContext ;
64
- }
65
-
66
60
export function JitDelegateContext (
67
61
doc : SimpleDocument ,
68
62
resolver : TestJitRuntimeResolver ,
69
63
env : EnvironmentDelegate
70
- ) : JitTestDelegateContext {
64
+ ) : EvaluationContext {
71
65
let sharedArtifacts = artifacts ( ) ;
72
- let context = programCompilationContext (
66
+ let runtime = runtimeContext (
67
+ { document : doc } ,
68
+ env ,
73
69
sharedArtifacts ,
74
- new JitCompileTimeLookup ( resolver ) ,
75
- ( heap ) => new RuntimeOpImpl ( heap )
70
+ new JitCompileTimeLookup ( resolver )
76
71
) ;
77
- let runtime = runtimeContext ( { document : doc } , env , sharedArtifacts , resolver ) ;
78
- return { runtime , program : context } ;
72
+
73
+ return new EvaluationContextImpl ( sharedArtifacts , ( heap ) => new RuntimeOpImpl ( heap ) , runtime ) ;
79
74
}
80
75
81
76
export class JitRenderDelegate implements RenderDelegate {
@@ -86,7 +81,7 @@ export class JitRenderDelegate implements RenderDelegate {
86
81
protected resolver : TestJitRuntimeResolver ;
87
82
88
83
private plugins : ASTPluginBuilder [ ] = [ ] ;
89
- private _context : JitTestDelegateContext | null = null ;
84
+ private _context : Nullable < EvaluationContext > = null ;
90
85
private self : Nullable < Reference > = null ;
91
86
private doc : SimpleDocument ;
92
87
private env : EnvironmentDelegate ;
@@ -108,7 +103,7 @@ export class JitRenderDelegate implements RenderDelegate {
108
103
this . registry . register ( 'helper' , 'concat' , concat ) ;
109
104
}
110
105
111
- get context ( ) : JitTestDelegateContext {
106
+ get context ( ) : EvaluationContext {
112
107
if ( this . _context === null ) {
113
108
this . _context = JitDelegateContext ( this . doc , this . resolver , this . env ) ;
114
109
}
@@ -118,7 +113,7 @@ export class JitRenderDelegate implements RenderDelegate {
118
113
119
114
getCapturedRenderTree ( ) : CapturedRenderNode [ ] {
120
115
return expect (
121
- this . context . runtime . env . debugRenderTree ,
116
+ this . context . env . debugRenderTree ,
122
117
'Attempted to capture the DebugRenderTree during tests, but it was not created. Did you enable it in the environment?'
123
118
) . capture ( ) ;
124
119
}
@@ -191,7 +186,7 @@ export class JitRenderDelegate implements RenderDelegate {
191
186
registerInternalHelper ( this . registry , name , helper ) ;
192
187
}
193
188
194
- getElementBuilder ( env : Environment , cursor : Cursor ) : ElementBuilder {
189
+ getElementBuilder ( env : Environment , cursor : Cursor ) : TreeBuilder {
195
190
return clientBuilder ( env , cursor ) ;
196
191
}
197
192
@@ -206,13 +201,13 @@ export class JitRenderDelegate implements RenderDelegate {
206
201
compileTemplate ( template : string ) : HandleResult {
207
202
let compiled = preprocess ( template , this . precompileOptions ) ;
208
203
209
- return unwrapTemplate ( compiled ) . asLayout ( ) . compile ( this . context . program ) ;
204
+ return unwrapTemplate ( compiled ) . asLayout ( ) . compile ( this . context ) ;
210
205
}
211
206
212
207
renderTemplate ( template : string , context : Dict < unknown > , element : SimpleElement ) : RenderResult {
213
208
let cursor = { element, nextSibling : null } ;
214
209
215
- let { env } = this . context . runtime ;
210
+ let { env } = this . context ;
216
211
217
212
return renderTemplate (
218
213
template ,
@@ -230,11 +225,11 @@ export class JitRenderDelegate implements RenderDelegate {
230
225
dynamicScope ?: DynamicScope
231
226
) : RenderResult {
232
227
let cursor = { element, nextSibling : null } ;
233
- let { program , runtime } = this . context ;
234
- let builder = this . getElementBuilder ( runtime . env , cursor ) ;
235
- let iterator = renderComponent ( runtime , builder , program , { } , component , args , dynamicScope ) ;
228
+ let { env } = this . context ;
229
+ let builder = this . getElementBuilder ( env , cursor ) ;
230
+ let iterator = renderComponent ( this . context , builder , { } , component , args , dynamicScope ) ;
236
231
237
- return renderSync ( runtime . env , iterator ) ;
232
+ return renderSync ( env , iterator ) ;
238
233
}
239
234
240
235
private get precompileOptions ( ) : PrecompileOptions {
0 commit comments