@@ -6,10 +6,11 @@ import {
66import * as ts from 'typescript' ;
77import { GetProgram } from "../../../src/transformer/program/program" ;
88import { baseTransformer } from '../../../src/transformer/base/base' ;
9- import { GetTypeQueryDescriptor } from '../../../src/transformer/descriptor/typeQuery/typeQuery' ;
10- import { Scope } from '../../../src/transformer/scope/scope' ;
119import { DefinitelyTypedTransformerLogger } from './logger' ;
1210import * as path from 'path' ;
11+ import { GetPropertiesFromSourceFileOrModuleDeclaration } from '../../../src/transformer/descriptor/module/module' ;
12+ import { Scope } from '../../../src/transformer/scope/scope' ;
13+ import { GetMockPropertiesFromDeclarations } from '../../../src/transformer/descriptor/mock/mockProperties' ;
1314
1415const customFunctions : CustomFunction [ ] = [
1516 {
@@ -21,6 +22,8 @@ const customFunctions: CustomFunction[] = [
2122const transformer = baseTransformer ( visitNode , customFunctions ) ;
2223export { transformer } ;
2324
25+ type CompatibleStatement = ts . InterfaceDeclaration | ts . FunctionDeclaration | ts . ClassDeclaration | ts . ModuleDeclaration ;
26+
2427function visitNode ( node : ts . CallExpression , declaration : ts . FunctionDeclaration ) : ts . Node {
2528 const typeQueryNode : ts . TypeNode = node . typeArguments [ 0 ] ;
2629
@@ -42,20 +45,34 @@ function visitNode(node: ts.CallExpression, declaration: ts.FunctionDeclaration)
4245 ( statement : ts . Statement ) => statement . kind === ts . SyntaxKind . InterfaceDeclaration
4346 || statement . kind === ts . SyntaxKind . FunctionDeclaration
4447 || statement . kind === ts . SyntaxKind . ClassDeclaration
48+ || statement . kind === ts . SyntaxKind . ModuleDeclaration
4549 ) ;
4650
4751 if ( compatibleStatements . length > 0 ) {
48- return ts . createArrayLiteral ( compatibleStatements . map ( ( workingStatement : ts . InterfaceDeclaration | ts . FunctionDeclaration | ts . ClassDeclaration ) => {
49- const nodeToMock : ts . TypeReferenceNode = ts . createTypeReferenceNode ( workingStatement . name , [ ] ) ;
52+ return ts . createArrayLiteral ( compatibleStatements . map (
53+ ( workingStatement : CompatibleStatement ) => {
54+ const name : ts . Identifier = workingStatement . name as ts . Identifier ;
55+ const scope = new Scope ( ) ;
56+
57+ if ( ts . isModuleDeclaration ( workingStatement ) ) {
58+ return GetMockPropertiesFromDeclarations (
59+ GetPropertiesFromSourceFileOrModuleDeclaration ( ( workingStatement as any ) . symbol , scope ) ,
60+ [ ] ,
61+ scope
62+ )
63+ }
64+
65+ const nodeToMock : ts . TypeReferenceNode = ts . createTypeReferenceNode ( name , undefined ) ;
5066 return getMock ( nodeToMock , node ) ;
51- } ) ) ;
67+
68+ } , [ ] ) ) ;
5269 }
5370 DefinitelyTypedTransformerLogger ( ) . moduleWithoutValidTypeStatements ( moduleName ) ;
5471
5572 return node ;
5673 }
5774
58- return GetTypeQueryDescriptor ( typeQueryNode , new Scope ( ) ) ;
75+ return getMock ( typeQueryNode , node ) ;
5976 }
6077
6178 return node ;
0 commit comments