9
9
import * as ts from 'typescript' ;
10
10
11
11
import { Evaluator , errorSymbol } from './evaluator' ;
12
- import { ClassMetadata , ConstructorMetadata , FunctionMetadata , MemberMetadata , MetadataEntry , MetadataError , MetadataMap , MetadataSymbolicBinaryExpression , MetadataSymbolicCallExpression , MetadataSymbolicExpression , MetadataSymbolicIfExpression , MetadataSymbolicIndexExpression , MetadataSymbolicPrefixExpression , MetadataSymbolicReferenceExpression , MetadataSymbolicSelectExpression , MetadataSymbolicSpreadExpression , MetadataValue , MethodMetadata , ModuleExportMetadata , ModuleMetadata , VERSION , isClassMetadata , isConstructorMetadata , isFunctionMetadata , isMetadataError , isMetadataGlobalReferenceExpression , isMetadataSymbolicExpression , isMetadataSymbolicReferenceExpression , isMetadataSymbolicSelectExpression , isMethodMetadata } from './schema' ;
12
+ import { ClassMetadata , ConstructorMetadata , FunctionMetadata , InterfaceMetadata , MemberMetadata , MetadataEntry , MetadataError , MetadataMap , MetadataSymbolicBinaryExpression , MetadataSymbolicCallExpression , MetadataSymbolicExpression , MetadataSymbolicIfExpression , MetadataSymbolicIndexExpression , MetadataSymbolicPrefixExpression , MetadataSymbolicReferenceExpression , MetadataSymbolicSelectExpression , MetadataSymbolicSpreadExpression , MetadataValue , MethodMetadata , ModuleExportMetadata , ModuleMetadata , VERSION , isClassMetadata , isConstructorMetadata , isFunctionMetadata , isMetadataError , isMetadataGlobalReferenceExpression , isMetadataSymbolicExpression , isMetadataSymbolicReferenceExpression , isMetadataSymbolicSelectExpression , isMethodMetadata } from './schema' ;
13
13
import { Symbols } from './symbols' ;
14
14
15
15
// In TypeScript 2.1 these flags moved
@@ -56,7 +56,8 @@ export class MetadataCollector {
56
56
*/
57
57
public getMetadata ( sourceFile : ts . SourceFile , strict : boolean = false ) : ModuleMetadata {
58
58
const locals = new Symbols ( sourceFile ) ;
59
- const nodeMap = new Map < MetadataValue | ClassMetadata | FunctionMetadata , ts . Node > ( ) ;
59
+ const nodeMap =
60
+ new Map < MetadataValue | ClassMetadata | InterfaceMetadata | FunctionMetadata , ts . Node > ( ) ;
60
61
const evaluator = new Evaluator ( locals , nodeMap , this . options ) ;
61
62
let metadata : { [ name : string ] : MetadataValue | ClassMetadata | FunctionMetadata } | undefined ;
62
63
let exports : ModuleExportMetadata [ ] ;
@@ -264,13 +265,14 @@ export class MetadataCollector {
264
265
} ) ;
265
266
266
267
const isExportedIdentifier = ( identifier : ts . Identifier ) => exportMap . has ( identifier . text ) ;
267
- const isExported = ( node : ts . FunctionDeclaration | ts . ClassDeclaration | ts . EnumDeclaration ) =>
268
- isExport ( node ) || isExportedIdentifier ( node . name ) ;
268
+ const isExported =
269
+ ( node : ts . FunctionDeclaration | ts . ClassDeclaration | ts . InterfaceDeclaration |
270
+ ts . EnumDeclaration ) => isExport ( node ) || isExportedIdentifier ( node . name ) ;
269
271
const exportedIdentifierName = ( identifier : ts . Identifier ) =>
270
272
exportMap . get ( identifier . text ) || identifier . text ;
271
273
const exportedName =
272
- ( node : ts . FunctionDeclaration | ts . ClassDeclaration | ts . EnumDeclaration ) =>
273
- exportedIdentifierName ( node . name ) ;
274
+ ( node : ts . FunctionDeclaration | ts . ClassDeclaration | ts . InterfaceDeclaration |
275
+ ts . EnumDeclaration ) => exportedIdentifierName ( node . name ) ;
274
276
275
277
276
278
// Predeclare classes and functions
@@ -290,6 +292,15 @@ export class MetadataCollector {
290
292
}
291
293
break ;
292
294
295
+ case ts . SyntaxKind . InterfaceDeclaration :
296
+ const interfaceDeclaration = < ts . InterfaceDeclaration > node ;
297
+ if ( interfaceDeclaration . name ) {
298
+ const interfaceName = interfaceDeclaration . name . text ;
299
+ // All references to interfaces should be converted to references to `any`.
300
+ locals . define ( interfaceName , { __symbolic : 'reference' , name : 'any' } ) ;
301
+ }
302
+ break ;
303
+
293
304
case ts . SyntaxKind . FunctionDeclaration :
294
305
const functionDeclaration = < ts . FunctionDeclaration > node ;
295
306
if ( ! isExported ( functionDeclaration ) ) {
@@ -356,6 +367,14 @@ export class MetadataCollector {
356
367
// Otherwise don't record metadata for the class.
357
368
break ;
358
369
370
+ case ts . SyntaxKind . InterfaceDeclaration :
371
+ const interfaceDeclaration = < ts . InterfaceDeclaration > node ;
372
+ if ( interfaceDeclaration . name && isExported ( interfaceDeclaration ) ) {
373
+ if ( ! metadata ) metadata = { } ;
374
+ metadata [ exportedName ( interfaceDeclaration ) ] = { __symbolic : 'interface' } ;
375
+ }
376
+ break ;
377
+
359
378
case ts . SyntaxKind . FunctionDeclaration :
360
379
// Record functions that return a single value. Record the parameter
361
380
// names substitution will be performed by the StaticReflector.
0 commit comments