From b967b361ad7ef409c065d7e1c82b41da396a2c8f Mon Sep 17 00:00:00 2001 From: Andreas Kunz Date: Mon, 22 Apr 2024 21:53:33 +0200 Subject: [PATCH] chore(ts-interface-generator): update dependencies + adapt This is a pure dependency update, but also an adaptation to the overall repo dependency update, where a new major version of prettier was applied, which causes lots of formatting changes (mostly adding trailing commas) in this change. Also, TypeScript was brought in sync to the other parts of the repo. --- packages/ts-interface-generator/package.json | 24 +- .../src/addSourceExports.ts | 2 +- .../src/astGenerationHelper.ts | 380 +++++++++--------- .../ts-interface-generator/src/astToString.ts | 2 +- .../src/collectClassInfo.ts | 12 +- .../src/generateTSInterfacesAPI.ts | 10 +- .../src/interfaceGenerationHelper.ts | 166 ++++---- .../src/jsdocGenerator.ts | 60 +-- .../src/test/generateMethods.test.ts | 4 +- .../test/interfaceGenerationHelper.test.ts | 4 +- .../src/typeScriptEnvironment.ts | 28 +- 11 files changed, 349 insertions(+), 343 deletions(-) diff --git a/packages/ts-interface-generator/package.json b/packages/ts-interface-generator/package.json index aee72863..44a92ced 100644 --- a/packages/ts-interface-generator/package.json +++ b/packages/ts-interface-generator/package.json @@ -34,26 +34,26 @@ "access": "public" }, "devDependencies": { - "@types/hjson": "2.4.3", - "@types/jest": "29.5.4", - "@types/node": "20.5.6", + "@types/hjson": "2.4.6", + "@types/jest": "29.5.12", + "@types/node": "20.12.7", "@types/openui5": "1.117.0", - "@types/yargs": "17.0.24", - "@typescript-eslint/eslint-plugin": "6.4.1", - "@typescript-eslint/parser": "6.4.1", - "eslint": "8.47.0", - "jest": "29.6.4", + "@types/yargs": "17.0.32", + "@typescript-eslint/eslint-plugin": "7.7.0", + "@typescript-eslint/parser": "7.7.0", + "eslint": "8.57.0", + "jest": "29.7.0", "npm-run-all": "4.1.5", - "ts-jest": "29.1.1", - "typescript": "5.2.2" + "ts-jest": "29.1.2", + "typescript": "5.4.5" }, "dependencies": { "hjson": "3.2.2", - "loglevel": "1.8.1", + "loglevel": "1.9.1", "yargs": "17.7.2" }, "peerDependencies": { - "typescript": ">=4.4.3" + "typescript": ">=5.2.0" }, "files": [ "dist" diff --git a/packages/ts-interface-generator/src/addSourceExports.ts b/packages/ts-interface-generator/src/addSourceExports.ts index c029d575..a88cc7b8 100644 --- a/packages/ts-interface-generator/src/addSourceExports.ts +++ b/packages/ts-interface-generator/src/addSourceExports.ts @@ -19,7 +19,7 @@ function addSourceExports( basePath: string, typeChecker: ts.TypeChecker, allPathMappings: { target: string; sourcePattern: string }[], - allExports: GlobalToModuleMapping + allExports: GlobalToModuleMapping, ) { const fileName = sourceFile.fileName; const moduleSymbol = typeChecker.getSymbolAtLocation(sourceFile); diff --git a/packages/ts-interface-generator/src/astGenerationHelper.ts b/packages/ts-interface-generator/src/astGenerationHelper.ts index 8e8e7e75..0843015a 100644 --- a/packages/ts-interface-generator/src/astGenerationHelper.ts +++ b/packages/ts-interface-generator/src/astGenerationHelper.ts @@ -24,7 +24,7 @@ const fixedCreateParameterDeclaration = string | ts.BindingName, ts.QuestionToken?, ts.TypeNode?, - ts.Expression? + ts.Expression?, ] ) { // @ts-ignore old signature before 4.8 is used here @@ -38,7 +38,7 @@ function generateSettingsInterface( settingsTypeFullName: string, requiredImports: RequiredImports, knownGlobals: GlobalToModuleMapping, - eventTypeAliases: { [eventName: string]: ts.TypeAliasDeclaration } + eventTypeAliases: { [eventName: string]: ts.TypeAliasDeclaration }, ) { const interfaceProperties = []; const currentClassName = classInfo.name; @@ -53,14 +53,14 @@ function generateSettingsInterface( property.type, requiredImports, knownGlobals, - currentClassName + currentClassName, ), createTSTypeNode( // 2. a binding info object... "sap.ui.base.ManagedObject.PropertyBindingInfo", requiredImports, knownGlobals, - currentClassName + currentClassName, ), ]; @@ -73,11 +73,11 @@ function generateSettingsInterface( undefined, property.name, factory.createToken(ts.SyntaxKind.QuestionToken), - factory.createUnionTypeNode(propertyTypes) + factory.createUnionTypeNode(propertyTypes), ); addJSDocCommentToNode( propertySignature, - buildJSDocStringFromLines(createJSDocCenterPart(property)) + buildJSDocStringFromLines(createJSDocCenterPart(property)), ); interfaceProperties.push(propertySignature); } @@ -93,7 +93,7 @@ function generateSettingsInterface( aggregation.type, requiredImports, knownGlobals, - currentClassName + currentClassName, ); if (aggregation.cardinality === "0..1") { @@ -108,7 +108,7 @@ function generateSettingsInterface( aggregation.altTypes[0], requiredImports, knownGlobals, - currentClassName + currentClassName, ), ]; typesToUse.push( @@ -117,8 +117,8 @@ function generateSettingsInterface( "sap.ui.base.ManagedObject.PropertyBindingInfo", requiredImports, knownGlobals, - currentClassName - ) + currentClassName, + ), ); if (aggregation.altTypes[0] !== "string") { // if "string" is not anyway allowed, also allow binding strings @@ -140,7 +140,7 @@ function generateSettingsInterface( "sap.ui.base.ManagedObject.AggregationBindingInfo", requiredImports, knownGlobals, - currentClassName + currentClassName, ), createBindingStringTypeNode(), // 4. a binding string ]); @@ -150,11 +150,11 @@ function generateSettingsInterface( undefined, aggregation.name, factory.createToken(ts.SyntaxKind.QuestionToken), - aggregationInitializationTypeNode + aggregationInitializationTypeNode, ); addJSDocCommentToNode( propertySignature, - buildJSDocStringFromLines(createJSDocCenterPart(aggregation)) + buildJSDocStringFromLines(createJSDocCenterPart(aggregation)), ); interfaceProperties.push(propertySignature); } @@ -169,7 +169,7 @@ function generateSettingsInterface( association.type, requiredImports, knownGlobals, - currentClassName + currentClassName, ); // allow object and string (=ID) and in case of multiple associations also arrays @@ -187,7 +187,7 @@ function generateSettingsInterface( factory.createUnionTypeNode([ associationSingleTypeNode, factory.createKeywordTypeNode(ts.SyntaxKind.StringKeyword), - ]) + ]), ), ]); } @@ -196,11 +196,11 @@ function generateSettingsInterface( undefined, association.name, factory.createToken(ts.SyntaxKind.QuestionToken), - associationInitializationTypeNode + associationInitializationTypeNode, ); addJSDocCommentToNode( propertySignature, - buildJSDocStringFromLines(createJSDocCenterPart(association)) + buildJSDocStringFromLines(createJSDocCenterPart(association)), ); factory.createKeywordTypeNode(ts.SyntaxKind.StringKeyword), interfaceProperties.push(propertySignature); @@ -223,15 +223,17 @@ function generateSettingsInterface( undefined, "event", undefined, - factory.createTypeReferenceNode(eventTypeAliases[event.name].name) + factory.createTypeReferenceNode( + eventTypeAliases[event.name].name, + ), ), ], - factory.createKeywordTypeNode(ts.SyntaxKind.VoidKeyword) - ) + factory.createKeywordTypeNode(ts.SyntaxKind.VoidKeyword), + ), ); addJSDocCommentToNode( propertySignature, - buildJSDocStringFromLines(createJSDocCenterPart(event)) + buildJSDocStringFromLines(createJSDocCenterPart(event)), ); interfaceProperties.push(propertySignature); } @@ -247,18 +249,18 @@ function generateSettingsInterface( settingsTypeFullName, requiredImports, knownGlobals, - currentClassName + currentClassName, ); if (!constructorSignaturesAvailable) { printConstructorBlockWarning( ownSettingsTypeName, classInfo.name, - classFileName + classFileName, ); // TODO: only print when the original class is missing the constructors! } else { log.debug( - `Constructor signatures are present in implementation file of ${classInfo.name}.` + `Constructor signatures are present in implementation file of ${classInfo.name}.`, ); } @@ -277,7 +279,7 @@ function generateSettingsInterface( ownSettingsTypeName, undefined, heritageClauses, - interfaceProperties + interfaceProperties, ); } else { myInterface = factory.createInterfaceDeclaration( @@ -287,7 +289,7 @@ function generateSettingsInterface( undefined, heritageClauses, // @ts-ignore: below TS 4.8 there were more params - interfaceProperties + interfaceProperties, ); } @@ -295,7 +297,7 @@ function generateSettingsInterface( ts.addSyntheticLeadingComment( myInterface, ts.SyntaxKind.MultiLineCommentTrivia, - "*\n * Interface defining the settings object used in constructor calls\n " + "*\n * Interface defining the settings object used in constructor calls\n ", ); addLineBreakBefore(myInterface); return myInterface; @@ -308,16 +310,16 @@ function createBindingStringTypeNode() { [ factory.createTemplateLiteralTypeSpan( factory.createKeywordTypeNode(ts.SyntaxKind.StringKeyword), - factory.createTemplateTail("}", "}") + factory.createTemplateTail("}", "}"), ), - ] + ], ); } function printConstructorBlockWarning( settingsTypeName: string, className: string, - fileName: string + fileName: string, ) { const constructorBlock = createConstructorBlock(settingsTypeName); @@ -340,7 +342,7 @@ function addJSDocCommentToNode(node: ts.Node, content: string) { node, ts.SyntaxKind.MultiLineCommentTrivia, "*" + content, - true + true, ); } } @@ -350,7 +352,7 @@ function generateMethods( requiredImports: RequiredImports, knownGlobals: GlobalToModuleMapping, eventParameterInterfaces: { [eventName: string]: ts.InterfaceDeclaration }, - eventTypeAliases: { [eventName: string]: ts.TypeAliasDeclaration } + eventTypeAliases: { [eventName: string]: ts.TypeAliasDeclaration }, ) { const allMethods: ts.MethodSignature[] = []; const currentClassName = classInfo.name; @@ -373,14 +375,14 @@ function generateMethods( property.type, requiredImports, knownGlobals, - currentClassName - ) + currentClassName, + ), ); addLineBreakBefore(getter, 2); ts.addSyntheticLeadingComment( getter, ts.SyntaxKind.SingleLineCommentTrivia, - " property: " + n + " property: " + n, ); addJSDocCommentToNode(getter, classInfo.generatedJSDoc?.PropertyGet[n]); allMethods.push(getter); @@ -401,11 +403,11 @@ function generateMethods( property.type, requiredImports, knownGlobals, - currentClassName - ) + currentClassName, + ), ), ], - factory.createThisTypeNode() + factory.createThisTypeNode(), ); addJSDocCommentToNode(setter, classInfo.generatedJSDoc?.PropertySet[n]); allMethods.push(setter); @@ -427,11 +429,11 @@ function generateMethods( "sap.ui.base.ManagedObject.PropertyBindingInfo", requiredImports, knownGlobals, - currentClassName - ) + currentClassName, + ), ), ], - factory.createThisTypeNode() + factory.createThisTypeNode(), ); addJSDocCommentToNode(bind, classInfo.generatedJSDoc?.PropertyBind[n]); allMethods.push(bind); @@ -443,11 +445,11 @@ function generateMethods( undefined, [], [], - factory.createThisTypeNode() + factory.createThisTypeNode(), ); addJSDocCommentToNode( unbind, - classInfo.generatedJSDoc?.PropertyUnbind[n] + classInfo.generatedJSDoc?.PropertyUnbind[n], ); allMethods.push(unbind); } @@ -473,21 +475,21 @@ function generateMethods( aggregation.type, requiredImports, knownGlobals, - currentClassName - ) + currentClassName, + ), ) : createTSTypeNode( aggregation.type, requiredImports, knownGlobals, - currentClassName - ) + currentClassName, + ), ); addLineBreakBefore(getter, 2); ts.addSyntheticLeadingComment( getter, ts.SyntaxKind.SingleLineCommentTrivia, - " aggregation: " + n + " aggregation: " + n, ); addJSDocCommentToNode(getter, classInfo.generatedJSDoc?.AggregationGet[n]); allMethods.push(getter); @@ -509,11 +511,11 @@ function generateMethods( aggregation.type, requiredImports, knownGlobals, - currentClassName - ) + currentClassName, + ), ), ], - factory.createThisTypeNode() + factory.createThisTypeNode(), ); addJSDocCommentToNode(add, classInfo.generatedJSDoc?.AggregationAdd[n]); allMethods.push(add); @@ -534,22 +536,22 @@ function generateMethods( aggregation.type, requiredImports, knownGlobals, - currentClassName - ) + currentClassName, + ), ), fixedCreateParameterDeclaration( undefined, undefined, "index", undefined, - factory.createKeywordTypeNode(ts.SyntaxKind.NumberKeyword) + factory.createKeywordTypeNode(ts.SyntaxKind.NumberKeyword), ), ], - factory.createThisTypeNode() + factory.createThisTypeNode(), ); addJSDocCommentToNode( insert, - classInfo.generatedJSDoc?.AggregationInsert[n] + classInfo.generatedJSDoc?.AggregationInsert[n], ); allMethods.push(insert); @@ -572,16 +574,16 @@ function generateMethods( aggregation.type, requiredImports, knownGlobals, - currentClassName + currentClassName, ), - ]) + ]), ), ], - factory.createThisTypeNode() + factory.createThisTypeNode(), ); addJSDocCommentToNode( remove, - classInfo.generatedJSDoc?.AggregationRemove[n] + classInfo.generatedJSDoc?.AggregationRemove[n], ); allMethods.push(remove); @@ -597,13 +599,13 @@ function generateMethods( aggregation.type, requiredImports, knownGlobals, - currentClassName - ) - ) + currentClassName, + ), + ), ); addJSDocCommentToNode( removeAll, - classInfo.generatedJSDoc?.AggregationRemoveAll[n] + classInfo.generatedJSDoc?.AggregationRemoveAll[n], ); allMethods.push(removeAll); @@ -623,15 +625,15 @@ function generateMethods( aggregation.type, requiredImports, knownGlobals, - currentClassName - ) + currentClassName, + ), ), ], - factory.createKeywordTypeNode(ts.SyntaxKind.NumberKeyword) + factory.createKeywordTypeNode(ts.SyntaxKind.NumberKeyword), ); addJSDocCommentToNode( indexOf, - classInfo.generatedJSDoc?.AggregationIndexOf[n] + classInfo.generatedJSDoc?.AggregationIndexOf[n], ); allMethods.push(indexOf); @@ -654,11 +656,11 @@ function generateMethods( aggregation.type, requiredImports, knownGlobals, - currentClassName - ) + currentClassName, + ), ), ], - factory.createThisTypeNode() + factory.createThisTypeNode(), ); addJSDocCommentToNode(set, classInfo.generatedJSDoc?.AggregationSet[n]); allMethods.push(set); @@ -671,11 +673,11 @@ function generateMethods( undefined, [], [], - factory.createThisTypeNode() + factory.createThisTypeNode(), ); addJSDocCommentToNode( destroy, - classInfo.generatedJSDoc?.AggregationDestroy[n] + classInfo.generatedJSDoc?.AggregationDestroy[n], ); allMethods.push(destroy); @@ -696,11 +698,11 @@ function generateMethods( "sap.ui.base.ManagedObject.AggregationBindingInfo", requiredImports, knownGlobals, - currentClassName - ) + currentClassName, + ), ), ], - factory.createThisTypeNode() + factory.createThisTypeNode(), ); addJSDocCommentToNode(bind, classInfo.generatedJSDoc?.AggregationBind[n]); allMethods.push(bind); @@ -712,11 +714,11 @@ function generateMethods( undefined, [], [], - factory.createThisTypeNode() + factory.createThisTypeNode(), ); addJSDocCommentToNode( unbind, - classInfo.generatedJSDoc?.AggregationUnbind[n] + classInfo.generatedJSDoc?.AggregationUnbind[n], ); allMethods.push(unbind); } @@ -738,15 +740,15 @@ function generateMethods( [], association.cardinality === "0..n" ? factory.createArrayTypeNode( - factory.createKeywordTypeNode(ts.SyntaxKind.StringKeyword) + factory.createKeywordTypeNode(ts.SyntaxKind.StringKeyword), ) - : factory.createKeywordTypeNode(ts.SyntaxKind.StringKeyword) + : factory.createKeywordTypeNode(ts.SyntaxKind.StringKeyword), ); addLineBreakBefore(getter, 2); ts.addSyntheticLeadingComment( getter, ts.SyntaxKind.SingleLineCommentTrivia, - " association: " + n + " association: " + n, ); addJSDocCommentToNode(getter, classInfo.generatedJSDoc?.AssociationGet[n]); allMethods.push(getter); @@ -771,16 +773,16 @@ function generateMethods( association.type, requiredImports, knownGlobals, - currentClassName + currentClassName, ), - ]) + ]), ), ], - factory.createThisTypeNode() + factory.createThisTypeNode(), ); addJSDocCommentToNode( setter, - classInfo.generatedJSDoc?.AssociationSet[n] + classInfo.generatedJSDoc?.AssociationSet[n], ); allMethods.push(setter); } else { @@ -804,12 +806,12 @@ function generateMethods( association.type, requiredImports, knownGlobals, - currentClassName + currentClassName, ), - ]) + ]), ), ], - factory.createThisTypeNode() + factory.createThisTypeNode(), ); addJSDocCommentToNode(add, classInfo.generatedJSDoc?.AssociationAdd[n]); allMethods.push(add); @@ -833,16 +835,16 @@ function generateMethods( association.type, requiredImports, knownGlobals, - currentClassName + currentClassName, ), - ]) + ]), ), ], - factory.createKeywordTypeNode(ts.SyntaxKind.StringKeyword) + factory.createKeywordTypeNode(ts.SyntaxKind.StringKeyword), ); addJSDocCommentToNode( remove, - classInfo.generatedJSDoc?.AssociationRemove[n] + classInfo.generatedJSDoc?.AssociationRemove[n], ); allMethods.push(remove); @@ -854,12 +856,12 @@ function generateMethods( [], [], factory.createArrayTypeNode( - factory.createKeywordTypeNode(ts.SyntaxKind.StringKeyword) - ) + factory.createKeywordTypeNode(ts.SyntaxKind.StringKeyword), + ), ); addJSDocCommentToNode( removeAll, - classInfo.generatedJSDoc?.AssociationRemoveAll[n] + classInfo.generatedJSDoc?.AssociationRemoveAll[n], ); allMethods.push(removeAll); } @@ -881,10 +883,10 @@ function generateMethods( undefined, "event", undefined, - factory.createTypeReferenceNode(eventTypeAliases[event.name].name) + factory.createTypeReferenceNode(eventTypeAliases[event.name].name), ), ], - factory.createKeywordTypeNode(ts.SyntaxKind.VoidKeyword) + factory.createKeywordTypeNode(ts.SyntaxKind.VoidKeyword), ); const attach = factory.createMethodSignature( undefined, @@ -897,23 +899,23 @@ function generateMethods( undefined, "fn", undefined, - callback + callback, ), fixedCreateParameterDeclaration( undefined, undefined, "listener", factory.createToken(ts.SyntaxKind.QuestionToken), - factory.createKeywordTypeNode(ts.SyntaxKind.ObjectKeyword) + factory.createKeywordTypeNode(ts.SyntaxKind.ObjectKeyword), ), ], - factory.createThisTypeNode() + factory.createThisTypeNode(), ); addLineBreakBefore(attach, 2); ts.addSyntheticLeadingComment( attach, ts.SyntaxKind.SingleLineCommentTrivia, - " event: " + n + " event: " + n, ); addJSDocCommentToNode(attach, classInfo.generatedJSDoc?.EventAttach[n]); allMethods.push(attach); @@ -927,17 +929,17 @@ function generateMethods( undefined, "event", undefined, - factory.createTypeReferenceNode(eventTypeAliases[event.name].name) + factory.createTypeReferenceNode(eventTypeAliases[event.name].name), ), fixedCreateParameterDeclaration( undefined, undefined, "data", undefined, - factory.createTypeReferenceNode("CustomDataType") + factory.createTypeReferenceNode("CustomDataType"), ), ], - factory.createKeywordTypeNode(ts.SyntaxKind.VoidKeyword) + factory.createKeywordTypeNode(ts.SyntaxKind.VoidKeyword), ); const attach2 = factory.createMethodSignature( undefined, @@ -948,12 +950,12 @@ function generateMethods( ? factory.createTypeParameterDeclaration( undefined, "CustomDataType", - factory.createKeywordTypeNode(ts.SyntaxKind.ObjectKeyword) + factory.createKeywordTypeNode(ts.SyntaxKind.ObjectKeyword), ) : factory.createTypeParameterDeclaration( // @ts-ignore this is the old method signature before TS 4.8 "CustomDataType", - factory.createKeywordTypeNode(ts.SyntaxKind.ObjectKeyword) + factory.createKeywordTypeNode(ts.SyntaxKind.ObjectKeyword), ), ], [ @@ -962,28 +964,28 @@ function generateMethods( undefined, "data", undefined, - factory.createTypeReferenceNode("CustomDataType") + factory.createTypeReferenceNode("CustomDataType"), ), fixedCreateParameterDeclaration( undefined, undefined, "fn", undefined, - callbackWithData + callbackWithData, ), fixedCreateParameterDeclaration( undefined, undefined, "listener", factory.createToken(ts.SyntaxKind.QuestionToken), - factory.createKeywordTypeNode(ts.SyntaxKind.ObjectKeyword) + factory.createKeywordTypeNode(ts.SyntaxKind.ObjectKeyword), ), ], - factory.createThisTypeNode() + factory.createThisTypeNode(), ); addJSDocCommentToNode( attach2, - classInfo.generatedJSDoc?.EventAttachWithData[n] + classInfo.generatedJSDoc?.EventAttachWithData[n], ); allMethods.push(attach2); @@ -999,17 +1001,17 @@ function generateMethods( undefined, "fn", undefined, - callback + callback, ), fixedCreateParameterDeclaration( undefined, undefined, "listener", factory.createToken(ts.SyntaxKind.QuestionToken), - factory.createKeywordTypeNode(ts.SyntaxKind.ObjectKeyword) + factory.createKeywordTypeNode(ts.SyntaxKind.ObjectKeyword), ), ], - factory.createThisTypeNode() + factory.createThisTypeNode(), ); addJSDocCommentToNode(detach, classInfo.generatedJSDoc?.EventDetach[n]); allMethods.push(detach); @@ -1032,11 +1034,11 @@ function generateMethods( "parameters", factory.createToken(ts.SyntaxKind.QuestionToken), factory.createTypeReferenceNode( - eventParameterInterfaces[event.name].name - ) + eventParameterInterfaces[event.name].name, + ), ), ], - returnValue + returnValue, ); addJSDocCommentToNode(fire, classInfo.generatedJSDoc?.EventFire[n]); allMethods.push(fire); @@ -1050,7 +1052,7 @@ function createTSTypeNode( requiredImports: RequiredImports, knownGlobals: GlobalToModuleMapping, currentClassName: string, - typeArguments: ts.TypeNode[] = [] + typeArguments: ts.TypeNode[] = [], ): ts.TypeNode { switch (typeName) { case "string": @@ -1058,7 +1060,7 @@ function createTSTypeNode( case "string[]": return factory.createArrayTypeNode( - factory.createKeywordTypeNode(ts.SyntaxKind.StringKeyword) + factory.createKeywordTypeNode(ts.SyntaxKind.StringKeyword), ); case "int": @@ -1068,7 +1070,7 @@ function createTSTypeNode( case "int[]": case "float[]": return factory.createArrayTypeNode( - factory.createKeywordTypeNode(ts.SyntaxKind.NumberKeyword) + factory.createKeywordTypeNode(ts.SyntaxKind.NumberKeyword), ); case "boolean": @@ -1076,7 +1078,7 @@ function createTSTypeNode( case "boolean[]": return factory.createArrayTypeNode( - factory.createKeywordTypeNode(ts.SyntaxKind.BooleanKeyword) + factory.createKeywordTypeNode(ts.SyntaxKind.BooleanKeyword), ); case "object": @@ -1084,17 +1086,17 @@ function createTSTypeNode( case "object[]": return factory.createArrayTypeNode( - factory.createKeywordTypeNode(ts.SyntaxKind.ObjectKeyword) + factory.createKeywordTypeNode(ts.SyntaxKind.ObjectKeyword), ); case "function": return factory.createTypeReferenceNode( - factory.createIdentifier("Function") + factory.createIdentifier("Function"), ); case "function[]": return factory.createArrayTypeNode( - factory.createTypeReferenceNode(factory.createIdentifier("Function")) + factory.createTypeReferenceNode(factory.createIdentifier("Function")), ); case "any": @@ -1102,7 +1104,7 @@ function createTSTypeNode( case "any[]": // a kinda strange type, but to be complete, let's cover it return factory.createArrayTypeNode( - factory.createKeywordTypeNode(ts.SyntaxKind.AnyKeyword) + factory.createKeywordTypeNode(ts.SyntaxKind.AnyKeyword), ); default: @@ -1115,10 +1117,10 @@ function createTSTypeNode( typeName.slice(0, -2).trim(), requiredImports, knownGlobals, - currentClassName + currentClassName, ), - typeArguments - ) + typeArguments, + ), ); } else { // common case: something like "sap.ui.core.CSSSize" @@ -1127,9 +1129,9 @@ function createTSTypeNode( typeName, requiredImports, knownGlobals, - currentClassName + currentClassName, ), - typeArguments + typeArguments, ); } } @@ -1139,7 +1141,7 @@ function uniqueImport( typeName: string, requiredImports: RequiredImports, knownGlobals: GlobalToModuleMapping, - currentClassName: string + currentClassName: string, ) { if (typeName === currentClassName) { // this is the class we are currently dealing with; no import and no name uniqueness check required @@ -1184,7 +1186,7 @@ function uniqueImport( log.warn( `For the type '${typeName}' an import is created with module name '${moduleName}', using its default export. Is this correct? Usually this indicates some kind of issue. Maybe this import will also show up as error in your code editor. -The cause of this could be that the type '${typeName}' is referenced somewhere in Class '${currentClassName}', but is mis-spelled or does actually not exist.` +The cause of this could be that the type '${typeName}' is referenced somewhere in Class '${currentClassName}', but is mis-spelled or does actually not exist.`, ); } } @@ -1211,7 +1213,7 @@ function addLineBreakBefore(node: ts.Node, count = 1) { ts.addSyntheticLeadingComment( node, ts.SyntaxKind.SingleLineCommentTrivia, - "" + "", ); } } @@ -1233,11 +1235,11 @@ function createConstructorBlock(settingsTypeName: string) { factory.createUnionTypeNode([ factory.createKeywordTypeNode(ts.SyntaxKind.StringKeyword), factory.createTypeReferenceNode(settingsTypeName), - ]) + ]), ), ], - undefined - ) + undefined, + ), ); // This creates: @@ -1251,18 +1253,18 @@ function createConstructorBlock(settingsTypeName: string) { undefined, "id", factory.createToken(ts.SyntaxKind.QuestionToken), - factory.createKeywordTypeNode(ts.SyntaxKind.StringKeyword) + factory.createKeywordTypeNode(ts.SyntaxKind.StringKeyword), ), fixedCreateParameterDeclaration( undefined, undefined, "settings", factory.createToken(ts.SyntaxKind.QuestionToken), - factory.createTypeReferenceNode(settingsTypeName) + factory.createTypeReferenceNode(settingsTypeName), ), ], - undefined - ) + undefined, + ), ); // This creates: @@ -1278,14 +1280,14 @@ function createConstructorBlock(settingsTypeName: string) { undefined, "id", factory.createToken(ts.SyntaxKind.QuestionToken), - factory.createKeywordTypeNode(ts.SyntaxKind.StringKeyword) + factory.createKeywordTypeNode(ts.SyntaxKind.StringKeyword), ), fixedCreateParameterDeclaration( undefined, undefined, "settings", factory.createToken(ts.SyntaxKind.QuestionToken), - factory.createTypeReferenceNode(settingsTypeName) + factory.createTypeReferenceNode(settingsTypeName), ), ], factory.createBlock([ @@ -1293,10 +1295,10 @@ function createConstructorBlock(settingsTypeName: string) { factory.createCallExpression(factory.createSuper(), undefined, [ factory.createIdentifier("id"), factory.createIdentifier("settings"), - ]) + ]), ), - ]) - ) + ]), + ), ); return nodes; @@ -1314,7 +1316,7 @@ const makeEventParametersName = (className: string, eventName: string) => { function generateEventWithGenericsCompatibilityModule( className: string, requiredImports: RequiredImports, - knownGlobals: GlobalToModuleMapping + knownGlobals: GlobalToModuleMapping, ) { const typeParameters = [ factory.createTypeParameterDeclaration( @@ -1324,7 +1326,7 @@ function generateEventWithGenericsCompatibilityModule( factory.createKeywordTypeNode(ts.SyntaxKind.StringKeyword), factory.createKeywordTypeNode(ts.SyntaxKind.AnyKeyword), ]), - factory.createKeywordTypeNode(ts.SyntaxKind.ObjectKeyword) + factory.createKeywordTypeNode(ts.SyntaxKind.ObjectKeyword), ), ]; @@ -1341,7 +1343,7 @@ function generateEventWithGenericsCompatibilityModule( factory.createIdentifier("id"), undefined, factory.createKeywordTypeNode(ts.SyntaxKind.StringKeyword), - undefined + undefined, ), fixedCreateParameterDeclaration( undefined, @@ -1352,9 +1354,9 @@ function generateEventWithGenericsCompatibilityModule( "sap.ui.base.EventProvider", requiredImports, knownGlobals, - className + className, ), - undefined + undefined, ), fixedCreateParameterDeclaration( undefined, @@ -1363,12 +1365,12 @@ function generateEventWithGenericsCompatibilityModule( undefined, factory.createTypeReferenceNode( factory.createIdentifier("ParamsType"), - undefined + undefined, ), - undefined + undefined, ), ], - undefined + undefined, ), factory.createMethodSignature( undefined, @@ -1378,8 +1380,8 @@ function generateEventWithGenericsCompatibilityModule( [], factory.createTypeReferenceNode( factory.createIdentifier("ParamsType"), - undefined - ) + undefined, + ), ), factory.createMethodSignature( undefined, @@ -1393,10 +1395,10 @@ function generateEventWithGenericsCompatibilityModule( ts.SyntaxKind.KeyOfKeyword, factory.createTypeReferenceNode( factory.createIdentifier("ParamsType"), - undefined - ) + undefined, + ), ), - undefined + undefined, ), ], [ @@ -1407,21 +1409,21 @@ function generateEventWithGenericsCompatibilityModule( undefined, factory.createTypeReferenceNode( factory.createIdentifier("ParamName"), - undefined + undefined, ), - undefined + undefined, ), ], factory.createIndexedAccessTypeNode( factory.createTypeReferenceNode( factory.createIdentifier("ParamsType"), - undefined + undefined, ), factory.createTypeReferenceNode( factory.createIdentifier("ParamName"), - undefined - ) - ) + undefined, + ), + ), ), ]; @@ -1435,7 +1437,7 @@ function generateEventWithGenericsCompatibilityModule( factory.createIdentifier("Event"), typeParameters, [], - methods + methods, ); } else { interfaceDeclaration = factory.createInterfaceDeclaration( @@ -1448,7 +1450,7 @@ function generateEventWithGenericsCompatibilityModule( typeParameters, [], // @ts-ignore: below TS 4.8 there were more params - methods + methods, ); } @@ -1457,20 +1459,20 @@ function generateEventWithGenericsCompatibilityModule( ? factory.createModuleDeclaration( [factory.createToken(ts.SyntaxKind.DeclareKeyword)], factory.createStringLiteral("sap/ui/base/Event"), - factory.createModuleBlock([interfaceDeclaration]) + factory.createModuleBlock([interfaceDeclaration]), ) : factory.createModuleDeclaration( undefined, // @ts-ignore old signature [factory.createToken(ts.SyntaxKind.DeclareKeyword)], factory.createStringLiteral("sap/ui/base/Event"), - factory.createModuleBlock([interfaceDeclaration]) + factory.createModuleBlock([interfaceDeclaration]), ); ts.addSyntheticLeadingComment( moduleDeclaration, ts.SyntaxKind.SingleLineCommentTrivia, - " This module enhances sap.ui.base.Event with Generics, which is needed in UI5 type definition versions below 1.115" + " This module enhances sap.ui.base.Event with Generics, which is needed in UI5 type definition versions below 1.115", ); return moduleDeclaration; @@ -1482,7 +1484,7 @@ function generateEventParameterInterfaces( }, className: string, requiredImports: RequiredImports, - knownGlobals: GlobalToModuleMapping + knownGlobals: GlobalToModuleMapping, ) { const eventParameterInterfaces: { [eventName: string]: ts.InterfaceDeclaration; @@ -1502,8 +1504,8 @@ function generateEventParameterInterfaces( parameter.type, requiredImports, knownGlobals, - className - ) + className, + ), ); /* TODO: comments for event parameters are not supported yet. From a certain nesting depth, Hjson.parse without comments is used, so they are lost. @@ -1522,23 +1524,23 @@ function generateEventParameterInterfaces( [factory.createToken(ts.SyntaxKind.ExportKeyword)], factory.createIdentifier( makeEventParametersName(className, eventName) - .eventParametersName + .eventParametersName, ), undefined, undefined, - properties + properties, ) : factory.createInterfaceDeclaration( undefined, [factory.createToken(ts.SyntaxKind.ExportKeyword)], factory.createIdentifier( makeEventParametersName(className, eventName) - .eventParametersName + .eventParametersName, ), undefined, undefined, // @ts-ignore: below TS 4.8 there were more params - properties + properties, ); addJSDocCommentToNode( interfc, @@ -1547,15 +1549,15 @@ function generateEventParameterInterfaces( `Interface describing the parameters of ${className}'${ className.endsWith("s") ? "" : "s" } '${eventName}' event.`, - ]) - ) + ]), + ), ); // empty interfaces can cause issues with linting if (properties.length === 0) { ts.addSyntheticLeadingComment( interfc, ts.SyntaxKind.SingleLineCommentTrivia, - " eslint-disable-next-line" + " eslint-disable-next-line", ); } @@ -1571,7 +1573,7 @@ function generateEventTypeAliases( eventParameterInterfaces: { [eventName: string]: ts.InterfaceDeclaration }, className: string, requiredImports: RequiredImports, - knownGlobals: GlobalToModuleMapping + knownGlobals: GlobalToModuleMapping, ) { const eventTypeAliases: { [eventName: string]: ts.TypeAliasDeclaration } = {}; @@ -1584,31 +1586,31 @@ function generateEventTypeAliases( [ factory.createTypeReferenceNode( factory.createIdentifier( - eventParameterInterfaces[eventName].name.text + eventParameterInterfaces[eventName].name.text, ), - undefined + undefined, ), - ] + ], ); const typeAlias = parseFloat(ts.version) >= 4.8 ? factory.createTypeAliasDeclaration( [factory.createToken(ts.SyntaxKind.ExportKeyword)], factory.createIdentifier( - makeEventParametersName(className, eventName).eventTypealiasName + makeEventParametersName(className, eventName).eventTypealiasName, ), undefined, - typeNode + typeNode, ) : factory.createTypeAliasDeclaration( undefined, [factory.createToken(ts.SyntaxKind.ExportKeyword)], factory.createIdentifier( - makeEventParametersName(className, eventName).eventTypealiasName + makeEventParametersName(className, eventName).eventTypealiasName, ), undefined, // @ts-ignore: below TS 4.8 there were more params - typeNode + typeNode, ); addJSDocCommentToNode( typeAlias, @@ -1617,8 +1619,8 @@ function generateEventTypeAliases( `Type describing the ${className}'${ className.endsWith("s") ? "" : "s" } '${eventName}' event.`, - ]) - ) + ]), + ), ); eventTypeAliases[eventName] = typeAlias; diff --git a/packages/ts-interface-generator/src/astToString.ts b/packages/ts-interface-generator/src/astToString.ts index cdb520b5..3c5b457c 100644 --- a/packages/ts-interface-generator/src/astToString.ts +++ b/packages/ts-interface-generator/src/astToString.ts @@ -6,7 +6,7 @@ function astToString(ast: ts.Node[]) { "", ts.ScriptTarget.Latest, false, - ts.ScriptKind.TS + ts.ScriptKind.TS, ); // @ts-ignore this assignment works file.statements = ts.factory.createNodeArray(ast); diff --git a/packages/ts-interface-generator/src/collectClassInfo.ts b/packages/ts-interface-generator/src/collectClassInfo.ts index 27f0230c..517c2d25 100644 --- a/packages/ts-interface-generator/src/collectClassInfo.ts +++ b/packages/ts-interface-generator/src/collectClassInfo.ts @@ -51,7 +51,11 @@ function collectClassInfo(metadata: ClassInfo, className: string) { function each( map: { [key: string]: APIMember }, defaultKey: string, - callback: (n: string, settings: APIMemberType, apiMember: APIMember) => void + callback: ( + n: string, + settings: APIMemberType, + apiMember: APIMember, + ) => void, ) { if (map) { for (const n in map) { @@ -195,7 +199,7 @@ function collectClassInfo(metadata: ClassInfo, className: string) { methods["bind"] = "bind" + N; methods["unbind"] = "unbind" + N; } - } + }, ); each( @@ -228,7 +232,7 @@ function collectClassInfo(metadata: ClassInfo, className: string) { methods["remove"] = "remove" + N1; methods["removeAll"] = "removeAll" + N; } - } + }, ); each(metadata.events, null, (n: string, settings) => { @@ -266,7 +270,7 @@ function collectClassInfo(metadata: ClassInfo, className: string) { experimental: settings.experimental, type: pSettings && pSettings.type ? pSettings.type : "", }; - } + }, ); }); diff --git a/packages/ts-interface-generator/src/generateTSInterfacesAPI.ts b/packages/ts-interface-generator/src/generateTSInterfacesAPI.ts index 3f51f6e8..c570b01c 100644 --- a/packages/ts-interface-generator/src/generateTSInterfacesAPI.ts +++ b/packages/ts-interface-generator/src/generateTSInterfacesAPI.ts @@ -46,14 +46,14 @@ export function main(args: Args) { tsconfig = ts.findConfigFile("./", ts.sys.fileExists, "tsconfig.json"); if (!tsconfig) { throw new Error( - "Could not find a valid 'tsconfig.json'. Please specify it using the '--config' parameter." + "Could not find a valid 'tsconfig.json'. Please specify it using the '--config' parameter.", ); } else { logFound = " (automatically found, as none was given)"; } } log.info( - `Using the following TypeScript configuration file${logFound}: ${tsconfig}` + `Using the following TypeScript configuration file${logFound}: ${tsconfig}`, ); initialize(tsconfig, onTSProgramUpdate, { watchMode }); @@ -76,7 +76,7 @@ function onTSProgramUpdate( program: ts.Program, typeChecker: ts.TypeChecker, changedFiles: string[], // is an empty array in non-watch case; is at least one file in watch case - but overall not reliable! - allKnownGlobals: GlobalToModuleMapping + allKnownGlobals: GlobalToModuleMapping, ) { // this block collects all path mappings from the compiler configuration, so we can find out the logical name for a concrete file path const paths = program.getCompilerOptions().paths; @@ -130,7 +130,7 @@ function onTSProgramUpdate( basePath, typeChecker, allPathMappings, - allKnownLocalExports + allKnownLocalExports, ); // extract all local exports }); @@ -139,7 +139,7 @@ function onTSProgramUpdate( generateInterfaces( sourceFile, typeChecker, - Object.assign(allKnownLocalExports, allKnownGlobals) + Object.assign(allKnownLocalExports, allKnownGlobals), ); // don't modify the ambient globals here, as they might have a different lifecycle and we don't want to keep adding the same properties again }); } diff --git a/packages/ts-interface-generator/src/interfaceGenerationHelper.ts b/packages/ts-interface-generator/src/interfaceGenerationHelper.ts index cd266bde..2a935a66 100644 --- a/packages/ts-interface-generator/src/interfaceGenerationHelper.ts +++ b/packages/ts-interface-generator/src/interfaceGenerationHelper.ts @@ -24,7 +24,7 @@ let ManagedObjectSymbol: ts.Symbol, WebComponentSymbol: ts.Symbol; function interestingBaseClassForSymbol( typeChecker: ts.TypeChecker, - symbol: ts.Symbol + symbol: ts.Symbol, ): "ManagedObject" | "Element" | "Control" | "WebComponent" | undefined { if (!ManagedObjectSymbol) { // cache - TODO: needs to be refreshed when the UI5 type definitions are updated during a run of the tool! @@ -36,10 +36,10 @@ function interestingBaseClassForSymbol( const managedObjectClassDeclaration = ( managedObjectModuleDeclaration?.body as ts.ModuleBlock )?.statements.filter( - (s) => ts.isClassDeclaration(s) && s.name?.text === "ManagedObject" + (s) => ts.isClassDeclaration(s) && s.name?.text === "ManagedObject", )[0] as ts.ClassDeclaration; ManagedObjectSymbol = typeChecker.getSymbolAtLocation( - managedObjectClassDeclaration?.name + managedObjectClassDeclaration?.name, ); const elementModuleDeclaration = typeChecker @@ -49,10 +49,10 @@ function interestingBaseClassForSymbol( const elementClassDeclaration = ( elementModuleDeclaration?.body as ts.ModuleBlock )?.statements.filter( - (s) => ts.isClassDeclaration(s) && s.name?.text === "UI5Element" + (s) => ts.isClassDeclaration(s) && s.name?.text === "UI5Element", )[0] as ts.ClassDeclaration; ElementSymbol = typeChecker.getSymbolAtLocation( - elementClassDeclaration?.name + elementClassDeclaration?.name, ); const controlModuleDeclaration = typeChecker @@ -62,10 +62,10 @@ function interestingBaseClassForSymbol( const controlClassDeclaration = ( controlModuleDeclaration?.body as ts.ModuleBlock )?.statements.filter( - (s) => ts.isClassDeclaration(s) && s.name?.text === "Control" + (s) => ts.isClassDeclaration(s) && s.name?.text === "Control", )[0] as ts.ClassDeclaration; ControlSymbol = typeChecker.getSymbolAtLocation( - controlClassDeclaration?.name + controlClassDeclaration?.name, ); const webComponentModuleDeclaration = typeChecker @@ -75,10 +75,10 @@ function interestingBaseClassForSymbol( const webComponentClassDeclaration = ( webComponentModuleDeclaration?.body as ts.ModuleBlock )?.statements.filter( - (s) => ts.isClassDeclaration(s) && s.name?.text === "WebComponent" + (s) => ts.isClassDeclaration(s) && s.name?.text === "WebComponent", )[0] as ts.ClassDeclaration; WebComponentSymbol = typeChecker.getSymbolAtLocation( - webComponentClassDeclaration?.name + webComponentClassDeclaration?.name, ); } if (symbol === ControlSymbol) { @@ -129,8 +129,8 @@ function generateInterfaces( resultProcessor: ( sourceFileName: string, className: string, - interfaceText: string - ) => void = writeInterfaceFile + interfaceText: string, + ) => void = writeInterfaceFile, ) { const mos = getManagedObjects(sourceFile, typeChecker); @@ -150,13 +150,13 @@ function generateInterfaces( const interfaceText = generateInterface( managedObjectOccurrence, allKnownGlobals, - { generateEventWithGenerics: !isEventGeneric } + { generateEventWithGenerics: !isEventGeneric }, ); // only returns the interface text if actually needed (it's not for ManagedObjects without metadata etc.) if (interfaceText) { resultProcessor( sourceFile.fileName, managedObjectOccurrence.className, - interfaceText + interfaceText, ); } }); @@ -171,7 +171,7 @@ function generateInterfaces( function writeInterfaceFile( sourceFileName: string, className: string, - interfaceText: string + interfaceText: string, ) { // file output const pathName = path.dirname(sourceFileName); @@ -182,7 +182,7 @@ function writeInterfaceFile( function getManagedObjects( sourceFile: ts.SourceFile, - typeChecker: ts.TypeChecker + typeChecker: ts.TypeChecker, ) { const managedObjects: ManagedObjectInfo[] = []; sourceFile.statements.forEach((statement) => { @@ -205,14 +205,14 @@ If a working "import" is not possible and it is a UI5 type (or type from another 2. Check inside which "node_modules" folder the types are actually available - if they are not, check whether "npm install" (or "yarn" etc.) has run successfully - maybe re-run it 3. Check the "tsconfig.json" file: types outside the default "@types" package must be explicitly added in the "types" or "typeRoots" section. Is the name and path correct? One known cause of this error is that the "typeRoots" setting in tsconfig.json has wrong paths, which are not actually pointing to the correct location of the type definitions. -Or is there a different reason why this type would not be known?` +Or is there a different reason why this type would not be known?`, ); } // now check whether this type from which has been inherited is a ManagedObject const interestingBaseClass = getInterestingBaseClass( type, - typeChecker + typeChecker, ); if (!interestingBaseClass) { return; @@ -241,7 +241,7 @@ Or is there a different reason why this type would not be known?` log.debug( `Class ${statement.name ? statement.name.text : ""} in ${ sourceFile.fileName - } inherits from ${interestingBaseClass} but has no metadata. This is not necessarily an issue, but if there is a metadata member in this class which *should* be recognized, make sure it has the 'static' keyword!` + } inherits from ${interestingBaseClass} but has no metadata. This is not necessarily an issue, but if there is a metadata member in this class which *should* be recognized, make sure it has the 'static' keyword!`, ); return; } else if (metadata.length > 1) { @@ -253,7 +253,7 @@ Or is there a different reason why this type would not be known?` statement.name ? statement.name.text : "" } inside ${ sourceFile.fileName - }. This is unexpected. Ignoring this class.` + }. This is unexpected. Ignoring this class.`, ); return; } else if (!metadata[0].initializer) { @@ -264,7 +264,7 @@ Or is there a different reason why this type would not be known?` log.warn( `Inside file ${sourceFile.fileName}${ statement.name ? " in class " + statement.name.text : "" - } there is a metadata declaration without a value. Did you accidentally write "metadata: ..." instead of "metadata = ..."?` + } there is a metadata declaration without a value. Did you accidentally write "metadata: ..." instead of "metadata = ..."?`, ); return; } @@ -286,10 +286,10 @@ Or is there a different reason why this type would not be known?` const settingsTypeSourceFile = settingsTypeDeclaration.getSourceFile().fileName; const settingsTypeDirectory = path.dirname( - settingsTypeSourceFile + settingsTypeSourceFile, ); const managedObjectDirectory = path.dirname( - sourceFile.fileName + sourceFile.fileName, ); if (managedObjectDirectory !== settingsTypeDirectory) { // settings type of superclass is in different directory, hence the generated import will have to traverse to that directory @@ -297,7 +297,7 @@ Or is there a different reason why this type would not be known?` .relative(managedObjectDirectory, settingsTypeDirectory) .replace(/\\/, "/"); const match = settingsTypeFullName.match( - /".\/([^/]+\/)*([^/]+)".*/ + /".\/([^/]+\/)*([^/]+)".*/, ); if (match) { // insert the relative path @@ -311,7 +311,7 @@ Or is there a different reason why this type would not be known?` `${ statement.name ? statement.name.text : "" } inherits from ${interestingBaseClass} and has metadata but the parent class ${typeChecker.getFullyQualifiedName( - type.getSymbol() + type.getSymbol(), )} seems to have no settings type. It might have no constructors, this is where the settings type is used. Or the settings type used there and its inheritance chain could not be resolved. In case this parent class is also in your project, make sure to add its constructors, then try again. A comment with instructions might be in the console output above. @@ -319,9 +319,9 @@ Otherwise, you can temporarily remove this file (${ sourceFile.fileName }) from the project and try again to get the console output with the suggested constructors. In any case, you need to make the parent class ${typeChecker.getFullyQualifiedName( - type.getSymbol() + type.getSymbol(), )} have constructors with typed settings object to overcome this issue. -` +`, ); } @@ -366,7 +366,7 @@ function checkConstructors(classDeclaration: ts.ClassDeclaration) { if ( isOneAStringAndTheOtherASettingsObject( parameter.type.types[0], - parameter.type.types[1] + parameter.type.types[1], ) ) { singleParameterDeclarationFound = true; @@ -377,7 +377,7 @@ function checkConstructors(classDeclaration: ts.ClassDeclaration) { if ( isOneAStringAndTheOtherASettingsObject( member.parameters[0].type, - member.parameters[1].type + member.parameters[1].type, ) ) { if (member.body) { @@ -388,7 +388,7 @@ function checkConstructors(classDeclaration: ts.ClassDeclaration) { } } else { log.warn( - `Unexpected constructor signature with a parameter number other than 1 or 2 in class ${member.parent.name.text}` + `Unexpected constructor signature with a parameter number other than 1 or 2 in class ${member.parent.name.text}`, ); } } @@ -410,7 +410,7 @@ function checkConstructors(classDeclaration: ts.ClassDeclaration) { : "\n- constructor declaration with two parameters") + (implementationFound ? "" - : "\n- constructor implementation with two parameters") + : "\n- constructor implementation with two parameters"), ); } return found; @@ -418,7 +418,7 @@ function checkConstructors(classDeclaration: ts.ClassDeclaration) { function isOneAStringAndTheOtherASettingsObject( type1: ts.TypeNode, - type2: ts.TypeNode + type2: ts.TypeNode, ) { return ( (type1.kind === ts.SyntaxKind.StringKeyword && @@ -441,7 +441,7 @@ function getSettingsType(type: ts.Type, typeChecker: ts.TypeChecker) { if (ts.isConstructorDeclaration(members[j])) { const settingsType = getSettingsTypeFromConstructor( members[j] as ts.ConstructorDeclaration, - typeChecker + typeChecker, ); if (settingsType) { return settingsType; @@ -457,7 +457,7 @@ function getSettingsType(type: ts.Type, typeChecker: ts.TypeChecker) { */ function getSettingsTypeFromConstructor( ctor: ts.ConstructorDeclaration, - typeChecker: ts.TypeChecker + typeChecker: ts.TypeChecker, ) { for (let i = 0; i < ctor.parameters.length; i++) { const parameter = ctor.parameters[i]; @@ -466,14 +466,14 @@ function getSettingsTypeFromConstructor( log.debug( `Checking constructor parameter ${parameter.name.getText()} (type ${( parameter.type as ts.TypeReferenceNode - ).typeName.getText()}) to find out whether it is the settings type of the base class.` + ).typeName.getText()}) to find out whether it is the settings type of the base class.`, ); const potentialSettingsType = typeChecker.getTypeFromTypeNode( - parameter.type + parameter.type, ); const interestingBaseSettingsClass = getInterestingBaseSettingsClass( potentialSettingsType, - typeChecker + typeChecker, ); if (interestingBaseSettingsClass) { return parameter.type; @@ -487,14 +487,14 @@ function getSettingsTypeFromConstructor( */ function getInterestingBaseClass( type: ts.Type, - typeChecker: ts.TypeChecker + typeChecker: ts.TypeChecker, ): "ManagedObject" | "Element" | "Control" | "WebComponent" | undefined { //const typeName = typeChecker.typeToString(type); //log.debug("-> " + typeName + " (" + typeChecker.getFullyQualifiedName(type.getSymbol()) + ")"); let interestingBaseClass = interestingBaseClassForSymbol( typeChecker, - type.getSymbol() + type.getSymbol(), ); if (interestingBaseClass) { return interestingBaseClass; @@ -507,7 +507,7 @@ function getInterestingBaseClass( if ( (interestingBaseClass = getInterestingBaseClass( baseTypes[i], - typeChecker + typeChecker, )) ) { return interestingBaseClass; @@ -521,7 +521,7 @@ function getInterestingBaseClass( */ function getInterestingBaseSettingsClass( type: ts.Type, - typeChecker: ts.TypeChecker + typeChecker: ts.TypeChecker, ): | "$ManagedObjectSettings" | "$ElementSettings" @@ -551,14 +551,14 @@ function getInterestingBaseSettingsClass( type.symbol.escapedName ) { console.warn( - `TypeScript could not resolve any base types for ${type.symbol.escapedName.toString()}.` + `TypeScript could not resolve any base types for ${type.symbol.escapedName.toString()}.`, ); } for (let i = 0; i < baseTypes.length; i++) { if ( (interestingBaseSettingsClass = getInterestingBaseSettingsClass( baseTypes[i], - typeChecker + typeChecker, )) ) { return interestingBaseSettingsClass; @@ -571,7 +571,7 @@ function getInterestingBaseSettingsClass( function getTagsWithName( jsDocs: ReadonlyArray, - tagName: string + tagName: string, ) { const fnCheck = tagName === "deprecated" ? ts.isJSDocDeprecatedTag : ts.isJSDocUnknownTag; @@ -626,7 +626,7 @@ function extractJSDoc(jsDocs: (ts.JSDoc | ts.JSDocTag)[]) { // for a single definition in the metadata (a single property, a single aggregation, ...), this method extracts all needed info into the returned APIMember instance function getMemberFromPropertyAssignment( propertyAssignment: ts.PropertyAssignment, - memberKind: T + memberKind: T, ): TypeForMetadataSectionName[T] { // the name const memberName = propertyAssignment.name.getText().replace(/['"]/g, ""); @@ -638,11 +638,11 @@ function getMemberFromPropertyAssignment( let definitionObject; try { definitionObject = Hjson.parse( - propertyAssignment.initializer.getText() + propertyAssignment.initializer.getText(), ) as APIMember; // parse with some fault tolerance: it's not a real JSON object, but JS code which may contain comments and property names which are not enclosed in double quotes definitionObject = expandDefaultKey( definitionObject, - memberKind === "events" ? null : "type" + memberKind === "events" ? null : "type", ); Object.assign(member, definitionObject); } catch (e) { @@ -651,13 +651,13 @@ function getMemberFromPropertyAssignment( member.name }: metadata is no valid JSON and could not be quick-fixed to be. Please make the metadata at least close to valid JSON. In particular, TypeScript type annotations cannot be used. Error: ${ (e as Error).message - }` + }`, ); } // need to type this yet undocumented method type GetJSDocCommentsAndTags = ( - pa: ts.PropertyAssignment + pa: ts.PropertyAssignment, ) => (ts.JSDoc | ts.JSDocTag)[]; // enrich with JSDoc @@ -665,7 +665,7 @@ function getMemberFromPropertyAssignment( const commentsAndTags = // @ts-ignore this method already exists in 5.0.4, but was only made public two weeks ago, maybe for 5.1 (https://github.com/microsoft/TypeScript/commit/a1df8f774fd81c389a10d2e44a3568d7f0647c67) (ts.getJSDocCommentsAndTags as GetJSDocCommentsAndTags)( - propertyAssignment + propertyAssignment, ); Object.assign(member, extractJSDoc(commentsAndTags)); } @@ -694,7 +694,7 @@ function generateInterface( metadata: ts.PropertyDeclaration[]; }, allKnownGlobals: GlobalToModuleMapping, - options: { generateEventWithGenerics: boolean } + options: { generateEventWithGenerics: boolean }, ) { const fileName = sourceFile.fileName; @@ -714,7 +714,7 @@ function generateInterface( .replace(/['"]/g, "") as MetadataSectionName; if ( !["properties", "aggregations", "associations", "events"].includes( - memberKind + memberKind, ) ) { return; // not interested in anything else than these four, because methods are generated only for these @@ -733,7 +733,7 @@ function generateInterface( const name = prop.name.getText().replace(/['"]/g, ""); metadataObject[memberKind][name] = getMemberFromPropertyAssignment( prop as ts.PropertyAssignment, - memberKind + memberKind, ); }); // cast ensured to be valid by the line above } @@ -742,7 +742,7 @@ function generateInterface( throw new Error( `When parsing the metadata of ${className} in ${fileName}: ${ (e as Error).message - }` + }`, ); } }); @@ -758,7 +758,7 @@ function generateInterface( } log.debug( - `\n\nClass ${className} inside ${fileName} inherits from ${interestingBaseClass} and contains metadata.` + `\n\nClass ${className} inside ${fileName} inherits from ${interestingBaseClass} and contains metadata.`, ); const classInfo = collectClassInfo(metadataObject, className); @@ -771,7 +771,7 @@ function generateInterface( moduleName, settingsTypeFullName, allKnownGlobals, - options + options, ); if (!ast) { // no interface needs to be generated @@ -788,7 +788,7 @@ function buildAST( moduleName: string, settingsTypeFullName: string, allKnownGlobals: GlobalToModuleMapping, - options?: { generateEventWithGenerics?: boolean } + options?: { generateEventWithGenerics?: boolean }, ) { const requiredImports: RequiredImports = {}; @@ -799,7 +799,7 @@ function buildAST( classInfo.events, classInfo.name, requiredImports, - allKnownGlobals + allKnownGlobals, ); let genericEventDefinitionModule; if ( @@ -809,7 +809,7 @@ function buildAST( genericEventDefinitionModule = generateEventWithGenericsCompatibilityModule( classInfo.name, requiredImports, - allKnownGlobals + allKnownGlobals, ); } @@ -818,7 +818,7 @@ function buildAST( eventParameterInterfaces, classInfo.name, requiredImports, - allKnownGlobals + allKnownGlobals, ); const methods = generateMethods( @@ -826,7 +826,7 @@ function buildAST( requiredImports, allKnownGlobals, eventParameterInterfaces, - eventTypeAliases + eventTypeAliases, ); if (methods.length === 0) { // nothing needs to be generated! @@ -840,7 +840,7 @@ function buildAST( settingsTypeFullName, requiredImports, allKnownGlobals, - eventTypeAliases + eventTypeAliases, ); const statements: ts.Statement[] = getImports(requiredImports); @@ -855,7 +855,7 @@ function buildAST( classInfo.name, undefined, undefined, - methods + methods, ); } else { myInterface = factory.createInterfaceDeclaration( @@ -868,7 +868,7 @@ function buildAST( undefined, undefined, // @ts-ignore: below TS 4.8 there were more params - methods + methods, ); } addLineBreakBefore(myInterface, 2); @@ -884,7 +884,7 @@ function buildAST( myInterface, ...Object.values(eventParameterInterfaces), ...Object.values(eventTypeAliases), - ]) + ]), ); } else { module = factory.createModuleDeclaration( @@ -897,7 +897,7 @@ function buildAST( myInterface, ...Object.values(eventParameterInterfaces), ...Object.values(eventTypeAliases), - ]) + ]), ); } if (statements.length > 0) { @@ -919,7 +919,7 @@ function buildAST( classInfo.name, undefined, undefined, - methods + methods, ); } else { myInterface2 = factory.createInterfaceDeclaration( @@ -929,7 +929,7 @@ function buildAST( undefined, undefined, // @ts-ignore: below TS 4.8 there were more params - methods + methods, ); } @@ -938,7 +938,7 @@ function buildAST( module2 = factory.createModuleDeclaration( [factory.createModifier(ts.SyntaxKind.DeclareKeyword)], factory.createStringLiteral("./" + moduleName), - factory.createModuleBlock([myInterface2]) + factory.createModuleBlock([myInterface2]), ); } else { module2 = factory.createModuleDeclaration( @@ -946,7 +946,7 @@ function buildAST( // @ts-ignore old signature [factory.createModifier(ts.SyntaxKind.DeclareKeyword)], factory.createStringLiteral("./" + moduleName), - factory.createModuleBlock([myInterface2]) + factory.createModuleBlock([myInterface2]), ); } addLineBreakBefore(module2, 2); @@ -955,7 +955,7 @@ function buildAST( ts.SyntaxKind.SingleLineCommentTrivia, " this duplicate interface without export is needed to avoid \"Cannot find name '" + classInfo.name + - "'\" TypeScript errors above" + "'\" TypeScript errors above", ); statements.push(module2); @@ -972,7 +972,7 @@ function getImports(requiredImports: RequiredImports) { } const singleImport = requiredImports[dependencyName]; const localNameIdentifier = factory.createIdentifier( - singleImport.localName + singleImport.localName, ); const namedImportOriginalNameIdentifier = singleImport.exportName && @@ -990,25 +990,25 @@ function getImports(requiredImports: RequiredImports) { false /* typeOnly */, namedImportOriginalNameIdentifier, // @ts-ignore after 4.5, createImportSpecifier got a third parameter (in the beginning!). This code shall work with older and newer versions, but as the compile-time error check is considering either <4.5 or >=4.5, one of these lines is recognized as error - localNameIdentifier + localNameIdentifier, ); } else { // @ts-ignore after 4.5, createImportSpecifier got a third parameter (in the beginning!). This code shall work with older and newer versions, but as the compile-time error check is considering either <4.5 or >=4.5, one of these lines is recognized as error importSpecifier = factory.createImportSpecifier( namedImportOriginalNameIdentifier, - localNameIdentifier + localNameIdentifier, ); } importClause = factory.createImportClause( false, undefined, - factory.createNamedImports([importSpecifier]) + factory.createNamedImports([importSpecifier]), ); } else { importClause = factory.createImportClause( false, factory.createIdentifier(singleImport.localName), - undefined + undefined, ); // importing the default export, so only the local name matters } @@ -1017,15 +1017,15 @@ function getImports(requiredImports: RequiredImports) { ? factory.createImportDeclaration( undefined, importClause, - factory.createStringLiteral(singleImport.moduleName) + factory.createStringLiteral(singleImport.moduleName), ) : factory.createImportDeclaration( undefined, undefined, // @ts-ignore old signature before 4.8 importClause, - factory.createStringLiteral(singleImport.moduleName) - ) + factory.createStringLiteral(singleImport.moduleName), + ), ); } @@ -1038,9 +1038,9 @@ function getImports(requiredImports: RequiredImports) { factory.createImportClause( false, factory.createIdentifier("Core"), - undefined + undefined, ), - factory.createStringLiteral("sap/ui/core/Core") + factory.createStringLiteral("sap/ui/core/Core"), ); } else { importDeclaration = factory.createImportDeclaration( @@ -1050,15 +1050,15 @@ function getImports(requiredImports: RequiredImports) { factory.createImportClause( false, factory.createIdentifier("Core"), - undefined + undefined, ), - factory.createStringLiteral("sap/ui/core/Core") + factory.createStringLiteral("sap/ui/core/Core"), ); } ts.addSyntheticTrailingComment( importDeclaration, ts.SyntaxKind.SingleLineCommentTrivia, - " dummy import to make this non-ambient" + " dummy import to make this non-ambient", ); imports.push(importDeclaration); } diff --git a/packages/ts-interface-generator/src/jsdocGenerator.ts b/packages/ts-interface-generator/src/jsdocGenerator.ts index 0b19f301..80d92744 100644 --- a/packages/ts-interface-generator/src/jsdocGenerator.ts +++ b/packages/ts-interface-generator/src/jsdocGenerator.ts @@ -91,7 +91,7 @@ export function addJSDoc(oClassInfo: ClassInfo) { propertyName: string, info: APIMember, lines: string[], - suffixLines: string[] + suffixLines: string[], ) { if (!oClassInfo.generatedJSDoc[methodType]) { oClassInfo.generatedJSDoc[methodType] = {}; @@ -118,7 +118,7 @@ export function addJSDoc(oClassInfo: ClassInfo) { n: string, type: string, description: string, - defaultValue: string + defaultValue: string, ) { let s = "@param "; @@ -149,7 +149,7 @@ export function addJSDoc(oClassInfo: ClassInfo) { ? "Default value is: " + JSON.stringify(info.defaultValue) : "", '@returns Value of property "' + n + '"', - ] + ], ); newJSDoc( MethodType.PropertySet, @@ -166,10 +166,10 @@ export function addJSDoc(oClassInfo: ClassInfo) { n, info.type, 'New value for property "' + n + '"', - info.defaultValue as string + info.defaultValue as string, ), '@returns Reference to "this" in order to allow method chaining', - ] + ], ); if (info.bindable) { newJSDoc( @@ -182,14 +182,14 @@ export function addJSDoc(oClassInfo: ClassInfo) { 'detailed description of the possible properties of "oBindingInfo"', "@param oBindingInfo The binding information", '@returns Reference to "this" in order to allow method chaining', - ] + ], ); newJSDoc( MethodType.PropertyUnbind, n, info, ['Unbinds property "' + n + '" from model data.'], - ['@returns Reference to "this" in order to allow method chaining'] + ['@returns Reference to "this" in order to allow method chaining'], ); } } @@ -211,7 +211,7 @@ export function addJSDoc(oClassInfo: ClassInfo) { ], [ // TODO: @returns missing?!? - ] + ], ); if (info.cardinality == "0..n") { const n1 = info.singularName; @@ -237,7 +237,7 @@ export function addJSDoc(oClassInfo: ClassInfo) { " is inserted at", " the last position", '@returns Reference to "this" in order to allow method chaining', - ] + ], ); newJSDoc( MethodType.AggregationAdd, @@ -251,7 +251,7 @@ export function addJSDoc(oClassInfo: ClassInfo) { n1 + " to add; if empty, nothing is inserted", '@returns Reference to "this" in order to allow method chaining', - ] + ], ); newJSDoc( MethodType.AggregationRemove, @@ -261,7 +261,7 @@ export function addJSDoc(oClassInfo: ClassInfo) { [ "@param " + n1 + " The " + n1 + " to remove or its index or id", "@returns The removed " + n1 + ' or "null"', - ] + ], ); newJSDoc( MethodType.AggregationRemoveAll, @@ -271,7 +271,7 @@ export function addJSDoc(oClassInfo: ClassInfo) { 'Removes all the controls from the aggregation "' + n + '".', "Additionally, it unregisters them from the hosting UIArea.", ], - ["@returns An array of the removed elements (might be empty)"] + ["@returns An array of the removed elements (might be empty)"], ); newJSDoc( MethodType.AggregationIndexOf, @@ -288,7 +288,7 @@ export function addJSDoc(oClassInfo: ClassInfo) { [ "@param " + n1 + " The " + n1 + " whose index is looked for", "@returns The index of the provided control in the aggregation if found, or -1 otherwise", - ] + ], ); } else { newJSDoc( @@ -299,7 +299,7 @@ export function addJSDoc(oClassInfo: ClassInfo) { [ "@param " + n + " The " + n + " to set", '@returns Reference to "this" in order to allow method chaining', - ] + ], ); } newJSDoc( @@ -315,7 +315,7 @@ export function addJSDoc(oClassInfo: ClassInfo) { n + '".', ], - ['@returns Reference to "this" in order to allow method chaining'] + ['@returns Reference to "this" in order to allow method chaining'], ); if (info.bindable) { newJSDoc( @@ -328,14 +328,14 @@ export function addJSDoc(oClassInfo: ClassInfo) { 'detailed description of the possible properties of "oBindingInfo".', "@param oBindingInfo The binding information", '@returns Reference to "this" in order to allow method chaining', - ] + ], ); newJSDoc( MethodType.AggregationUnbind, n, info, ['Unbinds aggregation "' + n + '" from model data.'], - ['@returns Reference to "this" in order to allow method chaining'] + ['@returns Reference to "this" in order to allow method chaining'], ); } } @@ -358,7 +358,7 @@ export function addJSDoc(oClassInfo: ClassInfo) { n + '", or "null".', ], - [] + [], ); if (info.cardinality === "0..n") { const n1 = info.singularName; @@ -374,7 +374,7 @@ export function addJSDoc(oClassInfo: ClassInfo) { n + " to add; if empty, nothing is inserted", '@returns Reference to "this" in order to allow method chaining', - ] + ], ); newJSDoc( MethodType.AssociationRemove, @@ -384,14 +384,14 @@ export function addJSDoc(oClassInfo: ClassInfo) { [ "@param " + n1 + " The " + n1 + " to be removed or its index or ID", "@returns The removed " + n1 + ' or "null"', - ] + ], ); newJSDoc( MethodType.AssociationRemoveAll, n, info, ["Removes all the controls in the association named " + n + "."], - ["@returns An array of the removed elements (might be empty)"] + ["@returns An array of the removed elements (might be empty)"], ); } else { newJSDoc( @@ -406,7 +406,7 @@ export function addJSDoc(oClassInfo: ClassInfo) { n + '" association; alternatively, an element instance may be given', '@returns Reference to "this" in order to allow method chaining', - ] + ], ); } } @@ -436,7 +436,7 @@ export function addJSDoc(oClassInfo: ClassInfo) { "@param oControlEvent.getParameters." + pName + " " + - (info.parameters[pName].doc || "") + (info.parameters[pName].doc || ""), ); } //newJSDoc(lines); // TODO @@ -462,7 +462,7 @@ export function addJSDoc(oClassInfo: ClassInfo) { '" itself', "", '@returns Reference to "this" in order to allow method chaining', - ] + ], ); newJSDoc( MethodType.EventAttachWithData, @@ -486,7 +486,7 @@ export function addJSDoc(oClassInfo: ClassInfo) { '" itself', "", '@returns Reference to "this" in order to allow method chaining', - ] + ], ); newJSDoc( MethodType.EventDetach, @@ -508,7 +508,7 @@ export function addJSDoc(oClassInfo: ClassInfo) { info.since ? "@since " + info.since : "", info.deprecation ? "@deprecated " + info.deprecation : "", info.experimental ? "@experimental " + info.experimental : "", - ] + ], ); // build documentation for fireEvent. It contains conditional parts which makes it a bit more complicated @@ -519,12 +519,12 @@ export function addJSDoc(oClassInfo: ClassInfo) { "", 'Listeners may prevent the default action of this event by calling the "preventDefault" method on the event object.', "The return value of this method indicates whether the default action should be executed.", - "" + "", ); } suffixLines.push( "", - "@param parameters Parameters to pass along with the event" + "@param parameters Parameters to pass along with the event", ); if (!isEmpty(info.parameters)) { for (const pName in info.parameters) { @@ -532,7 +532,7 @@ export function addJSDoc(oClassInfo: ClassInfo) { "@param [mParameters." + pName + "] " + - (info.parameters[pName].doc || "") + (info.parameters[pName].doc || ""), ); } suffixLines.push(""); @@ -541,7 +541,7 @@ export function addJSDoc(oClassInfo: ClassInfo) { suffixLines.push("@returns Whether or not to prevent the default action"); } else { suffixLines.push( - '@returns Reference to "this" in order to allow method chaining' + '@returns Reference to "this" in order to allow method chaining', ); } newJSDoc(MethodType.EventFire, n, info, lines, suffixLines); diff --git a/packages/ts-interface-generator/src/test/generateMethods.test.ts b/packages/ts-interface-generator/src/test/generateMethods.test.ts index 00bc8201..86f19002 100644 --- a/packages/ts-interface-generator/src/test/generateMethods.test.ts +++ b/packages/ts-interface-generator/src/test/generateMethods.test.ts @@ -27,7 +27,7 @@ setText(text: string): this;`; requiredImports, knownGlobals, {}, - {} + {}, ); const interfaceText = astToString(methods); @@ -82,7 +82,7 @@ unbindContent(): this;`; requiredImports, knownGlobals, {}, - {} + {}, ); const interfaceText = astToString(methods); diff --git a/packages/ts-interface-generator/src/test/interfaceGenerationHelper.test.ts b/packages/ts-interface-generator/src/test/interfaceGenerationHelper.test.ts index a57de0a8..6ba9a3b0 100644 --- a/packages/ts-interface-generator/src/test/interfaceGenerationHelper.test.ts +++ b/packages/ts-interface-generator/src/test/interfaceGenerationHelper.test.ts @@ -8,7 +8,7 @@ function onTSProgramUpdate( changedFiles: string[], // is an empty array in non-watch case; is at least one file in watch case allKnownGlobals: { [key: string]: { moduleName: string; exportName?: string }; - } + }, ) { // files recognized as "real" app source files should be exactly one: SampleControl.ts const sourceFiles: ts.SourceFile[] = program @@ -29,7 +29,7 @@ function onTSProgramUpdate( function checkResult( sourceFileName: string, className: string, - interfaceText: string + interfaceText: string, ) { expect(sourceFileName).toMatch(/.*SampleControl.ts/); expect(className).toEqual("SampleControl"); diff --git a/packages/ts-interface-generator/src/typeScriptEnvironment.ts b/packages/ts-interface-generator/src/typeScriptEnvironment.ts index 6a343f09..bd8b270a 100644 --- a/packages/ts-interface-generator/src/typeScriptEnvironment.ts +++ b/packages/ts-interface-generator/src/typeScriptEnvironment.ts @@ -17,7 +17,7 @@ type TSProgramUpdateCallback = ( program: ts.Program, typeChecker: ts.TypeChecker, changedFiles: string[], - allKnownGlobals: GlobalToModuleMapping + allKnownGlobals: GlobalToModuleMapping, ) => void; let newProgram: ts.SemanticDiagnosticsBuilderProgram; @@ -31,11 +31,11 @@ let options: { watchMode?: boolean }; function initialize( configFile: string, onTSProgramUpdateCallback: TSProgramUpdateCallback, - optionsParameter: { watchMode?: boolean } = {} + optionsParameter: { watchMode?: boolean } = {}, ) { if (onTSProgramUpdate) { throw new Error( - "There may be only ONE call to either initializeForOneRun or initializeWatchMode" + "There may be only ONE call to either initializeForOneRun or initializeWatchMode", ); } onTSProgramUpdate = onTSProgramUpdateCallback; @@ -43,7 +43,7 @@ function initialize( // initialize TypeScript program log.info( - "Initializing TypeScript program with all source files and type definitions (this may take a few seconds)..." + "Initializing TypeScript program with all source files and type definitions (this may take a few seconds)...", ); if (!options.watchMode) { @@ -53,7 +53,7 @@ function initialize( ts.sys.write = (text) => { text = text.replace( "Starting compilation in watch mode...", - "Starting compilation..." + "Starting compilation...", ); text = text.replace("Watching for file changes.", ""); originalTSwrite(text); @@ -66,7 +66,7 @@ function initialize( ts.sys, ts.createSemanticDiagnosticsBuilderProgram, options.watchMode ? reportDiagnostic : undefined, - options.watchMode ? reportWatchStatusChanged : undefined + options.watchMode ? reportWatchStatusChanged : undefined, ); // override the "after program create" function because we need access to the new "program" @@ -96,10 +96,10 @@ function initialize( changedFiles.push((aff as ts.SourceFile).fileName); } else { log.debug( - `### Changed: ${(aff as ts.Program).getRootFileNames().join(", ")}` + `### Changed: ${(aff as ts.Program).getRootFileNames().join(", ")}`, ); throw new Error( - "Not a source file change, but a program change caused the watch mode to trigger. This is unexpected. What does this mean? How did it happen?" + "Not a source file change, but a program change caused the watch mode to trigger. This is unexpected. What does this mean? How did it happen?", ); } diag = program.getSemanticDiagnosticsOfNextAffectedFile(); @@ -147,7 +147,7 @@ function reportWatchStatusChanged(diagnostic: ts.Diagnostic) { if (newProgram) { // TODO: handle errorCount newChangedFiles = newChangedFiles.filter( - (fileName) => !fileName.endsWith(".gen.d.ts") + (fileName) => !fileName.endsWith(".gen.d.ts"), ); // not interested in changes to generated files if (newChangedFiles.length) { const timer_begin = performance.now(); @@ -157,8 +157,8 @@ function reportWatchStatusChanged(diagnostic: ts.Diagnostic) { const timer_end = performance.now(); log.debug( `Handling the file change took ${(timer_end - timer_begin).toFixed( - 1 - )} ms.` + 1, + )} ms.`, ); } else { // no files modified/deleted @@ -169,13 +169,13 @@ function reportWatchStatusChanged(diagnostic: ts.Diagnostic) { } else { // should not happen throw new Error( - "reportWatchStatusChanged: diagnostic.code === 6194, but globalProgram not available" + "reportWatchStatusChanged: diagnostic.code === 6194, but globalProgram not available", ); } } else { // should not happen throw new Error( - `reportWatchStatusChanged: diagnostic.code !== 6031 or 6032 or 6193 or 6194, it is: ${diagnostic.code}` + `reportWatchStatusChanged: diagnostic.code !== 6031 or 6032 or 6193 or 6194, it is: ${diagnostic.code}`, ); } } @@ -188,7 +188,7 @@ function reportWatchStatusChanged(diagnostic: ts.Diagnostic) { */ function onProgramChanged( builderProgram: ts.SemanticDiagnosticsBuilderProgram, - changedFiles: string[] + changedFiles: string[], ) { const program = builderProgram.getProgram(); const typeChecker = program.getTypeChecker();