Skip to content

Commit

Permalink
feat(typescript): add support for typescript 3.8 (#246)
Browse files Browse the repository at this point in the history
  • Loading branch information
uittorio authored Mar 1, 2020
1 parent a93385e commit 2a18bed
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 21 deletions.
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
"ts-node": "^8.6.2",
"tslint": "^6.0.0",
"ttypescript": "1.5.10",
"typescript": "^3.7.5",
"typescript": "^3.8.3",
"webpack": "^4.41.6",
"webpack-cli": "^3.3.11",
"webpack-merge": "^4.2.2",
Expand Down
4 changes: 2 additions & 2 deletions src/transformer/descriptor/bigint/bigint.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import * as ts from 'typescript';
import { TypescriptCreator } from '../../helper/creator';

export function GetBigIntDescriptor(): ts.CallExpression {
return ts.createCall(
return TypescriptCreator.createCall(
ts.createIdentifier('BigInt'),
undefined,
[ts.createNumericLiteral('0')],
);

Expand Down
2 changes: 1 addition & 1 deletion src/transformer/descriptor/method/method.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export function GetMethodDescriptor(propertyName: ts.PropertyName, returnValue:
true,
));

return ts.createCall(providerGetMethod, [], [propertyNameStringLiteral, propertyValueFunction]);
return TypescriptCreator.createCall(providerGetMethod, [propertyNameStringLiteral, propertyValueFunction]);
}

function CreateProviderGetMethod(): ts.PropertyAccessExpression {
Expand Down
2 changes: 1 addition & 1 deletion src/transformer/descriptor/mock/mockCall.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { PropertyAssignments } from './mockPropertiesAssignments';
export function GetMockCall(properties: PropertyAssignments, signature: ts.Expression): ts.CallExpression {
const mockObjectReturnValueName: ts.Identifier = MockIdentifierObjectReturnValue;
const statements: ts.Statement[] = [
ts.createVariableStatement([], [
TypescriptCreator.createVariableStatement([
TypescriptCreator.createVariableDeclaration(MockIdentifierInternalValues, ts.createObjectLiteral()),
TypescriptCreator.createVariableDeclaration(mockObjectReturnValueName, signature || ts.createObjectLiteral(properties.literals)),
]),
Expand Down
22 changes: 17 additions & 5 deletions src/transformer/helper/creator.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,31 @@
import { PropertyName } from 'typescript';
import { PropertyName, VariableDeclaration, VariableStatement} from 'typescript';
import * as ts from 'typescript';

export namespace TypescriptCreator {
export function createArrowFunction(block: ts.ConciseBody, parameter: ReadonlyArray<ts.ParameterDeclaration> = []): ts.ArrowFunction {
return ts.createArrowFunction([], [], parameter, undefined, ts.createToken(ts.SyntaxKind.EqualsGreaterThanToken), block);
return ts.createArrowFunction(undefined, undefined, parameter, undefined, ts.createToken(ts.SyntaxKind.EqualsGreaterThanToken), block);
}

export function createFunctionExpression(block: ts.Block, parameter: ReadonlyArray<ts.ParameterDeclaration> = []): ts.FunctionExpression {
return ts.createFunctionExpression([], null, undefined, [], parameter, undefined, block);
return ts.createFunctionExpression(undefined, undefined, undefined, undefined, parameter, undefined, block);
}

export function createFunctionExpressionReturn(descriptorToReturn: ts.Expression, parameter: ReadonlyArray<ts.ParameterDeclaration> = []): ts.FunctionExpression {
const block: ts.Block = ts.createBlock([ts.createReturn(descriptorToReturn)]);

return ts.createFunctionExpression([], null, undefined, [], parameter, undefined, block);
return ts.createFunctionExpression(undefined, undefined, undefined, undefined, parameter, undefined, block);
}

export function createCall(expression: ts.Expression, argumentExpressions: ts.Expression[]): ts.CallExpression {
return ts.createCall(
expression,
undefined,
argumentExpressions,
);
}

export function createVariableStatement(declarations: VariableDeclaration[]): VariableStatement {
return ts.createVariableStatement(undefined, declarations);
}

export function createIIFE(block: ts.Block): ts.CallExpression {
Expand All @@ -37,7 +49,7 @@ export namespace TypescriptCreator {
}

export function createProperty(propertyName: string | PropertyName, type: ts.TypeNode): ts.PropertyDeclaration {
return ts.createProperty([], [], propertyName, undefined, type, undefined);
return ts.createProperty(undefined, undefined, propertyName, undefined, type, undefined);
}

export function createPropertySignature(propertyName: string | PropertyName, type: ts.TypeNode): ts.PropertySignature {
Expand Down
13 changes: 5 additions & 8 deletions src/transformer/mockFactoryCall/mockFactoryCall.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { GenericDeclarationSupported } from '../genericDeclaration/genericDeclar
import { MockDefiner } from '../mockDefiner/mockDefiner';
import { MockIdentifierGenericParameter } from '../mockIdentifier/mockIdentifier';
import { Scope } from '../scope/scope';
import { TypescriptCreator } from '../helper/creator';

export function GetMockFactoryCall(typeReferenceNode: ts.TypeReferenceNode, scope: Scope): ts.Expression {
const declaration: ts.Declaration = TypescriptHelper.GetDeclarationFromNode(typeReferenceNode.typeName);
Expand Down Expand Up @@ -40,29 +41,26 @@ export function GetMockFactoryCallIntersection(intersection: ts.IntersectionType
const genericsParametersExpression: ts.ObjectLiteralExpression[] = genericDeclaration.getExpressionForAllGenerics();
const mockFactoryCall: ts.Expression = MockDefiner.instance.getMockFactoryIntersection(declarations, intersection);

return ts.createCall(
return TypescriptCreator.createCall(
mockFactoryCall,
[],
[ts.createArrayLiteral(genericsParametersExpression)],
);
}

export function GetMockFactoryCallTypeofEnum(declaration: ts.EnumDeclaration): ts.Expression {
const mockFactoryCall: ts.Expression = MockDefiner.instance.getMockFactoryTypeofEnum(declaration);

return ts.createCall(
return TypescriptCreator.createCall(
mockFactoryCall,
[],
[],
);
}

export function GetMockFactoryCallForThis(mockKey: string): ts.Expression {
const mockFactoryCall: ts.Expression = MockDefiner.instance.getMockFactoryByKey(mockKey);

return ts.createCall(
return TypescriptCreator.createCall(
mockFactoryCall,
[],
[MockIdentifierGenericParameter],
);
}
Expand All @@ -78,9 +76,8 @@ function getDeclarationMockFactoryCall(declaration: ts.Declaration, typeReferenc

const genericsParametersExpression: ts.ObjectLiteralExpression[] = genericDeclaration.getExpressionForAllGenerics();

return ts.createCall(
return TypescriptCreator.createCall(
mockFactoryCall,
[],
[ts.createArrayLiteral(genericsParametersExpression)],
);
}
Expand Down

0 comments on commit 2a18bed

Please sign in to comment.