ts2famix 2.1.0-beta.1 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.json +24 -24
- package/LICENSE +24 -24
- package/README.md +78 -78
- package/dist/analyze.js +20 -10
- package/dist/analyze_functions/process_functions.js +109 -69
- package/dist/famix_functions/EntityDictionary.js +691 -606
- package/dist/famix_functions/helpers_creation.js +35 -19
- package/dist/fqn.js +351 -18
- package/dist/lib/famix/famix_JSON_exporter.js +1 -1
- package/dist/lib/famix/famix_base_element.js +1 -1
- package/dist/lib/famix/famix_repository.js +31 -12
- package/dist/lib/famix/index.js +18 -8
- package/dist/lib/famix/model/famix/access.js +1 -1
- package/dist/lib/famix/model/famix/accessor.js +1 -1
- package/dist/lib/famix/model/famix/alias.js +1 -1
- package/dist/lib/famix/model/famix/arrow_function.js +1 -1
- package/dist/lib/famix/model/famix/behavioral_entity.js +1 -1
- package/dist/lib/famix/model/famix/class.js +1 -1
- package/dist/lib/famix/model/famix/comment.js +1 -1
- package/dist/lib/famix/model/famix/concretisation.js +1 -1
- package/dist/lib/famix/model/famix/container_entity.js +1 -1
- package/dist/lib/famix/model/famix/decorator.js +1 -1
- package/dist/lib/famix/model/famix/entity.js +1 -1
- package/dist/lib/famix/model/famix/enum.js +1 -1
- package/dist/lib/famix/model/famix/enum_value.js +1 -1
- package/dist/lib/famix/model/famix/function.js +1 -1
- package/dist/lib/famix/model/famix/import_clause.js +1 -1
- package/dist/lib/famix/model/famix/index.js +1 -1
- package/dist/lib/famix/model/famix/indexed_file_anchor.js +1 -1
- package/dist/lib/famix/model/famix/inheritance.js +1 -1
- package/dist/lib/famix/model/famix/interface.js +1 -1
- package/dist/lib/famix/model/famix/invocation.js +1 -1
- package/dist/lib/famix/model/famix/method.js +1 -1
- package/dist/lib/famix/model/famix/module.js +2 -2
- package/dist/lib/famix/model/famix/named_entity.js +1 -1
- package/dist/lib/famix/model/famix/parameter.js +1 -1
- package/dist/lib/famix/model/famix/parameter_concretisation.js +1 -1
- package/dist/lib/famix/model/famix/parameter_type.js +1 -1
- package/dist/lib/famix/model/famix/parametric_arrow_function.js +1 -1
- package/dist/lib/famix/model/famix/parametric_class.js +1 -1
- package/dist/lib/famix/model/famix/parametric_function.js +1 -1
- package/dist/lib/famix/model/famix/parametric_interface.js +1 -1
- package/dist/lib/famix/model/famix/parametric_method.js +1 -1
- package/dist/lib/famix/model/famix/primitive_type.js +1 -1
- package/dist/lib/famix/model/famix/property.js +1 -1
- package/dist/lib/famix/model/famix/reference.js +1 -1
- package/dist/lib/famix/model/famix/scoping_entity.js +1 -1
- package/dist/lib/famix/model/famix/script_entity.js +1 -1
- package/dist/lib/famix/model/famix/source_anchor.js +1 -1
- package/dist/lib/famix/model/famix/source_language.js +1 -1
- package/dist/lib/famix/model/famix/sourced_entity.js +1 -1
- package/dist/lib/famix/model/famix/structural_entity.js +1 -1
- package/dist/lib/famix/model/famix/type.js +1 -1
- package/dist/lib/famix/model/famix/variable.js +1 -1
- package/dist/lib/ts-complex/cyclomatic-service.js +1 -1
- package/dist/refactorer/refactor-getter-setter.js +18 -8
- package/dist/ts2famix-cli-wrapper.js +18 -8
- package/dist/ts2famix-cli.js +18 -8
- package/dist/ts2famix-tsconfig.js +18 -8
- package/doc-uml/famix-typescript-model.puml +619 -607
- package/doc-uml/famix-typescript-model.svg +1 -1
- package/eslint.config.mjs +28 -28
- package/jest.config.json +1 -1
- package/package.json +70 -70
- package/src/analyze.ts +120 -120
- package/src/analyze_functions/process_functions.ts +1069 -1040
- package/src/famix_functions/EntityDictionary.ts +2061 -2016
- package/src/famix_functions/helpers_creation.ts +143 -135
- package/src/fqn.ts +416 -50
- package/src/generate_uml.sh +20 -20
- package/src/lib/famix/License.md +22 -22
- package/src/lib/famix/famix_JSON_exporter.ts +56 -56
- package/src/lib/famix/famix_base_element.ts +22 -22
- package/src/lib/famix/famix_repository.ts +288 -278
- package/src/lib/famix/index.ts +8 -8
- package/src/lib/famix/model/famix/access.ts +50 -50
- package/src/lib/famix/model/famix/accessor.ts +15 -15
- package/src/lib/famix/model/famix/alias.ts +39 -39
- package/src/lib/famix/model/famix/arrow_function.ts +15 -15
- package/src/lib/famix/model/famix/behavioral_entity.ts +97 -97
- package/src/lib/famix/model/famix/class.ts +85 -85
- package/src/lib/famix/model/famix/comment.ts +47 -47
- package/src/lib/famix/model/famix/concretisation.ts +40 -40
- package/src/lib/famix/model/famix/container_entity.ts +160 -160
- package/src/lib/famix/model/famix/decorator.ts +37 -37
- package/src/lib/famix/model/famix/entity.ts +15 -15
- package/src/lib/famix/model/famix/enum.ts +30 -30
- package/src/lib/famix/model/famix/enum_value.ts +28 -28
- package/src/lib/famix/model/famix/function.ts +15 -15
- package/src/lib/famix/model/famix/import_clause.ts +51 -51
- package/src/lib/famix/model/famix/index.ts +41 -41
- package/src/lib/famix/model/famix/indexed_file_anchor.ts +46 -46
- package/src/lib/famix/model/famix/inheritance.ts +40 -40
- package/src/lib/famix/model/famix/interface.ts +75 -75
- package/src/lib/famix/model/famix/invocation.ts +65 -65
- package/src/lib/famix/model/famix/method.ts +89 -89
- package/src/lib/famix/model/famix/module.ts +71 -71
- package/src/lib/famix/model/famix/named_entity.ts +95 -95
- package/src/lib/famix/model/famix/parameter.ts +28 -28
- package/src/lib/famix/model/famix/parameter_concretisation.ts +51 -51
- package/src/lib/famix/model/famix/parameter_type.ts +58 -58
- package/src/lib/famix/model/famix/parametric_arrow_function.ts +32 -32
- package/src/lib/famix/model/famix/parametric_class.ts +49 -49
- package/src/lib/famix/model/famix/parametric_function.ts +32 -32
- package/src/lib/famix/model/famix/parametric_interface.ts +49 -49
- package/src/lib/famix/model/famix/parametric_method.ts +32 -32
- package/src/lib/famix/model/famix/primitive_type.ts +15 -15
- package/src/lib/famix/model/famix/property.ts +94 -94
- package/src/lib/famix/model/famix/reference.ts +40 -40
- package/src/lib/famix/model/famix/scoping_entity.ts +35 -35
- package/src/lib/famix/model/famix/script_entity.ts +34 -34
- package/src/lib/famix/model/famix/source_anchor.ts +30 -30
- package/src/lib/famix/model/famix/source_language.ts +35 -35
- package/src/lib/famix/model/famix/sourced_entity.ts +70 -70
- package/src/lib/famix/model/famix/structural_entity.ts +43 -43
- package/src/lib/famix/model/famix/type.ts +87 -87
- package/src/lib/famix/model/famix/variable.ts +27 -27
- package/src/lib/famix/package.json +28 -28
- package/src/lib/ts-complex/cyclomatic-service.ts +83 -83
- package/src/refactorer/refactor-getter-setter.ts +140 -140
- package/src/ts2famix-cli-wrapper.ts +21 -21
- package/src/ts2famix-cli.ts +60 -60
- package/tsconfig.check-tests.json +14 -14
- package/tsconfig.json +73 -72
- package/.vscode/settings.json +0 -4
- package/TODO +0 -1
- package/arwea-fix.json +0 -1
- package/bogus.ts +0 -3
- package/class-diagram.puml +0 -792
- package/debug.txt +0 -13332
- package/debuglog.txt +0 -12073
- package/dist/famix2puml.js +0 -126
- package/dist/getClasses-arrow-body.js +0 -43
- package/dist/lib/famix/src/famix_JSON_exporter.js +0 -55
- package/dist/lib/famix/src/famix_base_element.js +0 -18
- package/dist/lib/famix/src/famix_repository.js +0 -224
- package/dist/lib/famix/src/index.js +0 -31
- package/dist/lib/famix/src/model/famix/access.js +0 -40
- package/dist/lib/famix/src/model/famix/accessor.js +0 -17
- package/dist/lib/famix/src/model/famix/alias.js +0 -33
- package/dist/lib/famix/src/model/famix/arrowFunction.js +0 -17
- package/dist/lib/famix/src/model/famix/arrow_function.js +0 -17
- package/dist/lib/famix/src/model/famix/behavioral_entity.js +0 -79
- package/dist/lib/famix/src/model/famix/class.js +0 -71
- package/dist/lib/famix/src/model/famix/comment.js +0 -39
- package/dist/lib/famix/src/model/famix/concretisation.js +0 -31
- package/dist/lib/famix/src/model/famix/container_entity.js +0 -126
- package/dist/lib/famix/src/model/famix/decorator.js +0 -32
- package/dist/lib/famix/src/model/famix/entity.js +0 -17
- package/dist/lib/famix/src/model/famix/enum.js +0 -31
- package/dist/lib/famix/src/model/famix/enum_value.js +0 -25
- package/dist/lib/famix/src/model/famix/function.js +0 -17
- package/dist/lib/famix/src/model/famix/implicit_variable.js +0 -17
- package/dist/lib/famix/src/model/famix/import_clause.js +0 -41
- package/dist/lib/famix/src/model/famix/index.js +0 -86
- package/dist/lib/famix/src/model/famix/indexed_file_anchor.js +0 -38
- package/dist/lib/famix/src/model/famix/inheritance.js +0 -33
- package/dist/lib/famix/src/model/famix/interface.js +0 -64
- package/dist/lib/famix/src/model/famix/invocation.js +0 -54
- package/dist/lib/famix/src/model/famix/method.js +0 -67
- package/dist/lib/famix/src/model/famix/module.js +0 -60
- package/dist/lib/famix/src/model/famix/named_entity.js +0 -78
- package/dist/lib/famix/src/model/famix/parameter.js +0 -25
- package/dist/lib/famix/src/model/famix/parameterConcretisation.js +0 -44
- package/dist/lib/famix/src/model/famix/parameter_concretisation.js +0 -44
- package/dist/lib/famix/src/model/famix/parameter_type.js +0 -45
- package/dist/lib/famix/src/model/famix/parametricArrowFunction.js +0 -29
- package/dist/lib/famix/src/model/famix/parametric_arrow_function.js +0 -31
- package/dist/lib/famix/src/model/famix/parametric_class.js +0 -44
- package/dist/lib/famix/src/model/famix/parametric_function.js +0 -31
- package/dist/lib/famix/src/model/famix/parametric_interface.js +0 -44
- package/dist/lib/famix/src/model/famix/parametric_method.js +0 -31
- package/dist/lib/famix/src/model/famix/primitive_type.js +0 -17
- package/dist/lib/famix/src/model/famix/property.js +0 -73
- package/dist/lib/famix/src/model/famix/reference.js +0 -33
- package/dist/lib/famix/src/model/famix/scoping_entity.js +0 -36
- package/dist/lib/famix/src/model/famix/script_entity.js +0 -29
- package/dist/lib/famix/src/model/famix/source_anchor.js +0 -27
- package/dist/lib/famix/src/model/famix/source_language.js +0 -35
- package/dist/lib/famix/src/model/famix/sourced_entity.js +0 -60
- package/dist/lib/famix/src/model/famix/structural_entity.js +0 -39
- package/dist/lib/famix/src/model/famix/text_anchor.js +0 -38
- package/dist/lib/famix/src/model/famix/type.js +0 -73
- package/dist/lib/famix/src/model/famix/variable.js +0 -24
- package/fqn-model.json +0 -1
- package/iterateGenericTypes.ts +0 -69
- package/out/class-diagram/class-diagram.svg +0 -1
- package/sample.json +0 -1
- package/sample.ts +0 -1
- package/stats.txt +0 -3091
- package/tabby-debug-output.txt +0 -19433
- package/ts2famix.log +0 -22656
- package/validate-references.js +0 -103
|
@@ -1,135 +1,143 @@
|
|
|
1
|
-
import * as Famix from "../lib/famix/model/famix";
|
|
2
|
-
import { logger } from "../analyze";
|
|
3
|
-
import { ConstructorDeclaration, Identifier, FunctionDeclaration, MethodDeclaration, MethodSignature, PropertyDeclaration, PropertySignature, VariableDeclaration, ParameterDeclaration, GetAccessorDeclaration, SetAccessorDeclaration, EnumMember, TypeAliasDeclaration, Node, SyntaxKind, FunctionExpression } from "ts-morph";
|
|
4
|
-
import { TSMorphTypeDeclaration } from "./EntityDictionary";
|
|
5
|
-
|
|
6
|
-
interface SearchParameters {
|
|
7
|
-
searchArray: string[];
|
|
8
|
-
targetArray: string[];
|
|
9
|
-
start?: number;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* This function works like indexOf, but it works with arrays of grapheme clusters.
|
|
14
|
-
* @param targetArray
|
|
15
|
-
*/
|
|
16
|
-
export function indexOfSplitArray(params: SearchParameters): number {
|
|
17
|
-
const {searchArray, targetArray, start = 0} = params;
|
|
18
|
-
for (let i = start; i <= searchArray.length - targetArray.length; i++) {
|
|
19
|
-
let found = true;
|
|
20
|
-
for (let j = 0; j < targetArray.length; j++) {
|
|
21
|
-
if (searchArray[i + j] !== targetArray[j]) {
|
|
22
|
-
found = false;
|
|
23
|
-
break;
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
if (found) {
|
|
27
|
-
return i; // Return the index where the target array was found
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
return -1; // Return -1 if the target array was not found in the search array
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
export function getSubTypeName(fmxNamedEntity: Famix.NamedEntity) {
|
|
34
|
-
const name = fmxNamedEntity instanceof Famix.Class ? 'Class' :
|
|
35
|
-
fmxNamedEntity instanceof Famix.Interface ? 'Interface' :
|
|
36
|
-
fmxNamedEntity instanceof Famix.Function ? 'Function' :
|
|
37
|
-
fmxNamedEntity instanceof Famix.Enum ? 'Enum' :
|
|
38
|
-
fmxNamedEntity instanceof Famix.EnumValue ? 'EnumValue' :
|
|
39
|
-
fmxNamedEntity instanceof Famix.Alias ? 'Alias' :
|
|
40
|
-
fmxNamedEntity instanceof Famix.Variable ? 'Variable' :
|
|
41
|
-
fmxNamedEntity instanceof Famix.Type ? 'Type' :
|
|
42
|
-
fmxNamedEntity instanceof Famix.Method ? 'Method' :
|
|
43
|
-
fmxNamedEntity instanceof Famix.Decorator ? 'Decorator' :
|
|
44
|
-
fmxNamedEntity instanceof Famix.Accessor ? 'Accessor' :
|
|
45
|
-
fmxNamedEntity instanceof Famix.Parameter ? 'Parameter' :
|
|
46
|
-
fmxNamedEntity instanceof Famix.Property ? 'Property' :
|
|
47
|
-
'NamedEntity';
|
|
48
|
-
logger.debug(`${fmxNamedEntity.name} is of type ${name}`);
|
|
49
|
-
return name;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* Gets the signature of a method or a function
|
|
54
|
-
* @param text A method or a function source code
|
|
55
|
-
* @returns The signature of the method or the function
|
|
56
|
-
*/
|
|
57
|
-
export function computeSignature(text: string): string {
|
|
58
|
-
const endSignatureText = text.indexOf("{");
|
|
59
|
-
return text.substring(0, endSignatureText).trim();
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* Finds the ancestor of a node
|
|
64
|
-
* @param node A node
|
|
65
|
-
* @returns The ancestor of the node
|
|
66
|
-
*/
|
|
67
|
-
export function findAncestor(node: Identifier): Node {
|
|
68
|
-
let ancestor: Node | undefined;
|
|
69
|
-
ancestor = node.getAncestors().find(a =>
|
|
70
|
-
a.getKind() === SyntaxKind.MethodDeclaration ||
|
|
71
|
-
a.getKind() === SyntaxKind.Constructor ||
|
|
72
|
-
a.getKind() === SyntaxKind.FunctionDeclaration ||
|
|
73
|
-
a.getKind() === SyntaxKind.FunctionExpression ||
|
|
74
|
-
a.getKind() === SyntaxKind.ModuleDeclaration ||
|
|
75
|
-
a.getKind() === SyntaxKind.SourceFile ||
|
|
76
|
-
a.getKindName() === "GetAccessor" ||
|
|
77
|
-
a.getKindName() === "SetAccessor" ||
|
|
78
|
-
a.getKind() === SyntaxKind.ClassDeclaration);
|
|
79
|
-
if (!ancestor) {
|
|
80
|
-
throw new Error(`Ancestor not found for ${node.getText()}`);
|
|
81
|
-
}
|
|
82
|
-
return ancestor
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
/**
|
|
86
|
-
* Finds the ancestor of a ts-morph element
|
|
87
|
-
* @param element A ts-morph element
|
|
88
|
-
* @returns The ancestor of the ts-morph element
|
|
89
|
-
*/
|
|
90
|
-
export function findTypeAncestor(element:
|
|
91
|
-
let ancestor: Node | undefined;
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
a.getKind()
|
|
97
|
-
a.
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
if (
|
|
112
|
-
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
export function
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
return
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
1
|
+
import * as Famix from "../lib/famix/model/famix";
|
|
2
|
+
import { logger } from "../analyze";
|
|
3
|
+
import { ConstructorDeclaration, Identifier, FunctionDeclaration, MethodDeclaration, MethodSignature, PropertyDeclaration, PropertySignature, VariableDeclaration, ParameterDeclaration, GetAccessorDeclaration, SetAccessorDeclaration, EnumMember, TypeAliasDeclaration, Node, SyntaxKind, FunctionExpression } from "ts-morph";
|
|
4
|
+
import { TSMorphTypeDeclaration } from "./EntityDictionary";
|
|
5
|
+
|
|
6
|
+
interface SearchParameters {
|
|
7
|
+
searchArray: string[];
|
|
8
|
+
targetArray: string[];
|
|
9
|
+
start?: number;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* This function works like indexOf, but it works with arrays of grapheme clusters.
|
|
14
|
+
* @param targetArray
|
|
15
|
+
*/
|
|
16
|
+
export function indexOfSplitArray(params: SearchParameters): number {
|
|
17
|
+
const {searchArray, targetArray, start = 0} = params;
|
|
18
|
+
for (let i = start; i <= searchArray.length - targetArray.length; i++) {
|
|
19
|
+
let found = true;
|
|
20
|
+
for (let j = 0; j < targetArray.length; j++) {
|
|
21
|
+
if (searchArray[i + j] !== targetArray[j]) {
|
|
22
|
+
found = false;
|
|
23
|
+
break;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
if (found) {
|
|
27
|
+
return i; // Return the index where the target array was found
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
return -1; // Return -1 if the target array was not found in the search array
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function getSubTypeName(fmxNamedEntity: Famix.NamedEntity) {
|
|
34
|
+
const name = fmxNamedEntity instanceof Famix.Class ? 'Class' :
|
|
35
|
+
fmxNamedEntity instanceof Famix.Interface ? 'Interface' :
|
|
36
|
+
fmxNamedEntity instanceof Famix.Function ? 'Function' :
|
|
37
|
+
fmxNamedEntity instanceof Famix.Enum ? 'Enum' :
|
|
38
|
+
fmxNamedEntity instanceof Famix.EnumValue ? 'EnumValue' :
|
|
39
|
+
fmxNamedEntity instanceof Famix.Alias ? 'Alias' :
|
|
40
|
+
fmxNamedEntity instanceof Famix.Variable ? 'Variable' :
|
|
41
|
+
fmxNamedEntity instanceof Famix.Type ? 'Type' :
|
|
42
|
+
fmxNamedEntity instanceof Famix.Method ? 'Method' :
|
|
43
|
+
fmxNamedEntity instanceof Famix.Decorator ? 'Decorator' :
|
|
44
|
+
fmxNamedEntity instanceof Famix.Accessor ? 'Accessor' :
|
|
45
|
+
fmxNamedEntity instanceof Famix.Parameter ? 'Parameter' :
|
|
46
|
+
fmxNamedEntity instanceof Famix.Property ? 'Property' :
|
|
47
|
+
'NamedEntity';
|
|
48
|
+
logger.debug(`${fmxNamedEntity.name} is of type ${name}`);
|
|
49
|
+
return name;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Gets the signature of a method or a function
|
|
54
|
+
* @param text A method or a function source code
|
|
55
|
+
* @returns The signature of the method or the function
|
|
56
|
+
*/
|
|
57
|
+
export function computeSignature(text: string): string {
|
|
58
|
+
const endSignatureText = text.indexOf("{");
|
|
59
|
+
return text.substring(0, endSignatureText).trim();
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Finds the ancestor of a node
|
|
64
|
+
* @param node A node
|
|
65
|
+
* @returns The ancestor of the node
|
|
66
|
+
*/
|
|
67
|
+
export function findAncestor(node: Identifier): Node {
|
|
68
|
+
let ancestor: Node | undefined;
|
|
69
|
+
ancestor = node.getAncestors().find(a =>
|
|
70
|
+
a.getKind() === SyntaxKind.MethodDeclaration ||
|
|
71
|
+
a.getKind() === SyntaxKind.Constructor ||
|
|
72
|
+
a.getKind() === SyntaxKind.FunctionDeclaration ||
|
|
73
|
+
a.getKind() === SyntaxKind.FunctionExpression ||
|
|
74
|
+
a.getKind() === SyntaxKind.ModuleDeclaration ||
|
|
75
|
+
a.getKind() === SyntaxKind.SourceFile ||
|
|
76
|
+
a.getKindName() === "GetAccessor" ||
|
|
77
|
+
a.getKindName() === "SetAccessor" ||
|
|
78
|
+
a.getKind() === SyntaxKind.ClassDeclaration);
|
|
79
|
+
if (!ancestor) {
|
|
80
|
+
throw new Error(`Ancestor not found for ${node.getText()}`);
|
|
81
|
+
}
|
|
82
|
+
return ancestor
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Finds the ancestor of a ts-morph element
|
|
87
|
+
* @param element A ts-morph element
|
|
88
|
+
* @returns The ancestor of the ts-morph element
|
|
89
|
+
*/
|
|
90
|
+
export function findTypeAncestor(element: Node): Node | undefined {
|
|
91
|
+
let ancestor: Node | undefined;
|
|
92
|
+
const ancestors = element.getAncestors();
|
|
93
|
+
console.log(`Ancestors count: ${ancestors.length}`);
|
|
94
|
+
|
|
95
|
+
ancestor = ancestors.find(a => {
|
|
96
|
+
const kind = a.getKind();
|
|
97
|
+
const kindName = a.getKindName();
|
|
98
|
+
return kind === SyntaxKind.MethodDeclaration ||
|
|
99
|
+
kind === SyntaxKind.Constructor ||
|
|
100
|
+
kind === SyntaxKind.MethodSignature ||
|
|
101
|
+
kind === SyntaxKind.FunctionDeclaration ||
|
|
102
|
+
kind === SyntaxKind.FunctionExpression ||
|
|
103
|
+
kind === SyntaxKind.ModuleDeclaration ||
|
|
104
|
+
kind === SyntaxKind.SourceFile ||
|
|
105
|
+
kindName === "GetAccessor" ||
|
|
106
|
+
kindName === "SetAccessor" ||
|
|
107
|
+
kind === SyntaxKind.ClassDeclaration ||
|
|
108
|
+
kind === SyntaxKind.InterfaceDeclaration;
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
if (!ancestor) {
|
|
112
|
+
throw new Error(`Type ancestor not found for ${element.getKindName()}`);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
return ancestor;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
export function arraysAreEqual(array1: string[], array2: string[]): boolean {
|
|
119
|
+
if (array1 && array2 ) {
|
|
120
|
+
return array1.length === array2.length && array1.every((value, index) => value === array2[index]);
|
|
121
|
+
} else {
|
|
122
|
+
return false;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
export function replaceLastBetweenTags(input: string, replacement: string): string {
|
|
127
|
+
const lastTagIndex = input.lastIndexOf('<');
|
|
128
|
+
|
|
129
|
+
if (lastTagIndex === -1) {
|
|
130
|
+
return input; // Return the original string if no tags are found
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
const closingTagIndex = input.indexOf('>', lastTagIndex);
|
|
134
|
+
|
|
135
|
+
if (closingTagIndex === -1) {
|
|
136
|
+
return input; // Return the original string if no closing tag is found
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
const beforeTag = input.substring(0, lastTagIndex + 1); // Include '<'
|
|
140
|
+
const afterTag = input.substring(closingTagIndex); // Include '>'
|
|
141
|
+
|
|
142
|
+
return beforeTag + replacement + afterTag;
|
|
143
|
+
}
|