From 2a18bed1925866d664b57e8f1369cfcff1d56953 Mon Sep 17 00:00:00 2001 From: Vittorio Date: Sun, 1 Mar 2020 18:16:58 +0530 Subject: [PATCH] feat(typescript): add support for typescript 3.8 (#246) --- package-lock.json | 6 ++--- package.json | 2 +- src/transformer/descriptor/bigint/bigint.ts | 4 ++-- src/transformer/descriptor/method/method.ts | 2 +- src/transformer/descriptor/mock/mockCall.ts | 2 +- src/transformer/helper/creator.ts | 22 ++++++++++++++----- .../mockFactoryCall/mockFactoryCall.ts | 13 +++++------ 7 files changed, 30 insertions(+), 21 deletions(-) diff --git a/package-lock.json b/package-lock.json index 6a5b9c742..744c9c189 100644 --- a/package-lock.json +++ b/package-lock.json @@ -7924,9 +7924,9 @@ "dev": true }, "typescript": { - "version": "3.7.5", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-3.7.5.tgz", - "integrity": "sha512-/P5lkRXkWHNAbcJIiHPfRoKqyd7bsyCma1hZNUGfn20qm64T6ZBlrzprymeu918H+mB/0rIg2gGK/BXkhhYgBw==", + "version": "3.8.3", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-3.8.3.tgz", + "integrity": "sha512-MYlEfn5VrLNsgudQTVJeNaQFUAI7DkhnOjdpAp4T+ku1TfQClewlbSuTVHiA+8skNBgaf02TL/kLOvig4y3G8w==", "dev": true }, "uglify-js": { diff --git a/package.json b/package.json index 14f956ec1..d6db9ed36 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/transformer/descriptor/bigint/bigint.ts b/src/transformer/descriptor/bigint/bigint.ts index c0f22b7e5..91a28de96 100644 --- a/src/transformer/descriptor/bigint/bigint.ts +++ b/src/transformer/descriptor/bigint/bigint.ts @@ -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')], ); diff --git a/src/transformer/descriptor/method/method.ts b/src/transformer/descriptor/method/method.ts index 2fefc9086..64db3e66e 100644 --- a/src/transformer/descriptor/method/method.ts +++ b/src/transformer/descriptor/method/method.ts @@ -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 { diff --git a/src/transformer/descriptor/mock/mockCall.ts b/src/transformer/descriptor/mock/mockCall.ts index 0e25d67ce..d84895b26 100644 --- a/src/transformer/descriptor/mock/mockCall.ts +++ b/src/transformer/descriptor/mock/mockCall.ts @@ -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)), ]), diff --git a/src/transformer/helper/creator.ts b/src/transformer/helper/creator.ts index 6e32e1631..bf16b8732 100644 --- a/src/transformer/helper/creator.ts +++ b/src/transformer/helper/creator.ts @@ -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.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.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.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 { @@ -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 { diff --git a/src/transformer/mockFactoryCall/mockFactoryCall.ts b/src/transformer/mockFactoryCall/mockFactoryCall.ts index f2df1d66a..512247866 100644 --- a/src/transformer/mockFactoryCall/mockFactoryCall.ts +++ b/src/transformer/mockFactoryCall/mockFactoryCall.ts @@ -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); @@ -40,9 +41,8 @@ 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)], ); } @@ -50,19 +50,17 @@ export function GetMockFactoryCallIntersection(intersection: ts.IntersectionType 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], ); } @@ -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)], ); }