@ts-for-gir/lib 4.0.0-beta.2 → 4.0.0-beta.20

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.
Files changed (319) hide show
  1. package/lib/constants.d.ts +6 -7
  2. package/lib/constants.js +74 -9
  3. package/lib/constants.js.map +1 -1
  4. package/lib/dependency-manager.d.ts +60 -14
  5. package/lib/dependency-manager.js +148 -46
  6. package/lib/dependency-manager.js.map +1 -1
  7. package/lib/generators/dts-inline.d.ts +4 -2
  8. package/lib/generators/dts-inline.js +10 -12
  9. package/lib/generators/dts-inline.js.map +1 -1
  10. package/lib/generators/dts-modules.d.ts +4 -2
  11. package/lib/generators/dts-modules.js +12 -14
  12. package/lib/generators/dts-modules.js.map +1 -1
  13. package/lib/generators/dts.d.ts +2 -2
  14. package/lib/generators/dts.js +10 -9
  15. package/lib/generators/dts.js.map +1 -1
  16. package/lib/generators/generator.d.ts +3 -3
  17. package/lib/generators/generator.js.map +1 -1
  18. package/lib/generators/json.d.ts +6 -5
  19. package/lib/generators/json.js +18 -21
  20. package/lib/generators/json.js.map +1 -1
  21. package/lib/generics/clutter.d.ts +10 -0
  22. package/lib/generics/clutter.js +2 -0
  23. package/lib/generics/clutter.js.map +1 -1
  24. package/lib/generics/generify.js +11 -3
  25. package/lib/generics/generify.js.map +1 -1
  26. package/lib/generics/gtk.d.ts +7 -0
  27. package/lib/generics/gtk.js +56 -0
  28. package/lib/generics/gtk.js.map +1 -0
  29. package/lib/generics/meta.d.ts +10 -0
  30. package/lib/generics/meta.js +2 -0
  31. package/lib/generics/meta.js.map +1 -1
  32. package/lib/generics/st.d.ts +10 -0
  33. package/lib/generics/st.js +15 -10
  34. package/lib/generics/st.js.map +1 -1
  35. package/lib/generics/visitor.js +5 -9
  36. package/lib/generics/visitor.js.map +1 -1
  37. package/lib/gir/alias.d.ts +2 -2
  38. package/lib/gir/alias.js +3 -3
  39. package/lib/gir/alias.js.map +1 -1
  40. package/lib/gir/base.d.ts +3 -3
  41. package/lib/gir/base.js +2 -14
  42. package/lib/gir/base.js.map +1 -1
  43. package/lib/gir/class.d.ts +6 -7
  44. package/lib/gir/class.js +35 -108
  45. package/lib/gir/class.js.map +1 -1
  46. package/lib/gir/const.d.ts +2 -2
  47. package/lib/gir/const.js +1 -1
  48. package/lib/gir/const.js.map +1 -1
  49. package/lib/gir/enum.d.ts +5 -5
  50. package/lib/gir/enum.js +7 -7
  51. package/lib/gir/enum.js.map +1 -1
  52. package/lib/gir/function.d.ts +11 -10
  53. package/lib/gir/function.js +4 -4
  54. package/lib/gir/function.js.map +1 -1
  55. package/lib/gir/index.d.ts +14 -0
  56. package/lib/gir/index.js +15 -0
  57. package/lib/gir/index.js.map +1 -0
  58. package/lib/gir/nodes.d.ts +1 -1
  59. package/lib/gir/nodes.js +1 -1
  60. package/lib/gir/nodes.js.map +1 -1
  61. package/lib/gir/promisify.d.ts +5 -0
  62. package/lib/gir/promisify.js +158 -0
  63. package/lib/gir/promisify.js.map +1 -0
  64. package/lib/gir/property.d.ts +2 -2
  65. package/lib/gir/property.js.map +1 -1
  66. package/lib/gir/registry.d.ts +6 -6
  67. package/lib/gir/registry.js +6 -3
  68. package/lib/gir/registry.js.map +1 -1
  69. package/lib/gir/signal.d.ts +2 -2
  70. package/lib/gir/signal.js.map +1 -1
  71. package/lib/gir/util.d.ts +3 -3
  72. package/lib/gir/util.js +17 -14
  73. package/lib/gir/util.js.map +1 -1
  74. package/lib/gir-module.d.ts +27 -39
  75. package/lib/gir-module.js +161 -149
  76. package/lib/gir-module.js.map +1 -1
  77. package/lib/gir.d.ts +43 -40
  78. package/lib/gir.js +28 -27
  79. package/lib/gir.js.map +1 -1
  80. package/lib/index.d.ts +1 -2
  81. package/lib/index.js +1 -2
  82. package/lib/index.js.map +1 -1
  83. package/lib/injections/gio.js +133 -1
  84. package/lib/injections/gio.js.map +1 -1
  85. package/lib/injections/glib.js +6 -0
  86. package/lib/injections/glib.js.map +1 -1
  87. package/lib/injections/gobject.js +84 -64
  88. package/lib/injections/gobject.js.map +1 -1
  89. package/lib/injections/gtk4.d.ts +7 -0
  90. package/lib/injections/gtk4.js +19 -0
  91. package/lib/injections/gtk4.js.map +1 -0
  92. package/lib/injections/inject.js +5 -0
  93. package/lib/injections/inject.js.map +1 -1
  94. package/lib/injections/shell.d.ts +14 -0
  95. package/lib/injections/shell.js +32 -0
  96. package/lib/injections/shell.js.map +1 -0
  97. package/lib/library-version.d.ts +2 -0
  98. package/lib/library-version.js +13 -0
  99. package/lib/library-version.js.map +1 -1
  100. package/lib/logger.d.ts +18 -16
  101. package/lib/logger.js +28 -26
  102. package/lib/logger.js.map +1 -1
  103. package/lib/messages.d.ts +0 -3
  104. package/lib/messages.js +0 -3
  105. package/lib/messages.js.map +1 -1
  106. package/lib/registry.d.ts +0 -1
  107. package/lib/registry.js +0 -1
  108. package/lib/registry.js.map +1 -1
  109. package/lib/transformation.d.ts +5 -15
  110. package/lib/transformation.js +9 -89
  111. package/lib/transformation.js.map +1 -1
  112. package/lib/types/dependency.d.ts +13 -1
  113. package/lib/types/format.d.ts +1 -0
  114. package/lib/types/format.js +2 -0
  115. package/lib/types/format.js.map +1 -0
  116. package/lib/types/gir-instance-parameter.d.ts +1 -2
  117. package/lib/types/gir-module-resolved-by.d.ts +5 -0
  118. package/lib/types/index.d.ts +7 -2
  119. package/lib/types/index.js +7 -2
  120. package/lib/types/index.js.map +1 -1
  121. package/lib/types/metadata.d.ts +8 -0
  122. package/lib/types/metadata.js +2 -0
  123. package/lib/types/metadata.js.map +1 -0
  124. package/lib/types/options-base.d.ts +4 -0
  125. package/lib/types/options-base.js +2 -0
  126. package/lib/types/options-base.js.map +1 -0
  127. package/lib/types/{generate-config.d.ts → options-generation.d.ts} +21 -11
  128. package/lib/types/options-generation.js +2 -0
  129. package/lib/types/options-generation.js.map +1 -0
  130. package/lib/types/options-load.d.ts +5 -0
  131. package/lib/types/options-load.js +2 -0
  132. package/lib/types/options-load.js.map +1 -0
  133. package/lib/types/options-transform.d.ts +4 -0
  134. package/lib/types/options-transform.js +2 -0
  135. package/lib/types/options-transform.js.map +1 -0
  136. package/lib/types/output-format.d.ts +1 -0
  137. package/lib/types/output-format.js +2 -0
  138. package/lib/types/output-format.js.map +1 -0
  139. package/lib/types/property-case.d.ts +1 -0
  140. package/lib/types/property-case.js +2 -0
  141. package/lib/types/property-case.js.map +1 -0
  142. package/lib/types/template-data.d.ts +2 -2
  143. package/lib/types/user-config.d.ts +21 -6
  144. package/lib/utils/files.d.ts +21 -0
  145. package/lib/utils/files.js +62 -0
  146. package/lib/utils/files.js.map +1 -0
  147. package/lib/utils/girs.d.ts +45 -0
  148. package/lib/utils/girs.js +101 -0
  149. package/lib/utils/girs.js.map +1 -0
  150. package/lib/utils/index.d.ts +6 -0
  151. package/lib/utils/index.js +7 -0
  152. package/lib/utils/index.js.map +1 -0
  153. package/lib/utils/numbers.d.ts +6 -0
  154. package/lib/utils/numbers.js +9 -0
  155. package/lib/utils/numbers.js.map +1 -0
  156. package/lib/utils/objects.d.ts +136 -0
  157. package/lib/utils/objects.js +121 -0
  158. package/lib/utils/objects.js.map +1 -0
  159. package/lib/utils/path.d.ts +1 -0
  160. package/lib/utils/path.js +7 -0
  161. package/lib/utils/path.js.map +1 -0
  162. package/lib/utils/strings.d.ts +74 -0
  163. package/lib/utils/strings.js +121 -0
  164. package/lib/utils/strings.js.map +1 -0
  165. package/lib/utils.d.ts +21 -15
  166. package/lib/utils.js +58 -13
  167. package/lib/utils.js.map +1 -1
  168. package/lib/validators/enum-parameters.d.ts +16 -0
  169. package/lib/validators/enum-parameters.js +42 -0
  170. package/lib/validators/enum-parameters.js.map +1 -0
  171. package/lib/validators/function-parameters.d.ts +14 -0
  172. package/lib/validators/function-parameters.js +31 -0
  173. package/lib/validators/function-parameters.js.map +1 -0
  174. package/lib/validators/interface.js +1 -1
  175. package/lib/validators/interface.js.map +1 -1
  176. package/package.json +15 -14
  177. package/lib/conflict-resolver.d.ts +0 -119
  178. package/lib/conflict-resolver.js +0 -893
  179. package/lib/conflict-resolver.js.map +0 -1
  180. package/lib/generators/dts/gio.d.ts +0 -2
  181. package/lib/generators/dts/gio.js +0 -9
  182. package/lib/generators/dts/gio.js.map +0 -1
  183. package/lib/gir-factory.d.ts +0 -52
  184. package/lib/gir-factory.js +0 -340
  185. package/lib/gir-factory.js.map +0 -1
  186. package/lib/injection/callbacks/gjs/Gio-2.0.d.ts +0 -2
  187. package/lib/injection/callbacks/gjs/Gio-2.0.js +0 -36
  188. package/lib/injection/callbacks/gjs/Gio-2.0.js.map +0 -1
  189. package/lib/injection/callbacks/gjs/index.d.ts +0 -2
  190. package/lib/injection/callbacks/gjs/index.js +0 -3
  191. package/lib/injection/callbacks/gjs/index.js.map +0 -1
  192. package/lib/injection/callbacks/index.d.ts +0 -3
  193. package/lib/injection/callbacks/index.js +0 -3
  194. package/lib/injection/callbacks/index.js.map +0 -1
  195. package/lib/injection/classes/gjs/gio-2.0.d.ts +0 -5
  196. package/lib/injection/classes/gjs/gio-2.0.js +0 -254
  197. package/lib/injection/classes/gjs/gio-2.0.js.map +0 -1
  198. package/lib/injection/classes/gjs/glib-2.0.d.ts +0 -2
  199. package/lib/injection/classes/gjs/glib-2.0.js +0 -225
  200. package/lib/injection/classes/gjs/glib-2.0.js.map +0 -1
  201. package/lib/injection/classes/gjs/gobject-2.0.d.ts +0 -2
  202. package/lib/injection/classes/gjs/gobject-2.0.js +0 -634
  203. package/lib/injection/classes/gjs/gobject-2.0.js.map +0 -1
  204. package/lib/injection/classes/gjs/index.d.ts +0 -2
  205. package/lib/injection/classes/gjs/index.js +0 -5
  206. package/lib/injection/classes/gjs/index.js.map +0 -1
  207. package/lib/injection/classes/glib-2.0.d.ts +0 -2
  208. package/lib/injection/classes/glib-2.0.js +0 -35
  209. package/lib/injection/classes/glib-2.0.js.map +0 -1
  210. package/lib/injection/classes/index.d.ts +0 -3
  211. package/lib/injection/classes/index.js +0 -4
  212. package/lib/injection/classes/index.js.map +0 -1
  213. package/lib/injection/index.d.ts +0 -3
  214. package/lib/injection/index.js +0 -4
  215. package/lib/injection/index.js.map +0 -1
  216. package/lib/injection/injector.d.ts +0 -16
  217. package/lib/injection/injector.js +0 -138
  218. package/lib/injection/injector.js.map +0 -1
  219. package/lib/symtable.d.ts +0 -24
  220. package/lib/symtable.js +0 -63
  221. package/lib/symtable.js.map +0 -1
  222. package/lib/types/conflict-child-element.d.ts +0 -10
  223. package/lib/types/conflict-child-element.js +0 -2
  224. package/lib/types/conflict-child-element.js.map +0 -1
  225. package/lib/types/conflict-grouped-element.d.ts +0 -6
  226. package/lib/types/conflict-grouped-element.js +0 -2
  227. package/lib/types/conflict-grouped-element.js.map +0 -1
  228. package/lib/types/conflict-grouped-elements.d.ts +0 -4
  229. package/lib/types/conflict-grouped-elements.js +0 -2
  230. package/lib/types/conflict-grouped-elements.js.map +0 -1
  231. package/lib/types/generate-config.js +0 -2
  232. package/lib/types/generate-config.js.map +0 -1
  233. package/lib/types/injection-callback.d.ts +0 -16
  234. package/lib/types/injection-callback.js +0 -2
  235. package/lib/types/injection-callback.js.map +0 -1
  236. package/lib/types/injection-class.d.ts +0 -25
  237. package/lib/types/injection-class.js +0 -2
  238. package/lib/types/injection-class.js.map +0 -1
  239. package/lib/types/injection-function.d.ts +0 -7
  240. package/lib/types/injection-function.js +0 -2
  241. package/lib/types/injection-function.js.map +0 -1
  242. package/lib/types/injection-generic-parameter.d.ts +0 -2
  243. package/lib/types/injection-generic-parameter.js +0 -2
  244. package/lib/types/injection-generic-parameter.js.map +0 -1
  245. package/lib/types/injection-instance-parameter.d.ts +0 -2
  246. package/lib/types/injection-instance-parameter.js +0 -2
  247. package/lib/types/injection-instance-parameter.js.map +0 -1
  248. package/lib/types/injection-parameter.d.ts +0 -8
  249. package/lib/types/injection-parameter.js +0 -2
  250. package/lib/types/injection-parameter.js.map +0 -1
  251. package/lib/types/injection-property.d.ts +0 -4
  252. package/lib/types/injection-property.js +0 -2
  253. package/lib/types/injection-property.js.map +0 -1
  254. package/lib/types/injection-type.d.ts +0 -2
  255. package/lib/types/injection-type.js +0 -2
  256. package/lib/types/injection-type.js.map +0 -1
  257. package/lib/types/injection.d.ts +0 -5
  258. package/lib/types/injection.js +0 -2
  259. package/lib/types/injection.js.map +0 -1
  260. package/lib/types/promisify-func.d.ts +0 -7
  261. package/lib/types/promisify-func.js +0 -2
  262. package/lib/types/promisify-func.js.map +0 -1
  263. package/lib/types/sym-table-items.d.ts +0 -4
  264. package/lib/types/sym-table-items.js +0 -2
  265. package/lib/types/sym-table-items.js.map +0 -1
  266. package/lib/types/ts-alias.d.ts +0 -10
  267. package/lib/types/ts-alias.js +0 -2
  268. package/lib/types/ts-alias.js.map +0 -1
  269. package/lib/types/ts-callback-interface.d.ts +0 -10
  270. package/lib/types/ts-callback-interface.js +0 -2
  271. package/lib/types/ts-callback-interface.js.map +0 -1
  272. package/lib/types/ts-callback.d.ts +0 -17
  273. package/lib/types/ts-callback.js +0 -2
  274. package/lib/types/ts-callback.js.map +0 -1
  275. package/lib/types/ts-class.d.ts +0 -85
  276. package/lib/types/ts-class.js +0 -2
  277. package/lib/types/ts-class.js.map +0 -1
  278. package/lib/types/ts-enum.d.ts +0 -12
  279. package/lib/types/ts-enum.js +0 -2
  280. package/lib/types/ts-enum.js.map +0 -1
  281. package/lib/types/ts-function.d.ts +0 -55
  282. package/lib/types/ts-function.js +0 -2
  283. package/lib/types/ts-function.js.map +0 -1
  284. package/lib/types/ts-generic-parameter.d.ts +0 -8
  285. package/lib/types/ts-generic-parameter.js +0 -2
  286. package/lib/types/ts-generic-parameter.js.map +0 -1
  287. package/lib/types/ts-instance-parameter.d.ts +0 -4
  288. package/lib/types/ts-instance-parameter.js +0 -2
  289. package/lib/types/ts-instance-parameter.js.map +0 -1
  290. package/lib/types/ts-member.d.ts +0 -10
  291. package/lib/types/ts-member.js +0 -2
  292. package/lib/types/ts-member.js.map +0 -1
  293. package/lib/types/ts-method.d.ts +0 -5
  294. package/lib/types/ts-method.js +0 -2
  295. package/lib/types/ts-method.js.map +0 -1
  296. package/lib/types/ts-parameter.d.ts +0 -15
  297. package/lib/types/ts-parameter.js +0 -2
  298. package/lib/types/ts-parameter.js.map +0 -1
  299. package/lib/types/ts-property.d.ts +0 -17
  300. package/lib/types/ts-property.js +0 -2
  301. package/lib/types/ts-property.js.map +0 -1
  302. package/lib/types/ts-signal.d.ts +0 -17
  303. package/lib/types/ts-signal.js +0 -2
  304. package/lib/types/ts-signal.js.map +0 -1
  305. package/lib/types/ts-type-name.d.ts +0 -1
  306. package/lib/types/ts-type-name.js +0 -2
  307. package/lib/types/ts-type-name.js.map +0 -1
  308. package/lib/types/ts-type-separator.d.ts +0 -1
  309. package/lib/types/ts-type-separator.js +0 -2
  310. package/lib/types/ts-type-separator.js.map +0 -1
  311. package/lib/types/ts-type.d.ts +0 -26
  312. package/lib/types/ts-type.js +0 -2
  313. package/lib/types/ts-type.js.map +0 -1
  314. package/lib/types/ts-var.d.ts +0 -17
  315. package/lib/types/ts-var.js +0 -2
  316. package/lib/types/ts-var.js.map +0 -1
  317. package/lib/types.d.ts +0 -23
  318. package/lib/types.js +0 -2
  319. package/lib/types.js.map +0 -1
@@ -1,893 +0,0 @@
1
- import { GirFactory } from './gir-factory.js';
2
- import { Logger } from './logger.js';
3
- import { NO_TSDATA } from './messages.js';
4
- import { isEqual } from './utils.js';
5
- import { SIGNAL_METHOD_NAMES, MAX_CLASS_PARENT_DEPTH } from './constants.js';
6
- /**
7
- * Resolve conflicts between types caused by overloads / inheritances and implementations
8
- * With multiple implementations or a inherit it can happen that the interfaces / parent have the same method and/or property names with incompatible types,
9
- * we are trying to resolve this conflicts by merging, overloading or removing this conflicts.
10
- */
11
- export class ConflictResolver {
12
- log;
13
- girFactory = new GirFactory();
14
- constructor(verbose) {
15
- this.log = new Logger(verbose, 'ConflictResolver');
16
- }
17
- girElArrToChildArr(dataArr, depth) {
18
- return dataArr
19
- .filter((data) => !!data?._tsData)
20
- .map((data) => {
21
- if (!data?._tsData)
22
- throw new Error('_tsData not set!');
23
- return {
24
- depth,
25
- data: data?._tsData,
26
- };
27
- });
28
- }
29
- tsElArrToChildArr(dataArr, depth) {
30
- return dataArr
31
- .filter((m) => !!m)
32
- .map((data) => {
33
- return {
34
- depth,
35
- data,
36
- };
37
- });
38
- }
39
- /**
40
- * Get class elements and parent elements (implementations and inherits)
41
- * @param tsClass
42
- * @param depth
43
- * @returns
44
- */
45
- getClassElements(tsClass, depth, processedClasses) {
46
- const tsClassFullPackageSymName = `${tsClass.namespace}-${tsClass.version}.${tsClass.namespace}.${tsClass.name}`;
47
- const signalMethods = [];
48
- const propertySignalMethods = [];
49
- const methods = [];
50
- const virtualMethods = [];
51
- const staticFunctions = [];
52
- const constructors = [];
53
- const properties = [];
54
- const fields = [];
55
- const constructProps = [];
56
- const depthLimitReached = depth >= MAX_CLASS_PARENT_DEPTH;
57
- const classAlreadyProcessed = processedClasses.includes(tsClassFullPackageSymName);
58
- if (depthLimitReached || classAlreadyProcessed) {
59
- if (depthLimitReached) {
60
- this.log.error(`[getClassElements] Maximum recursion depth reached (limit: ${MAX_CLASS_PARENT_DEPTH})!`);
61
- }
62
- return {
63
- signalMethods,
64
- propertySignalMethods,
65
- methods,
66
- virtualMethods,
67
- staticFunctions,
68
- constructors,
69
- properties,
70
- fields,
71
- constructProps,
72
- };
73
- }
74
- // Signals
75
- const _signals = tsClass.signals.map((s) => s._tsData).filter((s) => !!s);
76
- for (const tsSignal of _signals) {
77
- signalMethods.push(...this.tsElArrToChildArr(tsSignal.tsMethods, depth));
78
- }
79
- // Property signals
80
- propertySignalMethods.push(...this.tsElArrToChildArr(tsClass.propertySignalMethods, depth));
81
- // Methods
82
- if (tsClass.methods.length)
83
- methods.push(...this.girElArrToChildArr(tsClass.methods, depth));
84
- // Virtual methods
85
- if (tsClass.virtualMethods.length)
86
- virtualMethods.push(...this.girElArrToChildArr(tsClass.virtualMethods, depth));
87
- // Static functions
88
- if (tsClass.staticFunctions.length)
89
- staticFunctions.push(...this.girElArrToChildArr(tsClass.staticFunctions, depth));
90
- // Constructors
91
- if (tsClass.constructors.length)
92
- constructors.push(...this.girElArrToChildArr(tsClass.constructors, depth));
93
- // Properties
94
- if (tsClass.properties.length)
95
- properties.push(...this.girElArrToChildArr(tsClass.properties, depth));
96
- // Fields
97
- if (tsClass.fields.length)
98
- fields.push(...this.girElArrToChildArr(tsClass.fields, depth));
99
- // Constructor properties
100
- if (tsClass.constructProps.length)
101
- constructProps.push(...this.girElArrToChildArr(tsClass.constructProps, depth));
102
- for (const ifacePackageFullSymName of Object.keys(tsClass.implements)) {
103
- if (tsClassFullPackageSymName === ifacePackageFullSymName) {
104
- this.log.warn("[getImplementedInterfaceElements] A interface can't implement itself");
105
- continue;
106
- }
107
- const { interface: implementation, depth: parentDepth } = tsClass.implements[ifacePackageFullSymName];
108
- const implementationElements = this.getClassElements(implementation, parentDepth + depth + 1, processedClasses);
109
- signalMethods.push(...implementationElements.signalMethods);
110
- propertySignalMethods.push(...implementationElements.propertySignalMethods);
111
- methods.push(...implementationElements.methods);
112
- virtualMethods.push(...implementationElements.virtualMethods);
113
- staticFunctions.push(...implementationElements.staticFunctions);
114
- constructors.push(...implementationElements.constructors);
115
- properties.push(...implementationElements.properties);
116
- fields.push(...implementationElements.fields);
117
- constructProps.push(...implementationElements.constructProps);
118
- }
119
- for (const ifaceFullPackageSymName of Object.keys(tsClass.inherit)) {
120
- if (tsClassFullPackageSymName === ifaceFullPackageSymName) {
121
- this.log.warn("[getClassElements] A class can't inherit itself");
122
- continue;
123
- }
124
- const { class: inherit, depth: parentDepth } = tsClass.inherit[ifaceFullPackageSymName];
125
- const inheritElements = this.getClassElements(inherit, parentDepth + depth + 1, processedClasses);
126
- signalMethods.push(...inheritElements.signalMethods);
127
- propertySignalMethods.push(...inheritElements.propertySignalMethods);
128
- methods.push(...inheritElements.methods);
129
- virtualMethods.push(...inheritElements.virtualMethods);
130
- staticFunctions.push(...inheritElements.staticFunctions);
131
- constructors.push(...inheritElements.constructors);
132
- properties.push(...inheritElements.properties);
133
- fields.push(...inheritElements.fields);
134
- constructProps.push(...inheritElements.constructProps);
135
- }
136
- processedClasses.push(tsClassFullPackageSymName);
137
- return {
138
- signalMethods,
139
- propertySignalMethods,
140
- methods,
141
- virtualMethods,
142
- staticFunctions,
143
- constructors,
144
- properties,
145
- fields,
146
- constructProps,
147
- };
148
- }
149
- tsElementIsSignal(el) {
150
- return el.tsTypeName === 'event-methods';
151
- }
152
- tsElementIsConstructor(el) {
153
- return el.tsTypeName === 'constructor';
154
- }
155
- tsElementIsMethodOrFunction(el) {
156
- return el.tsTypeName === 'function' || el.tsTypeName === 'method' || el.tsTypeName === 'static-function';
157
- }
158
- tsElementIsPropertyOrVariable(el) {
159
- return (el.tsTypeName === 'constant' ||
160
- el.tsTypeName === 'constructor-property' ||
161
- el.tsTypeName === 'property' ||
162
- el.tsTypeName === 'static-property');
163
- }
164
- tsElementIsStatic(el) {
165
- return (
166
- // el.tsTypeName === 'constructor' ||
167
- el.isStatic || el.tsTypeName === 'static-property' || el.tsTypeName === 'static-function');
168
- }
169
- tsTypeIsEqual(a, b) {
170
- return (a &&
171
- b &&
172
- a.optional === b.optional &&
173
- a.nullable === b.nullable &&
174
- a.type === b.type &&
175
- a.isArray === b.isArray &&
176
- a.isFunction === b.isFunction &&
177
- a.isCallback === b.isCallback &&
178
- a.leftSeparator === b.leftSeparator &&
179
- isEqual(a.callbacks, b.callbacks) &&
180
- isEqual(a.generics, b.generics));
181
- }
182
- mergeTypes(leftSeparator, ...types) {
183
- const dest = [];
184
- for (const type of types) {
185
- if (!type)
186
- continue;
187
- if (!dest.find((destType) => this.tsTypeIsEqual(destType, type))) {
188
- dest.push({ ...type, leftSeparator });
189
- }
190
- }
191
- return dest;
192
- }
193
- /**
194
- * Merge property types together
195
- * @param baseProp The property to change or null if you want to create a new property
196
- * @param props The properties you want to merge
197
- * @returns
198
- */
199
- mergeProperties(typeSeparator, baseProp, ...props) {
200
- const typesMap = [];
201
- for (const prop of props) {
202
- typesMap.push(...prop.type);
203
- }
204
- const types = this.mergeTypes(typeSeparator, ...typesMap);
205
- // Merge readonly
206
- let readonly = false;
207
- for (const prop of props) {
208
- readonly = readonly || prop.readonly || false;
209
- }
210
- if (!props[0] || !props[0].name) {
211
- throw new Error('At least one property to merge must exist!');
212
- }
213
- if (baseProp) {
214
- baseProp.type = types;
215
- baseProp.readonly = readonly;
216
- return baseProp;
217
- }
218
- const newProp = this.girFactory.newTsProperty({
219
- readonly: readonly,
220
- isStatic: props[0].isStatic || false,
221
- name: props[0].name,
222
- type: types,
223
- girTypeName: props[0].girTypeName,
224
- });
225
- return newProp;
226
- }
227
- /**
228
- * Check if there is a type conflict between the ts elements a and b
229
- * @param a
230
- * @param b
231
- * @returns
232
- */
233
- hasConflict(a, b) {
234
- if (a !== b && a.data.name === b.data.name) {
235
- const name = a.data.name;
236
- // Ignore element with name of:
237
- if (name === 'constructor' || name === '_init') {
238
- return false;
239
- }
240
- if (this.elementHasConflict(a.data, b.data)) {
241
- return true;
242
- }
243
- }
244
- return false;
245
- }
246
- newAnyTsProperty(name, girTypeName) {
247
- return this.girFactory.newTsProperty({
248
- name,
249
- girTypeName,
250
- type: [{ type: 'any' }],
251
- });
252
- }
253
- /**
254
- * Returns a new any function: `name(...args: any[]): any`
255
- * @param name The name of the function
256
- */
257
- newAnyTsFunction(name, girTypeName, isStatic, parent) {
258
- return this.girFactory.newTsFunction({
259
- name,
260
- isStatic,
261
- inParams: [
262
- {
263
- name: 'args',
264
- isRest: true,
265
- type: [this.girFactory.newTsType({ type: 'any', isArray: true })],
266
- },
267
- ],
268
- returnTypes: [{ type: 'any' }],
269
- girTypeName,
270
- }, parent);
271
- }
272
- getCompatibleTsProperty(elements, baseProp) {
273
- return elements.find((prop) => !this.propertyHasConflict(baseProp, prop));
274
- }
275
- getCompatibleTsFunction(elements, baseFunc) {
276
- return elements.find((func) => !this.functionHasConflict(baseFunc, func));
277
- }
278
- /**
279
- * Use this instead of `getCompatibleTsProperty` and `getCompatibleTsProperty` if you can, because it's much faster
280
- * @param elements
281
- * @param name
282
- * @returns
283
- */
284
- getTsElementByName(elements, name) {
285
- return elements.find((el) => el.name === name);
286
- }
287
- canAddConflictProperty(conflictProperties, prop) {
288
- const canAdd = prop.name &&
289
- // Only one property can be defined, no overloads
290
- !this.getTsElementByName(conflictProperties, prop.name) &&
291
- // Do not set properties with signal method names
292
- !SIGNAL_METHOD_NAMES.includes(prop.name);
293
- return canAdd;
294
- }
295
- /**
296
- * Check conflicts between the implementations / inheritances
297
- * To fix type errors like:
298
- * ```
299
- * Interface 'PopoverMenu' can\'t simultaneously extend types 'Popover' and 'Native'.
300
- * Named property 'parent' of types 'Popover' and 'Native' are not identical.
301
- */
302
- fixIndirectConflicts(name, elements, baseClass) {
303
- for (const base of elements) {
304
- if (base.data.hasUnresolvedConflict) {
305
- continue;
306
- }
307
- for (const b of elements) {
308
- if (b === base || b.data.hasUnresolvedConflict) {
309
- continue;
310
- }
311
- const className = `${baseClass.namespace}-${baseClass.version}.${baseClass.name}`;
312
- // If a element is a function / method
313
- if (this.tsElementIsMethodOrFunction(base.data)) {
314
- const baseFunc = base.data;
315
- // Function vs. Property
316
- if (this.tsElementIsPropertyOrVariable(b.data)) {
317
- this.log.debug(`${className}.${name} External Function vs. Property`, baseFunc, b.data);
318
- b.data.hasUnresolvedConflict = true;
319
- }
320
- // Function vs. Signal
321
- else if (this.tsElementIsSignal(b.data)) {
322
- this.log.debug(`${className}.${name} External Function vs. Signal`, baseFunc, b.data);
323
- baseFunc.hasUnresolvedConflict = true;
324
- }
325
- // Function vs. Function
326
- else if (this.tsElementIsMethodOrFunction(b.data)) {
327
- const bFunc = b.data;
328
- this.log.debug(`${className}.${name} External Function vs. Function`, baseFunc.inParams.map((p) => p._tsData?.name).join(', '), bFunc.inParams.map((p) => p._tsData?.name).join(', '));
329
- // Just add conflicting methods to the class
330
- if (!baseClass.conflictMethods.includes(baseFunc)) {
331
- baseClass.conflictMethods.push(baseFunc);
332
- }
333
- if (!baseClass.conflictMethods.includes(bFunc)) {
334
- baseClass.conflictMethods.push(bFunc);
335
- }
336
- }
337
- // Function vs. Constructor
338
- else if (this.tsElementIsConstructor(base.data)) {
339
- const bConstr = b.data;
340
- this.log.debug(`${className}.${name} External Function vs. Constructor`, baseFunc, bConstr);
341
- // Just add conflicting methods to the class
342
- if (!baseClass.conflictMethods.includes(baseFunc)) {
343
- baseClass.conflictMethods.push(baseFunc);
344
- }
345
- if (!baseClass.conflictMethods.includes(bConstr)) {
346
- baseClass.conflictMethods.push(bConstr);
347
- }
348
- }
349
- // Function vs. Unknown
350
- else {
351
- this.log.debug(`${className}.${name} External Unknown ${b.data.tsTypeName}`, baseFunc, b.data);
352
- baseFunc.hasUnresolvedConflict = true;
353
- }
354
- }
355
- // If a element is a constructor
356
- else if (this.tsElementIsConstructor(base.data)) {
357
- const baseConstr = base.data;
358
- // Constructor vs. Function
359
- if (this.tsElementIsMethodOrFunction(b.data)) {
360
- const bFunc = b.data;
361
- this.log.debug(`${className}.${name} External Constructor vs. Function`, baseConstr.inParams.map((p) => p._tsData?.name).join(', '), bFunc.inParams.map((p) => p._tsData?.name).join(', '));
362
- if (!baseClass.conflictMethods.includes(baseConstr)) {
363
- baseClass.conflictMethods.push(baseConstr);
364
- }
365
- if (!baseClass.conflictMethods.includes(bFunc)) {
366
- baseClass.conflictMethods.push(bFunc);
367
- }
368
- }
369
- // Constructor vs. Constructor
370
- else if (this.tsElementIsConstructor(base.data)) {
371
- this.log.debug(`${className}.${name} External Constructor vs. Constructor`, baseConstr, b.data);
372
- const anyFunc = this.newAnyTsFunction(name, baseConstr.girTypeName, baseConstr.isStatic, baseConstr.parent);
373
- // Check if any function is not already added
374
- if (!this.getTsElementByName(baseClass.conflictMethods, anyFunc.name)) {
375
- baseClass.conflictMethods.push(anyFunc);
376
- }
377
- }
378
- }
379
- // If a element is a property / variable
380
- else if (this.tsElementIsPropertyOrVariable(base.data)) {
381
- const baseProp = base.data;
382
- // Property vs. Function
383
- if (this.tsElementIsMethodOrFunction(b.data)) {
384
- const bFunc = b.data;
385
- this.log.debug(`${className}.${name} External Property vs. Function`, baseProp.type[0].type, bFunc);
386
- baseProp.hasUnresolvedConflict = true;
387
- }
388
- // Property vs. Property
389
- else if (this.tsElementIsPropertyOrVariable(b.data)) {
390
- const bProp = b.data;
391
- this.log.debug(`${className}.${name} External Property vs. Property`, baseProp.type[0].type, bProp.type[0].type);
392
- switch (name) {
393
- case 'parent':
394
- case 'window':
395
- case 'parent_instance':
396
- case 'priv':
397
- const mergedProp = this.mergeProperties('&', null, baseProp, bProp);
398
- if (this.canAddConflictProperty(baseClass.conflictProperties, mergedProp)) {
399
- baseClass.conflictProperties.push(mergedProp);
400
- }
401
- break;
402
- default:
403
- const anyProp = this.newAnyTsProperty(name, baseProp.girTypeName);
404
- if (this.canAddConflictProperty(baseClass.conflictProperties, anyProp)) {
405
- baseClass.conflictProperties.push(anyProp);
406
- }
407
- break;
408
- }
409
- }
410
- // Property vs. Signal
411
- else if (this.tsElementIsSignal(b.data)) {
412
- this.log.debug(`${className}.${name} External Property vs. Signal`, baseProp, b.data);
413
- base.data.hasUnresolvedConflict = true;
414
- }
415
- else {
416
- this.log.error(`${className}.${name} External Unknown ${b.data.tsTypeName}`, baseProp, b.data);
417
- }
418
- }
419
- // Other
420
- else {
421
- this.log.error(`${className}.${name} External Unknown ${base.data.tsTypeName}`);
422
- base.data.hasUnresolvedConflict = true;
423
- }
424
- }
425
- }
426
- }
427
- /**
428
- * Check conflicts within the class itself (ignores implementations / inheritances)
429
- */
430
- fixInternalConflicts(name, elements, baseClass) {
431
- for (const base of elements) {
432
- if (base.data.hasUnresolvedConflict) {
433
- continue;
434
- }
435
- for (const b of elements) {
436
- if (b === base || b.data.hasUnresolvedConflict) {
437
- continue;
438
- }
439
- const className = `${baseClass.namespace}-${baseClass.version}.${baseClass.name}`;
440
- // Conflict between injected and original elements
441
- if (base.data.isInjected !== b.data.isInjected) {
442
- if (!base.data.isInjected) {
443
- base.data.hasUnresolvedConflict = true;
444
- }
445
- else if (!b.data.isInjected) {
446
- b.data.hasUnresolvedConflict = true;
447
- }
448
- // Copy doc from original element if not set in the injected element
449
- if (!b.data.doc.text && base.data.doc.text) {
450
- b.data.doc = base.data.doc;
451
- }
452
- else if (!base.data.doc.text && b.data.doc.text) {
453
- base.data.doc = b.data.doc;
454
- }
455
- continue;
456
- }
457
- // If a element is a function / method
458
- if (this.tsElementIsMethodOrFunction(base.data)) {
459
- const baseFunc = base.data;
460
- // Function vs. Property
461
- if (this.tsElementIsPropertyOrVariable(b.data)) {
462
- this.log.debug(`${className}.${name} Internal Function vs. Property`, baseFunc, b.data);
463
- b.data.hasUnresolvedConflict = true;
464
- }
465
- // Function vs. Signal
466
- else if (this.tsElementIsSignal(b.data)) {
467
- this.log.debug(`${className}.${name} Internal Function vs. Signal`, baseFunc, b.data);
468
- // Do nothing
469
- }
470
- // Function vs. Function
471
- else if (this.tsElementIsMethodOrFunction(b.data)) {
472
- const bFunc = b.data;
473
- this.log.debug(`${className}.${name} Internal Function vs. Function`, baseFunc.inParams.map((p) => p._tsData?.name).join(', '), bFunc.inParams.map((p) => p._tsData?.name).join(', '));
474
- // Conflict between virtual and non-virtual methods (this should only occur in node-gtk, because Gjs has a vfunc_ prefix for virtual methods)
475
- if (baseFunc.isVirtual !== bFunc.isVirtual) {
476
- if (!baseFunc.isVirtual) {
477
- baseFunc.hasUnresolvedConflict = true;
478
- }
479
- else {
480
- bFunc.hasUnresolvedConflict = true;
481
- }
482
- continue;
483
- }
484
- // Do nothing..
485
- }
486
- else {
487
- this.log.error(`${className}.${name} Internal Unknown ${b.data.tsTypeName}`, baseFunc, b.data);
488
- b.data.hasUnresolvedConflict = true;
489
- }
490
- }
491
- // If a element is a property / variable
492
- else if (this.tsElementIsPropertyOrVariable(base.data)) {
493
- const baseProp = base.data;
494
- // Property vs. Function
495
- if (this.tsElementIsMethodOrFunction(b.data)) {
496
- const bFunc = b.data;
497
- this.log.debug(`${className}.${name} Internal Property vs. Function`, baseProp.type[0].type, bFunc);
498
- baseProp.hasUnresolvedConflict = true;
499
- }
500
- // Property vs. Property
501
- else if (this.tsElementIsPropertyOrVariable(b.data)) {
502
- const bProp = b.data;
503
- this.log.debug(`${className}.${name} Internal Property vs. Property`, baseProp.type[0].type, bProp.type[0].type);
504
- switch (name) {
505
- case 'parent':
506
- case 'window':
507
- case 'parent_instance':
508
- this.mergeProperties('&', baseProp, baseProp, bProp);
509
- break;
510
- default:
511
- // Set property type to any
512
- baseProp.type = [this.girFactory.newTsType({ ...bProp.type, type: 'any' })];
513
- break;
514
- }
515
- }
516
- // Property vs. Signal
517
- else if (this.tsElementIsSignal(b.data)) {
518
- this.log.debug(`${className}.${name} Internal Property vs. Signal`, baseProp, b.data);
519
- base.data.hasUnresolvedConflict = true;
520
- }
521
- else {
522
- this.log.error(`${className}.${name} Internal Unknown ${b.data.tsTypeName}`, baseProp, b.data);
523
- }
524
- }
525
- // If a element is a signal
526
- else if (this.tsElementIsSignal(base.data)) {
527
- const baseSig = base.data;
528
- // Signal vs. Function
529
- if (this.tsElementIsMethodOrFunction(b.data)) {
530
- this.log.debug(`${className}.${name} Internal Signal vs. Function`, baseSig, b.data);
531
- // Do nothing
532
- }
533
- // Signal vs. Property
534
- else if (this.tsElementIsPropertyOrVariable(b.data)) {
535
- this.log.debug(`${className}.${name} Internal Signal vs. Property`, baseSig, b.data);
536
- b.data.hasUnresolvedConflict = true;
537
- }
538
- }
539
- // Other
540
- else {
541
- this.log.error(`${className}.${name} Internal Unknown ${base.data.tsTypeName}`);
542
- }
543
- }
544
- }
545
- }
546
- /**
547
- * Check conflicts of the class with implementations and inheritances
548
- */
549
- fixDirectConflicts(name, elements) {
550
- const className = `${elements.baseClass.namespace}-${elements.baseClass.version}.${elements.baseClass.name}`;
551
- for (const base of elements.baseElements) {
552
- if (base.data.hasUnresolvedConflict) {
553
- continue;
554
- }
555
- // Each conflicting elements
556
- for (const b of elements.inheritedElements) {
557
- if (b === base || b.data.hasUnresolvedConflict) {
558
- continue;
559
- }
560
- // If base element is a function
561
- if (this.tsElementIsMethodOrFunction(base.data)) {
562
- const baseFunc = base.data;
563
- // Function vs. Function
564
- if (this.tsElementIsMethodOrFunction(b.data)) {
565
- const bFunc = b.data;
566
- this.log.debug(`${className}.${name} Direct Function vs. Function`, baseFunc.inParams.map((p) => p._tsData?.name).join(', '), bFunc.inParams.map((p) => p._tsData?.name).join(', '));
567
- // Add a function to overload methods if there is not already a compatible version
568
- if (!baseFunc.overloads.includes(bFunc) &&
569
- !this.getCompatibleTsFunction(baseFunc.overloads, bFunc)) {
570
- baseFunc.overloads.push(bFunc);
571
- }
572
- }
573
- // Function vs. Constructor
574
- else if (this.tsElementIsConstructor(b.data)) {
575
- const bConstr = b.data;
576
- this.log.debug(`${className}.${name} Direct Function vs. Constructor`, baseFunc.inParams.map((p) => p._tsData?.name).join(', '), bConstr.inParams.map((p) => p._tsData?.name).join(', '));
577
- // Add a function to overload methods if there is not already a compatible version
578
- if (!this.getCompatibleTsFunction(baseFunc.overloads, bConstr)) {
579
- baseFunc.overloads.push(bConstr);
580
- }
581
- }
582
- // Function vs. Property
583
- else if (this.tsElementIsPropertyOrVariable(b.data)) {
584
- this.log.debug(`${className}.${name} Direct Function vs. Property`);
585
- b.data.hasUnresolvedConflict = true;
586
- }
587
- // Function vs. Signal
588
- else if (this.tsElementIsSignal(b.data)) {
589
- this.log.debug(`${className}.${name} Direct Function vs. Signal`);
590
- // Do nothing
591
- }
592
- }
593
- // If base element is a property / variable
594
- else if (this.tsElementIsPropertyOrVariable(base.data)) {
595
- const baseProp = base.data;
596
- // Property vs. Property
597
- if (this.tsElementIsPropertyOrVariable(b.data)) {
598
- const bProp = b.data;
599
- this.log.debug(`${className}.${name} Direct Property vs. Property`, baseProp.type[0].type, bProp.type[0].type);
600
- switch (name) {
601
- case 'parent':
602
- case 'window':
603
- case 'parent_instance':
604
- this.mergeProperties('&', baseProp, baseProp, bProp);
605
- break;
606
- default:
607
- // Set property type to any
608
- baseProp.type = [this.girFactory.newTsType({ ...bProp.type, type: 'any' })];
609
- break;
610
- }
611
- }
612
- // Property vs. Function
613
- else if (this.tsElementIsMethodOrFunction(b.data)) {
614
- this.log.debug(`${className}.${name} Direct Property vs. Function`);
615
- baseProp.hasUnresolvedConflict = true;
616
- }
617
- // Property vs. Signal
618
- else if (this.tsElementIsSignal(b.data)) {
619
- this.log.debug(`${className}.${name} Direct Property vs. Signal`);
620
- baseProp.hasUnresolvedConflict = true;
621
- }
622
- }
623
- // If base element is a signal method
624
- else if (this.tsElementIsSignal(base.data)) {
625
- // Signal vs. Property
626
- if (this.tsElementIsPropertyOrVariable(b.data)) {
627
- this.log.debug(`${className}.${name} Direct Signal vs. Property`);
628
- b.data.hasUnresolvedConflict = true;
629
- }
630
- // Signal vs. Function
631
- if (this.tsElementIsMethodOrFunction(b.data)) {
632
- this.log.debug(`${className}.${name} Direct Signal vs. Function`);
633
- const bFunc = b.data;
634
- const baseSignal = base.data;
635
- // Add parent class incompatible method as overload
636
- if (!this.getCompatibleTsFunction(baseSignal.overloads, bFunc)) {
637
- baseSignal.overloads.push(bFunc);
638
- }
639
- }
640
- }
641
- // If a element is a constructor
642
- else if (this.tsElementIsConstructor(base.data)) {
643
- const baseConstr = base.data;
644
- // Constructor vs. Function
645
- if (this.tsElementIsMethodOrFunction(b.data)) {
646
- const bFunc = b.data;
647
- this.log.debug(`${className}.${name} Direct Constructor vs. Function`, baseConstr.inParams.map((p) => p._tsData?.name).join(', '), bFunc.inParams.map((p) => p._tsData?.name).join(', '));
648
- // Add a function to overload methods if there is not already a compatible version
649
- if (!this.getCompatibleTsFunction(baseConstr.overloads, bFunc)) {
650
- baseConstr.overloads.push(bFunc);
651
- }
652
- }
653
- // Constructor vs. Constructor
654
- else if (this.tsElementIsConstructor(base.data)) {
655
- const bConstr = b.data;
656
- this.log.debug(`${className}.${name} Direct Constructor vs. Constructor`, baseConstr, bConstr);
657
- // Add the constructor to overload methods if there is not already a compatible version
658
- if (!this.getCompatibleTsFunction(baseConstr.overloads, bConstr)) {
659
- baseConstr.overloads.push(bConstr);
660
- }
661
- }
662
- }
663
- else {
664
- this.log.warn(`{className}.${name} Unknown ${base.data.tsTypeName}`, base);
665
- base.data.hasUnresolvedConflict = true;
666
- }
667
- }
668
- }
669
- }
670
- /**
671
- * Fix the conflicts of a class
672
- * @param groupedElements
673
- */
674
- fixConflicts(groupedElements) {
675
- for (const key of Object.keys(groupedElements)) {
676
- const elements = groupedElements[key];
677
- // Remove the key prefix `_`
678
- const name = key.substring(1);
679
- if (elements.baseElements.length === 0) {
680
- this.fixIndirectConflicts(name, elements.inheritedElements, elements.baseClass);
681
- }
682
- this.fixInternalConflicts(name, elements.baseElements, elements.baseClass);
683
- this.fixDirectConflicts(name, elements);
684
- }
685
- }
686
- /**
687
- * Group conflicts by name and sort them by depth for simpler handling of conflicts
688
- */
689
- groupConflicts(elements, tsClass) {
690
- const groupedConflicts = {};
691
- const IGNORE_CONFLICT_NAMES = ['$gtype', '__gtype__'];
692
- for (const a of elements) {
693
- const name = a.data.name;
694
- for (const b of elements) {
695
- if (a === b ||
696
- !name ||
697
- !b.data.name ||
698
- IGNORE_CONFLICT_NAMES.includes(name) ||
699
- IGNORE_CONFLICT_NAMES.includes(b.data.name)) {
700
- continue;
701
- }
702
- if (a && name && b && b.data.name && a !== b && this.hasConflict(a, b)) {
703
- const key = `_${name}`; // if the key would be `toString` this would be always true so we prefix `_`
704
- groupedConflicts[key] ||= {
705
- baseElements: [],
706
- inheritedElements: [],
707
- baseClass: tsClass,
708
- };
709
- const groupedConflict = groupedConflicts[key];
710
- const isBaseElement = a.depth === 0;
711
- if (isBaseElement) {
712
- if (!groupedConflict.baseElements.find((c) => isEqual(c.data, a.data))) {
713
- groupedConflict.baseElements.push(a);
714
- }
715
- }
716
- else {
717
- if (!groupedConflict.baseElements.find((c) => isEqual(c.data, a.data)) &&
718
- !groupedConflict.inheritedElements.find((c) => isEqual(c.data, a.data))) {
719
- groupedConflict.inheritedElements.push(a);
720
- }
721
- }
722
- }
723
- }
724
- }
725
- // Sort by depth
726
- for (const key of Object.keys(groupedConflicts)) {
727
- groupedConflicts[key].inheritedElements = groupedConflicts[key].inheritedElements.sort((a, b) => a.depth - b.depth);
728
- }
729
- return groupedConflicts;
730
- }
731
- /**
732
- * With multiple implementations or a inherit it can happen that the interfaces / parent have the same method and/or property name with incompatible types.
733
- * We merge these types here to solve this problem.
734
- * @param girClass
735
- */
736
- repairClass(girClass) {
737
- if (!girClass._tsData)
738
- throw new Error(NO_TSDATA('repairClass'));
739
- const classElements = this.getClassElements(girClass._tsData, 0, []);
740
- // Do not pass a reference of the array here
741
- const elements = [
742
- ...classElements.signalMethods,
743
- ...classElements.propertySignalMethods,
744
- ...classElements.methods,
745
- ...classElements.virtualMethods,
746
- ...classElements.staticFunctions,
747
- ...classElements.constructors,
748
- ...classElements.properties,
749
- ...classElements.fields,
750
- ];
751
- const groupedElementConflicts = this.groupConflicts(elements, girClass._tsData);
752
- const groupedConstructPropConflicts = this.groupConflicts(classElements.constructProps, girClass._tsData);
753
- this.fixConflicts(groupedElementConflicts);
754
- this.fixConflicts(groupedConstructPropConflicts);
755
- return girClass;
756
- }
757
- /**
758
- * Returns true if `p1s` and `p2s` conflicting with each other.
759
- * The parameters must have the same length and the same type but can have different names
760
- * @param params
761
- * @returns
762
- */
763
- paramsHasConflict(...params) {
764
- let conflict = false;
765
- for (const p1s of params) {
766
- for (const p2s of params) {
767
- if (p1s.length !== p2s.length) {
768
- conflict = true;
769
- return conflict;
770
- }
771
- for (const [i, p1] of p1s.entries()) {
772
- const p2 = p2s[i];
773
- if (p2._tsData && p1._tsData) {
774
- if (this.typesHasConflict(p2._tsData?.type, p1._tsData?.type)) {
775
- conflict = true;
776
- return conflict;
777
- }
778
- }
779
- else {
780
- conflict = true;
781
- return conflict;
782
- }
783
- }
784
- }
785
- }
786
- return conflict;
787
- }
788
- typesHasConflict(a, b) {
789
- if (a.length !== b.length) {
790
- return true;
791
- }
792
- // return !isEqual(a, b.data)
793
- for (let i = 0; i < a.length; i++) {
794
- const aType = a[i];
795
- const bType = b[i];
796
- if (aType.type !== bType.type ||
797
- aType.nullable !== bType.nullable ||
798
- aType.optional !== bType.optional ||
799
- aType.isFunction !== bType.isFunction ||
800
- aType.isCallback !== bType.isCallback ||
801
- aType.isArray !== bType.isArray ||
802
- aType.callbacks.length !== bType.callbacks.length ||
803
- aType.generics.length !== bType.generics.length ||
804
- !isEqual(aType.callbacks, bType.callbacks) ||
805
- !isEqual(aType.generics, bType.generics) ||
806
- !isEqual(aType, bType) // TODO
807
- ) {
808
- return true;
809
- }
810
- }
811
- return false;
812
- }
813
- /**
814
- * Returns `true` if the function / method types of `a` and `b` are not compatible with each other.
815
- * The parameters must have the same length and the same type but can have different names
816
- * @param a
817
- * @param b
818
- * @returns
819
- */
820
- functionHasConflict(a, b) {
821
- // TODO find a better solution for that, not all this methods are conflicting
822
- if (a.isVirtual !== b.isVirtual) {
823
- return true;
824
- }
825
- if (this.typesHasConflict(a.returnTypes, b.returnTypes)) {
826
- return true;
827
- }
828
- if (this.paramsHasConflict(a.inParams, b.inParams)) {
829
- return true;
830
- }
831
- if (this.paramsHasConflict(a.outParams, b.outParams)) {
832
- return true;
833
- }
834
- return false;
835
- }
836
- /**
837
- * Returns `true` if the property types of `a` and `b` are not compatible with each other.
838
- * @param a
839
- * @param b
840
- * @returns
841
- */
842
- propertyHasConflict(a, b) {
843
- if (!!a.isStatic !== !!b.isStatic)
844
- return false;
845
- if (a.name !== b.name)
846
- return false;
847
- if (!!a.readonly !== !!b.readonly || this.typesHasConflict(a.type, b.type))
848
- return true;
849
- return false;
850
- }
851
- signalHasConflict(a, b) {
852
- if (!!a.isStatic !== !!b.isStatic)
853
- return false;
854
- if (a.name !== b.name)
855
- return false;
856
- // TODO
857
- return false;
858
- }
859
- /**
860
- * Returns true if the elements (properties or methods) of `a` and `b` are not compatible with each other (has no conflict).
861
- * @param a
862
- * @param b
863
- * @returns
864
- */
865
- elementHasConflict(a, b) {
866
- if (a.name !== b.name) {
867
- return false;
868
- }
869
- else if (this.tsElementIsStatic(a) !== this.tsElementIsStatic(b)) {
870
- return false;
871
- }
872
- else if (this.tsElementIsMethodOrFunction(a) && this.tsElementIsMethodOrFunction(b)) {
873
- return this.functionHasConflict(a, b);
874
- }
875
- else if (this.tsElementIsPropertyOrVariable(a) && this.tsElementIsPropertyOrVariable(b)) {
876
- return this.propertyHasConflict(a, b);
877
- }
878
- else if (this.tsElementIsConstructor(a) && this.tsElementIsConstructor(b)) {
879
- return this.functionHasConflict(a, b);
880
- }
881
- else if (this.tsElementIsSignal(a) && this.tsElementIsSignal(b)) {
882
- // TODO
883
- return this.signalHasConflict(a, b);
884
- }
885
- else if (a.tsTypeName !== b.tsTypeName) {
886
- return true;
887
- }
888
- else {
889
- return true;
890
- }
891
- }
892
- }
893
- //# sourceMappingURL=conflict-resolver.js.map