11import * as ts from 'typescript' ;
22import { TypescriptCreator } from '../../helper/creator' ;
33import { MockIdentifierInternalValues , MockIdentifierObjectReturnValue } from '../../mockIdentifier/mockIdentifier' ;
4+ import { GetMethodDescriptor , MethodSignature } from '../method/method' ;
45import { GetMockMarkerProperty , Property } from './mockMarker' ;
56import { PropertyAssignments } from './mockPropertiesAssignments' ;
67
7- export function GetMockCall ( properties : PropertyAssignments , signature : ts . Expression | null ) : ts . CallExpression {
8+ export function GetMockCall ( properties : PropertyAssignments , signatures : MethodSignature [ ] ) : ts . CallExpression {
89 const mockObjectReturnValueName : ts . Identifier = MockIdentifierObjectReturnValue ;
10+
11+ if ( signatures . length ) {
12+ // FIXME: It'd probably be wise to extract the name of the callable
13+ // signature and fallback to `new` or smth if there is none.
14+ return GetMethodDescriptor ( ts . createStringLiteral ( 'new' ) , signatures ) ;
15+ }
16+
917 const statements : ts . Statement [ ] = [
1018 TypescriptCreator . createVariableStatement ( [
1119 TypescriptCreator . createVariableDeclaration ( MockIdentifierInternalValues , ts . createObjectLiteral ( ) ) ,
12- TypescriptCreator . createVariableDeclaration ( mockObjectReturnValueName , signature || ts . createObjectLiteral ( properties . literals ) ) ,
20+ TypescriptCreator . createVariableDeclaration ( mockObjectReturnValueName , ts . createObjectLiteral ( properties . literals ) ) ,
1321 ] ) ,
1422 ] ;
1523
16- if ( signature ) {
17- let literalProperty : ts . PropertyAssignment ;
18- let index : number = 0 ;
24+ // if (signatures[0] ) {
25+ // let literalProperty: ts.PropertyAssignment;
26+ // let index: number = 0;
1927
20- // tslint:disable-next-line:no-conditional-assignment
21- while ( ( literalProperty = properties . literals [ index ++ ] ) ) {
22- statements . push ( AssignLiteralPropertyTo ( mockObjectReturnValueName , literalProperty ) ) ;
23- }
24- }
28+ // // tslint:disable-next-line:no-conditional-assignment
29+ // while ((literalProperty = properties.literals[index++])) {
30+ // statements.push(AssignLiteralPropertyTo(mockObjectReturnValueName, literalProperty));
31+ // }
32+ // }
2533
2634 if ( properties . lazy . length ) {
2735 const addPropertiesToUniqueVariable : ts . ExpressionStatement = AssignPropertiesTo ( properties . lazy , mockObjectReturnValueName ) ;
@@ -30,24 +38,24 @@ export function GetMockCall(properties: PropertyAssignments, signature: ts.Expre
3038
3139 const addMockMarkerToUniqueVariable : ts . ExpressionStatement = AssignMockMarkerPropertyTo ( mockObjectReturnValueName ) ;
3240 statements . push ( addMockMarkerToUniqueVariable ) ;
33-
3441 statements . push ( ts . createReturn ( mockObjectReturnValueName ) ) ;
3542
3643 const functionBlock : ts . Block = ts . createBlock ( statements ) ;
3744 const functionExpression : ts . FunctionExpression = TypescriptCreator . createFunctionExpression ( functionBlock ) ;
3845 const IFFEFunction : ts . ParenthesizedExpression = ts . createParen ( functionExpression ) ;
46+
3947 return ts . createCall ( IFFEFunction , [ ] , [ ] ) ;
4048}
4149
42- function AssignVariableTo ( variable : ts . Expression , expression : ts . Expression ) : ts . ExpressionStatement {
43- const binaryExpression : ts . BinaryExpression = ts . createBinary ( variable , ts . SyntaxKind . EqualsToken , expression ) ;
44- return ts . createExpressionStatement ( binaryExpression ) ;
45- }
50+ // function AssignVariableTo(variable: ts.Expression, expression: ts.Expression): ts.ExpressionStatement {
51+ // const binaryExpression: ts.BinaryExpression = ts.createBinary(variable, ts.SyntaxKind.EqualsToken, expression);
52+ // return ts.createExpressionStatement(binaryExpression);
53+ // }
4654
47- function AssignLiteralPropertyTo ( mockObjectReturnValueName : ts . Identifier , literalProperty : ts . PropertyAssignment ) : ts . ExpressionStatement {
48- const propertyAccess : ts . ElementAccessExpression = ts . createElementAccess ( mockObjectReturnValueName , literalProperty . name as ts . StringLiteral ) ;
49- return AssignVariableTo ( propertyAccess , literalProperty . initializer ) ;
50- }
55+ // function AssignLiteralPropertyTo(mockObjectReturnValueName: ts.Identifier, literalProperty: ts.PropertyAssignment): ts.ExpressionStatement {
56+ // const propertyAccess: ts.ElementAccessExpression = ts.createElementAccess(mockObjectReturnValueName, literalProperty.name as ts.StringLiteral);
57+ // return AssignVariableTo(propertyAccess, literalProperty.initializer);
58+ // }
5159
5260function AssignMockMarkerPropertyTo ( identifier : ts . Identifier ) : ts . ExpressionStatement {
5361 const mockMarkerProperty : Property = GetMockMarkerProperty ( ) ;
0 commit comments