@@ -11,7 +11,7 @@ import * as ts from 'typescript';
11
11
12
12
import { absoluteFrom , AbsoluteFsPath , getSourceFileOrError , LogicalFileSystem } from '../../file_system' ;
13
13
import { TestFile } from '../../file_system/testing' ;
14
- import { AbsoluteModuleStrategy , LocalIdentifierStrategy , LogicalProjectStrategy , ModuleResolver , Reexport , Reference , ReferenceEmitter } from '../../imports' ;
14
+ import { AbsoluteModuleStrategy , LocalIdentifierStrategy , LogicalProjectStrategy , ModuleResolver , Reexport , Reference , ReferenceEmitter , RelativePathStrategy } from '../../imports' ;
15
15
import { NOOP_INCREMENTAL_BUILD } from '../../incremental' ;
16
16
import { ClassPropertyMapping , CompoundMetadataReader } from '../../metadata' ;
17
17
import { ClassDeclaration , isNamedClassDeclaration , TypeScriptReflectionHost } from '../../reflection' ;
@@ -28,6 +28,7 @@ import {Environment} from '../src/environment';
28
28
import { OutOfBandDiagnosticRecorder } from '../src/oob' ;
29
29
import { TypeCheckShimGenerator } from '../src/shim' ;
30
30
import { generateTypeCheckBlock } from '../src/type_check_block' ;
31
+ import { TypeCheckFile } from '../src/type_check_file' ;
31
32
32
33
export function typescriptLibDts ( ) : TestFile {
33
34
return {
@@ -201,6 +202,7 @@ export type TestDirective = Partial<Pick<
201
202
coercedInputFields ?: string [ ] , restrictedInputFields ?: string [ ] ,
202
203
stringLiteralInputFields ?: string [ ] , undeclaredInputFields ?: string [ ] , isGeneric ?: boolean ;
203
204
} ;
205
+
204
206
export type TestPipe = {
205
207
name : string ,
206
208
file ?: AbsoluteFsPath , pipeName : string , type : 'pipe' ,
@@ -212,9 +214,14 @@ export function tcb(
212
214
template : string , declarations : TestDeclaration [ ] = [ ] , config ?: TypeCheckingConfig ,
213
215
options ?: { emitSpans ?: boolean } ) : string {
214
216
const classes = [ 'Test' , ...declarations . map ( decl => decl . name ) ] ;
215
- const code = classes . map ( name => `class ${ name } <T extends string> {}` ) . join ( '\n' ) ;
217
+ const code = classes . map ( name => `export class ${ name } <T extends string> {}` ) . join ( '\n' ) ;
218
+
219
+ const rootFilePath = absoluteFrom ( '/synthetic.ts' ) ;
220
+ const { program, host} = makeProgram ( [
221
+ { name : rootFilePath , contents : code , isRoot : true } ,
222
+ ] ) ;
216
223
217
- const sf = ts . createSourceFile ( 'synthetic.ts' , code , ts . ScriptTarget . Latest , true ) ;
224
+ const sf = getSourceFileOrError ( program , rootFilePath ) ;
218
225
const clazz = getClass ( sf , 'Test' ) ;
219
226
const templateUrl = 'synthetic.html' ;
220
227
const { nodes} = parseTemplate ( template , templateUrl ) ;
@@ -251,13 +258,25 @@ export function tcb(
251
258
emitSpans : false ,
252
259
} ;
253
260
261
+ const fileName = absoluteFrom ( '/type-check-file.ts' ) ;
262
+
263
+ const reflectionHost = new TypeScriptReflectionHost ( program . getTypeChecker ( ) ) ;
264
+
265
+ const refEmmiter : ReferenceEmitter = new ReferenceEmitter (
266
+ [ new LocalIdentifierStrategy ( ) , new RelativePathStrategy ( reflectionHost ) ] ) ;
267
+
268
+ const env = new TypeCheckFile ( fileName , config , refEmmiter , reflectionHost , host ) ;
269
+
270
+ const ref = new Reference ( clazz ) ;
271
+
254
272
const tcb = generateTypeCheckBlock (
255
- FakeEnvironment . newFake ( config ) , new Reference ( clazz ) , ts . createIdentifier ( 'Test_TCB' ) , meta ,
256
- new NoopSchemaChecker ( ) , new NoopOobRecorder ( ) ) ;
273
+ env , ref , ts . createIdentifier ( 'Test_TCB' ) , meta , new NoopSchemaChecker ( ) ,
274
+ new NoopOobRecorder ( ) ) ;
275
+
276
+ env . addTypeCheckBlock ( ref , meta , new NoopSchemaChecker ( ) , new NoopOobRecorder ( ) ) ;
257
277
258
- const removeComments = ! options . emitSpans ;
259
- const res = ts . createPrinter ( { removeComments} ) . printNode ( ts . EmitHint . Unspecified , tcb , sf ) ;
260
- return res . replace ( / \s + / g, ' ' ) ;
278
+ const rendered = env . render ( ! options . emitSpans /* removeComments */ ) ;
279
+ return rendered . replace ( / \s + / g, ' ' ) ;
261
280
}
262
281
263
282
/**
0 commit comments