-
-
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.
enhancement(transformer): Refactor GetMethodDescriptor implementation…
… and utilize TypeScript's MethodSignature type
- Loading branch information
1 parent
d4f3a41
commit eebf687
Showing
7 changed files
with
82 additions
and
173 deletions.
There are no files selected for viewing
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,14 +1,26 @@ | ||
import * as ts from 'typescript'; | ||
import { Scope } from '../../scope/scope'; | ||
import { TypescriptCreator } from '../../helper/creator'; | ||
import { PropertySignatureCache } from '../property/cache'; | ||
import { GetReturnTypeFromBodyDescriptor } from './bodyReturnType'; | ||
import { GetReturnNodeFromBody } from './bodyReturnType'; | ||
import { GetMethodDescriptor } from './method'; | ||
|
||
type functionAssignment = ts.ArrowFunction | ts.FunctionExpression; | ||
|
||
export function GetFunctionAssignmentDescriptor(node: functionAssignment, scope: Scope): ts.Expression { | ||
const property: ts.PropertyName = PropertySignatureCache.instance.get(); | ||
const returnValue: ts.Expression = GetReturnTypeFromBodyDescriptor(node, scope); | ||
const returnValue: ts.Expression = GetReturnNodeFromBody(node); | ||
|
||
return GetMethodDescriptor(property, [{ returnValue }]); | ||
const returnType: ts.TypeNode = ts.createLiteralTypeNode(returnValue as ts.LiteralExpression); | ||
|
||
return GetMethodDescriptor( | ||
property, | ||
[ | ||
TypescriptCreator.createMethodSignature( | ||
undefined, | ||
returnType, | ||
), | ||
], | ||
scope, | ||
); | ||
} |
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
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,17 +1,19 @@ | ||
import * as ts from 'typescript'; | ||
import { Scope } from '../../scope/scope'; | ||
import { GetDescriptor } from '../descriptor'; | ||
import { TypescriptCreator } from '../../helper/creator'; | ||
import { GetNullDescriptor } from '../null/null'; | ||
import { GetMethodDescriptor } from './method'; | ||
|
||
export function GetMethodSignatureDescriptor(node: ts.MethodSignature, scope: Scope): ts.Expression { | ||
let returnValue: ts.Expression; | ||
|
||
if (node.type) { | ||
returnValue = GetDescriptor(node.type, scope); | ||
} else { | ||
returnValue = GetNullDescriptor(); | ||
} | ||
|
||
return GetMethodDescriptor(node.name, [{ returnValue }]); | ||
return GetMethodDescriptor( | ||
node.name, | ||
[ | ||
TypescriptCreator.createMethodSignature( | ||
node.parameters.map((p: ts.ParameterDeclaration) => p.type), | ||
node.type, | ||
), | ||
], | ||
scope, | ||
); | ||
} |
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