From 3e442a040fdb3c487b92dbc9695a70ccb6b2987e Mon Sep 17 00:00:00 2001 From: hbofolts1 Date: Tue, 29 Aug 2023 12:17:28 -0700 Subject: [PATCH] build: update typescript to 5.2.2 --- package-lock.json | 79 +++------------------------ package.json | 2 +- src/Factories/ComponentFactory.ts | 15 +++-- src/Factories/MethodFactory.ts | 2 +- src/Factories/ParameterFactory.ts | 4 ++ src/Factories/PropertyFactory.ts | 5 ++ src/Factories/TypeParameterFactory.ts | 6 +- 7 files changed, 35 insertions(+), 78 deletions(-) diff --git a/package-lock.json b/package-lock.json index aa8f08a..07875f9 100644 --- a/package-lock.json +++ b/package-lock.json @@ -13,7 +13,7 @@ "glob": "^7.1.6", "node-plantuml": "0.9.0", "plantuml-encoder": "^1.4.0", - "typescript": "4.0.3" + "typescript": "5.2.2" }, "bin": { "tplant": "dist/index.js" @@ -1289,20 +1289,6 @@ "typescript": ">=4.2.0" } }, - "node_modules/@typescript-eslint/eslint-plugin/node_modules/typescript": { - "version": "5.2.2", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.2.2.tgz", - "integrity": "sha512-mI4WrpHsbCIcwT9cF4FZvr80QUeKvsUsUvKDoR+X/7XHQH98xYD8YHZg7ANtz2GtZt/CBq2QJ0thkGJMHfqc1w==", - "dev": true, - "peer": true, - "bin": { - "tsc": "bin/tsc", - "tsserver": "bin/tsserver" - }, - "engines": { - "node": ">=14.17" - } - }, "node_modules/@typescript-eslint/parser": { "version": "6.5.0", "resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-6.5.0.tgz", @@ -1387,20 +1373,6 @@ "typescript": ">=4.2.0" } }, - "node_modules/@typescript-eslint/type-utils/node_modules/typescript": { - "version": "5.2.2", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.2.2.tgz", - "integrity": "sha512-mI4WrpHsbCIcwT9cF4FZvr80QUeKvsUsUvKDoR+X/7XHQH98xYD8YHZg7ANtz2GtZt/CBq2QJ0thkGJMHfqc1w==", - "dev": true, - "peer": true, - "bin": { - "tsc": "bin/tsc", - "tsserver": "bin/tsserver" - }, - "engines": { - "node": ">=14.17" - } - }, "node_modules/@typescript-eslint/types": { "version": "6.5.0", "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-6.5.0.tgz", @@ -1453,20 +1425,6 @@ "typescript": ">=4.2.0" } }, - "node_modules/@typescript-eslint/typescript-estree/node_modules/typescript": { - "version": "5.2.2", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.2.2.tgz", - "integrity": "sha512-mI4WrpHsbCIcwT9cF4FZvr80QUeKvsUsUvKDoR+X/7XHQH98xYD8YHZg7ANtz2GtZt/CBq2QJ0thkGJMHfqc1w==", - "dev": true, - "peer": true, - "bin": { - "tsc": "bin/tsc", - "tsserver": "bin/tsserver" - }, - "engines": { - "node": ">=14.17" - } - }, "node_modules/@typescript-eslint/utils": { "version": "6.5.0", "resolved": "https://registry.npmjs.org/@typescript-eslint/utils/-/utils-6.5.0.tgz", @@ -5346,15 +5304,15 @@ } }, "node_modules/typescript": { - "version": "4.0.3", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.0.3.tgz", - "integrity": "sha512-tEu6DGxGgRJPb/mVPIZ48e69xCn2yRmCgYmDugAVwmJ6o+0u1RI18eO7E7WBTLYLaEVVOhwQmcdhQHweux/WPg==", + "version": "5.2.2", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.2.2.tgz", + "integrity": "sha512-mI4WrpHsbCIcwT9cF4FZvr80QUeKvsUsUvKDoR+X/7XHQH98xYD8YHZg7ANtz2GtZt/CBq2QJ0thkGJMHfqc1w==", "bin": { "tsc": "bin/tsc", "tsserver": "bin/tsserver" }, "engines": { - "node": ">=4.2.0" + "node": ">=14.17" } }, "node_modules/universalify": { @@ -6595,13 +6553,6 @@ "integrity": "sha512-Cbu4nIqnEdd+THNEsBdkolnOXhg0I8XteoHaEKgvsxpsbWda4IsUut2c187HxywQCvveojow0Dgw/amxtSKVkQ==", "dev": true, "requires": {} - }, - "typescript": { - "version": "5.2.2", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.2.2.tgz", - "integrity": "sha512-mI4WrpHsbCIcwT9cF4FZvr80QUeKvsUsUvKDoR+X/7XHQH98xYD8YHZg7ANtz2GtZt/CBq2QJ0thkGJMHfqc1w==", - "dev": true, - "peer": true } } }, @@ -6646,13 +6597,6 @@ "integrity": "sha512-Cbu4nIqnEdd+THNEsBdkolnOXhg0I8XteoHaEKgvsxpsbWda4IsUut2c187HxywQCvveojow0Dgw/amxtSKVkQ==", "dev": true, "requires": {} - }, - "typescript": { - "version": "5.2.2", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.2.2.tgz", - "integrity": "sha512-mI4WrpHsbCIcwT9cF4FZvr80QUeKvsUsUvKDoR+X/7XHQH98xYD8YHZg7ANtz2GtZt/CBq2QJ0thkGJMHfqc1w==", - "dev": true, - "peer": true } } }, @@ -6683,13 +6627,6 @@ "integrity": "sha512-Cbu4nIqnEdd+THNEsBdkolnOXhg0I8XteoHaEKgvsxpsbWda4IsUut2c187HxywQCvveojow0Dgw/amxtSKVkQ==", "dev": true, "requires": {} - }, - "typescript": { - "version": "5.2.2", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.2.2.tgz", - "integrity": "sha512-mI4WrpHsbCIcwT9cF4FZvr80QUeKvsUsUvKDoR+X/7XHQH98xYD8YHZg7ANtz2GtZt/CBq2QJ0thkGJMHfqc1w==", - "dev": true, - "peer": true } } }, @@ -9613,9 +9550,9 @@ } }, "typescript": { - "version": "4.0.3", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.0.3.tgz", - "integrity": "sha512-tEu6DGxGgRJPb/mVPIZ48e69xCn2yRmCgYmDugAVwmJ6o+0u1RI18eO7E7WBTLYLaEVVOhwQmcdhQHweux/WPg==" + "version": "5.2.2", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.2.2.tgz", + "integrity": "sha512-mI4WrpHsbCIcwT9cF4FZvr80QUeKvsUsUvKDoR+X/7XHQH98xYD8YHZg7ANtz2GtZt/CBq2QJ0thkGJMHfqc1w==" }, "universalify": { "version": "0.1.2", diff --git a/package.json b/package.json index d484419..fb6c9eb 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,7 @@ "glob": "^7.1.6", "node-plantuml": "0.9.0", "plantuml-encoder": "^1.4.0", - "typescript": "4.0.3" + "typescript": "5.2.2" }, "devDependencies": { "@types/glob": "^7.1.1", diff --git a/src/Factories/ComponentFactory.ts b/src/Factories/ComponentFactory.ts index 54928ff..410cfd4 100644 --- a/src/Factories/ComponentFactory.ts +++ b/src/Factories/ComponentFactory.ts @@ -81,7 +81,7 @@ export function create(fileName: string, node: ts.Node, checker: ts.TypeChecker) return componentComposites; } -function getModifier(modifiers: ts.NodeArray): Modifier { +function getModifier(modifiers: readonly ts.Modifier[]): Modifier { for (const modifier of modifiers) { if (modifier.kind === ts.SyntaxKind.PrivateKeyword) { return 'private'; @@ -119,7 +119,7 @@ function getOriginalFile(typeSymbol: ts.Symbol, checker: ts.TypeChecker): string deAliasSymbol = typeSymbol; } - return deAliasSymbol.declarations?.[0].getSourceFile().fileName; + return deAliasSymbol.declarations?.[0].getSourceFile().fileName ?? ''; } export function getOriginalFileOriginalType(tsType: ts.Type, checker: ts.TypeChecker): string { @@ -160,7 +160,10 @@ function isTypeParameter(declaration: ts.NamedDeclaration): boolean { } export function getMemberModifier(memberDeclaration: ts.Declaration): Modifier { - const memberModifiers: ts.NodeArray | undefined = memberDeclaration.modifiers; + if (!ts.canHaveModifiers(memberDeclaration)) { + return 'public'; + } + const memberModifiers: readonly ts.Modifier[] | undefined = ts.getModifiers(memberDeclaration); if (memberModifiers === undefined) { return 'public'; @@ -171,7 +174,11 @@ export function getMemberModifier(memberDeclaration: ts.Declaration): Modifier { export function isModifier(memberDeclaration: ts.Declaration, modifierKind: ts.SyntaxKind): boolean { - const memberModifiers: ts.NodeArray | undefined = memberDeclaration.modifiers; + if (!ts.canHaveModifiers(memberDeclaration)) { + return false; + } + + const memberModifiers: readonly ts.Modifier[] | undefined = ts.getModifiers(memberDeclaration); if (memberModifiers !== undefined) { for (const memberModifier of memberModifiers) { diff --git a/src/Factories/MethodFactory.ts b/src/Factories/MethodFactory.ts index 55ab2a7..883ba8e 100644 --- a/src/Factories/MethodFactory.ts +++ b/src/Factories/MethodFactory.ts @@ -23,7 +23,7 @@ export function create(signature: ts.Symbol, namedDeclaration: ts.NamedDeclarati result.typeParameters = methodSignature.typeParameters .map( (typeParameter: ts.TypeParameter) => - TypeParameterFactory.create(typeParameter.symbol, typeParameter.symbol.declarations[0], checker) + TypeParameterFactory.create(typeParameter.symbol, typeParameter.symbol.declarations?.[0], checker) ); } } diff --git a/src/Factories/ParameterFactory.ts b/src/Factories/ParameterFactory.ts index ef6f78f..5849b48 100644 --- a/src/Factories/ParameterFactory.ts +++ b/src/Factories/ParameterFactory.ts @@ -12,6 +12,10 @@ export function create(parameterSymbol: ts.Symbol, checker: ts.TypeChecker): Par declaration = declarations[0]; } + if (parameterSymbol.valueDeclaration === undefined) { + throw new Error("unable to determine parameterType"); + } + const typeOfSymbol: ts.Type = checker.getTypeOfSymbolAtLocation( parameterSymbol, parameterSymbol.valueDeclaration diff --git a/src/Factories/PropertyFactory.ts b/src/Factories/PropertyFactory.ts index 20611c5..08978f9 100644 --- a/src/Factories/PropertyFactory.ts +++ b/src/Factories/PropertyFactory.ts @@ -9,6 +9,11 @@ export function create(signature: ts.Symbol, namedDeclaration: ts.NamedDeclarati result.isOptional = ComponentFactory.isOptional(namedDeclaration); result.isStatic = ComponentFactory.isModifier(namedDeclaration, ts.SyntaxKind.StaticKeyword); result.isReadonly = ComponentFactory.isModifier(namedDeclaration, ts.SyntaxKind.ReadonlyKeyword); + + if (signature.valueDeclaration === undefined) { + throw new Error("unable to determing returnType"); + } + result.returnType = checker.typeToString( checker.getTypeOfSymbolAtLocation( signature, diff --git a/src/Factories/TypeParameterFactory.ts b/src/Factories/TypeParameterFactory.ts index 3dafaf6..022b081 100644 --- a/src/Factories/TypeParameterFactory.ts +++ b/src/Factories/TypeParameterFactory.ts @@ -13,9 +13,13 @@ export function getConstraint(memberDeclaration: ts.Declaration, checker: ts.Typ return checker.getTypeFromTypeNode(effectiveConstraint); } -export function create(signature: ts.Symbol, namedDeclaration: ts.NamedDeclaration, checker: ts.TypeChecker): TypeParameter { +export function create(signature: ts.Symbol, namedDeclaration: ts.NamedDeclaration | undefined, checker: ts.TypeChecker): TypeParameter { const result: TypeParameter = new TypeParameter(signature.getName()); + if (namedDeclaration === undefined) { + return result; + } + const constraintType: ts.Type | undefined = getConstraint(namedDeclaration, checker); if (constraintType !== undefined) {