-
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #19 from uittorio/fix_class_method_without_return_…
…type fix bug where a mock of a method with body without specified return type was failing
- Loading branch information
Showing
8 changed files
with
859 additions
and
822 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import * as ts from "typescript"; | ||
import {GetDescriptor} from "../descriptor"; | ||
import {GetNullDescriptor} from "../null/null"; | ||
|
||
export function GetReturnTypeFromBody(node: ts.ArrowFunction | ts.FunctionExpression | ts.MethodDeclaration): ts.Expression { | ||
let returnValue: ts.Expression; | ||
|
||
const functionBody = node.body as ts.FunctionBody; | ||
|
||
if (functionBody.statements) { | ||
const returnStatement: ts.ReturnStatement = GetReturnStatement(functionBody); | ||
|
||
if (returnStatement) { | ||
returnValue = GetDescriptor(returnStatement.expression); | ||
} else { | ||
returnValue = GetNullDescriptor(); | ||
} | ||
} else { | ||
returnValue = GetDescriptor(node.body); | ||
} | ||
|
||
return returnValue; | ||
} | ||
|
||
function GetReturnStatement(body: ts.FunctionBody): ts.ReturnStatement { | ||
return body.statements.find((statement: ts.Statement) => { | ||
return statement.kind === ts.SyntaxKind.ReturnStatement | ||
}) as ts.ReturnStatement | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,13 @@ | ||
import * as ts from 'typescript'; | ||
import { GetDescriptor } from "../descriptor"; | ||
import { GetNullDescriptor } from "../null/null"; | ||
import { PropertySignatureCache } from "../property/cache"; | ||
import { GetMethodDescriptor } from "./method"; | ||
import {PropertySignatureCache} from "../property/cache"; | ||
import {GetMethodDescriptor} from "./method"; | ||
import {GetReturnTypeFromBody} from "./bodyReturnType"; | ||
|
||
type functionAssignment = ts.ArrowFunction | ts.FunctionExpression; | ||
|
||
export function GetFunctionAssignmentDescriptor(node: functionAssignment): ts.Expression { | ||
const property: ts.PropertyName = PropertySignatureCache.instance.get(); | ||
let returnValue; | ||
|
||
const functionBody = node.body as ts.FunctionBody; | ||
|
||
if (functionBody.statements) { | ||
const returnStatement: ts.ReturnStatement = GetReturnStatement(functionBody); | ||
|
||
if (returnStatement) { | ||
returnValue = GetDescriptor(returnStatement.expression); | ||
} else { | ||
returnValue = GetNullDescriptor(); | ||
} | ||
|
||
return GetMethodDescriptor(property, returnValue); | ||
} else { | ||
returnValue = GetDescriptor(node.body); | ||
} | ||
|
||
return GetMethodDescriptor(property, returnValue); | ||
} | ||
const property: ts.PropertyName = PropertySignatureCache.instance.get(); | ||
const returnValue = GetReturnTypeFromBody(node); | ||
|
||
function GetReturnStatement(body: ts.FunctionBody): ts.ReturnStatement { | ||
return body.statements.find((statement: ts.Statement) => { | ||
return statement.kind === ts.SyntaxKind.ReturnStatement | ||
}) as ts.ReturnStatement | ||
} | ||
return GetMethodDescriptor(property, returnValue); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,16 @@ | ||
import * as ts from 'typescript'; | ||
import { GetMethodDescriptor } from "./method"; | ||
import { GetDescriptor } from "../descriptor"; | ||
import {GetMethodDescriptor} from "./method"; | ||
import {GetDescriptor} from "../descriptor"; | ||
import {GetReturnTypeFromBody} from "./bodyReturnType"; | ||
|
||
type Methods = ts.MethodSignature | ts.MethodDeclaration; | ||
export function GetMethodDeclarationDescriptor(node: ts.MethodDeclaration): ts.Expression { | ||
let returnType: ts.Expression; | ||
|
||
export function GetMethodDeclarationDescriptor(node: Methods): ts.Expression { | ||
const returnValue: ts.Expression = GetDescriptor(node.type); | ||
return GetMethodDescriptor(node.name, returnValue); | ||
if (node.type) { | ||
returnType = GetDescriptor(node.type); | ||
} else { | ||
returnType = GetReturnTypeFromBody(node); | ||
} | ||
|
||
return GetMethodDescriptor(node.name, returnType); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import * as ts from "typescript"; | ||
import {GetDescriptor} from "../descriptor"; | ||
import {GetMethodDescriptor} from "./method"; | ||
|
||
type Methods = ts.MethodSignature | ts.MethodDeclaration; | ||
|
||
export function GetMethodSignatureDescriptor(node: Methods): ts.Expression { | ||
const returnType: ts.Expression = GetDescriptor(node.type); | ||
return GetMethodDescriptor(node.name, returnType); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters