-
-
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.
feat(map): add Map support as a type (#228)
* #225 add Map support as a type Also changed a linting rule for indentation, remove some code regarding typescript types, fixed a bug when using typeof variable without type and function call initializer and removed descriptor 'case' for function call * remove extra webpack configuration * use custom function to get null descriptor * remove casting, use typescript function to narrow type * handle callExpression in descriptor, handle calls of variables
- Loading branch information
Showing
22 changed files
with
456 additions
and
247 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
36 changes: 36 additions & 0 deletions
36
src/transformer/descriptor/callExpression/callExpression.ts
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,36 @@ | ||
import { FunctionLikeDeclaration } from 'typescript'; | ||
import * as ts from 'typescript'; | ||
import { TransformerLogger } from '../../logger/transformerLogger'; | ||
import { NodeToString } from '../../printNode'; | ||
import { Scope } from '../../scope/scope'; | ||
import { GetDescriptor } from '../descriptor'; | ||
import { TypescriptHelper } from '../helper/helper'; | ||
import { GetFunctionReturnType } from '../method/functionReturnType'; | ||
import { GetNullDescriptor } from '../null/null'; | ||
|
||
export function GetCallExpressionDescriptor(node: ts.CallExpression, scope: Scope): ts.Expression { | ||
return GetDescriptor(GetCallExpressionType(node), scope); | ||
} | ||
|
||
export function GetCallExpressionType(node: ts.CallExpression): ts.Node { | ||
const declaration: ts.Declaration = TypescriptHelper.GetDeclarationFromNode(node.expression); | ||
|
||
return GetFinalFunctionTypeFromDeclaration(node, declaration); | ||
} | ||
|
||
function GetFinalFunctionTypeFromDeclaration(initialNode: ts.Node, node: ts.Node): ts.Node { | ||
if (ts.isFunctionLike(node)) { | ||
return GetFunctionReturnType(node as FunctionLikeDeclaration); | ||
} else if (ts.isVariableDeclaration(node)) { | ||
if (node.type) { | ||
if (ts.isFunctionTypeNode(node.type)) { | ||
return node.type.type; | ||
} | ||
} else if (node.initializer) { | ||
return GetFinalFunctionTypeFromDeclaration(initialNode, node.initializer); | ||
} | ||
} | ||
|
||
TransformerLogger().typeOfFunctionCallNotFound(NodeToString(initialNode)); | ||
return GetNullDescriptor(); | ||
} |
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,14 +1,14 @@ | ||
import * as ts from 'typescript'; | ||
import { Scope } from '../../scope/scope'; | ||
import { PropertySignatureCache } from '../property/cache'; | ||
import { GetReturnTypeFromBody } from './bodyReturnType'; | ||
import { GetReturnTypeFromBodyDescriptor } 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 = GetReturnTypeFromBody(node, scope); | ||
const returnValue: ts.Expression = GetReturnTypeFromBodyDescriptor(node, scope); | ||
|
||
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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import * as ts from 'typescript'; | ||
import { GetReturnNodeFromBody } from './bodyReturnType'; | ||
|
||
export function GetFunctionReturnType(node: ts.FunctionLikeDeclaration): ts.Node { | ||
let returnType: ts.Node; | ||
|
||
if (node.type) { | ||
returnType = node.type; | ||
} else { | ||
returnType = GetReturnNodeFromBody(node); | ||
} | ||
|
||
return 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 |
---|---|---|
@@ -1,17 +1,12 @@ | ||
import * as ts from 'typescript'; | ||
import { Scope } from '../../scope/scope'; | ||
import { GetDescriptor } from '../descriptor'; | ||
import { GetReturnTypeFromBody } from './bodyReturnType'; | ||
import { GetFunctionReturnType } from './functionReturnType'; | ||
import { GetMethodDescriptor } from './method'; | ||
|
||
export function GetMethodDeclarationDescriptor(node: ts.MethodDeclaration | ts.FunctionDeclaration, scope: Scope): ts.Expression { | ||
let returnType: ts.Expression; | ||
|
||
if (node.type) { | ||
returnType = GetDescriptor(node.type, scope); | ||
} else { | ||
returnType = GetReturnTypeFromBody(node, scope); | ||
} | ||
const returnTypeNode: ts.Node = GetFunctionReturnType(node); | ||
const returnType: ts.Expression = GetDescriptor(returnTypeNode, scope); | ||
|
||
return GetMethodDescriptor(node.name, returnType); | ||
} |
Oops, something went wrong.