@ts-for-gir/cli 3.0.0-beta.8 → 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.
Files changed (672) hide show
  1. package/README.md +429 -49
  2. package/lib/commands/doc.d.ts +1 -17
  3. package/lib/commands/doc.js +7 -13
  4. package/lib/commands/doc.js.map +1 -1
  5. package/lib/commands/generate.d.ts +1 -39
  6. package/lib/commands/generate.js +8 -25
  7. package/lib/commands/generate.js.map +1 -1
  8. package/lib/commands/list.d.ts +1 -11
  9. package/lib/commands/list.js +6 -10
  10. package/lib/commands/list.js.map +1 -1
  11. package/lib/config.d.ts +25 -11
  12. package/lib/config.js +194 -112
  13. package/lib/config.js.map +1 -1
  14. package/lib/generation-handler.d.ts +3 -4
  15. package/lib/generation-handler.js +8 -12
  16. package/lib/generation-handler.js.map +1 -1
  17. package/lib/index.d.ts +0 -12
  18. package/lib/index.js +0 -12
  19. package/lib/index.js.map +1 -1
  20. package/lib/module-loader.d.ts +41 -27
  21. package/lib/module-loader.js +54 -56
  22. package/lib/module-loader.js.map +1 -1
  23. package/lib/utils.d.ts +13 -86
  24. package/lib/utils.js +13 -194
  25. package/lib/utils.js.map +1 -1
  26. package/package.json +32 -37
  27. package/src/commands/doc.ts +9 -14
  28. package/src/commands/generate.ts +10 -25
  29. package/src/commands/list.ts +8 -10
  30. package/src/config.ts +211 -115
  31. package/src/generation-handler.ts +12 -13
  32. package/src/index.ts +0 -12
  33. package/src/module-loader.ts +88 -75
  34. package/src/utils.ts +12 -222
  35. package/lib/conflict-resolver.d.ts +0 -155
  36. package/lib/conflict-resolver.js +0 -1103
  37. package/lib/conflict-resolver.js.map +0 -1
  38. package/lib/constants.d.ts +0 -18
  39. package/lib/constants.js +0 -23
  40. package/lib/constants.js.map +0 -1
  41. package/lib/generator.d.ts +0 -5
  42. package/lib/generator.js +0 -2
  43. package/lib/generator.js.map +0 -1
  44. package/lib/gir-factory.d.ts +0 -51
  45. package/lib/gir-factory.js +0 -361
  46. package/lib/gir-factory.js.map +0 -1
  47. package/lib/gir-module.d.ts +0 -256
  48. package/lib/gir-module.js +0 -2075
  49. package/lib/gir-module.js.map +0 -1
  50. package/lib/html-doc-generator.d.ts +0 -13
  51. package/lib/html-doc-generator.js +0 -18
  52. package/lib/html-doc-generator.js.map +0 -1
  53. package/lib/injection/callbacks/gjs/Gio-2.0.d.ts +0 -2
  54. package/lib/injection/callbacks/gjs/Gio-2.0.js +0 -36
  55. package/lib/injection/callbacks/gjs/Gio-2.0.js.map +0 -1
  56. package/lib/injection/callbacks/gjs/index.d.ts +0 -2
  57. package/lib/injection/callbacks/gjs/index.js +0 -3
  58. package/lib/injection/callbacks/gjs/index.js.map +0 -1
  59. package/lib/injection/callbacks/index.d.ts +0 -4
  60. package/lib/injection/callbacks/index.js +0 -4
  61. package/lib/injection/callbacks/index.js.map +0 -1
  62. package/lib/injection/callbacks/node-gtk/index.d.ts +0 -2
  63. package/lib/injection/callbacks/node-gtk/index.js +0 -2
  64. package/lib/injection/callbacks/node-gtk/index.js.map +0 -1
  65. package/lib/injection/classes/GLib-2-0.d.ts +0 -2
  66. package/lib/injection/classes/GLib-2-0.js +0 -35
  67. package/lib/injection/classes/GLib-2-0.js.map +0 -1
  68. package/lib/injection/classes/gjs/GLib-2.0.d.ts +0 -2
  69. package/lib/injection/classes/gjs/GLib-2.0.js +0 -200
  70. package/lib/injection/classes/gjs/GLib-2.0.js.map +0 -1
  71. package/lib/injection/classes/gjs/GObject-2.0.d.ts +0 -2
  72. package/lib/injection/classes/gjs/GObject-2.0.js +0 -634
  73. package/lib/injection/classes/gjs/GObject-2.0.js.map +0 -1
  74. package/lib/injection/classes/gjs/Gio-2.0.d.ts +0 -5
  75. package/lib/injection/classes/gjs/Gio-2.0.js +0 -218
  76. package/lib/injection/classes/gjs/Gio-2.0.js.map +0 -1
  77. package/lib/injection/classes/gjs/index.d.ts +0 -2
  78. package/lib/injection/classes/gjs/index.js +0 -5
  79. package/lib/injection/classes/gjs/index.js.map +0 -1
  80. package/lib/injection/classes/index.d.ts +0 -4
  81. package/lib/injection/classes/index.js +0 -5
  82. package/lib/injection/classes/index.js.map +0 -1
  83. package/lib/injection/classes/node-gtk/GLib-2.0.d.ts +0 -2
  84. package/lib/injection/classes/node-gtk/GLib-2.0.js +0 -19
  85. package/lib/injection/classes/node-gtk/GLib-2.0.js.map +0 -1
  86. package/lib/injection/classes/node-gtk/GObject-2.0.d.ts +0 -2
  87. package/lib/injection/classes/node-gtk/GObject-2.0.js +0 -66
  88. package/lib/injection/classes/node-gtk/GObject-2.0.js.map +0 -1
  89. package/lib/injection/classes/node-gtk/Gdk-4.0.d.ts +0 -2
  90. package/lib/injection/classes/node-gtk/Gdk-4.0.js +0 -32
  91. package/lib/injection/classes/node-gtk/Gdk-4.0.js.map +0 -1
  92. package/lib/injection/classes/node-gtk/Gio-2.0.d.ts +0 -2
  93. package/lib/injection/classes/node-gtk/Gio-2.0.js +0 -14
  94. package/lib/injection/classes/node-gtk/Gio-2.0.js.map +0 -1
  95. package/lib/injection/classes/node-gtk/Graphene-1.0.d.ts +0 -2
  96. package/lib/injection/classes/node-gtk/Graphene-1.0.js +0 -133
  97. package/lib/injection/classes/node-gtk/Graphene-1.0.js.map +0 -1
  98. package/lib/injection/classes/node-gtk/Gtk-3.0.d.ts +0 -2
  99. package/lib/injection/classes/node-gtk/Gtk-3.0.js +0 -31
  100. package/lib/injection/classes/node-gtk/Gtk-3.0.js.map +0 -1
  101. package/lib/injection/classes/node-gtk/Gtk-4.0.d.ts +0 -2
  102. package/lib/injection/classes/node-gtk/Gtk-4.0.js +0 -52
  103. package/lib/injection/classes/node-gtk/Gtk-4.0.js.map +0 -1
  104. package/lib/injection/classes/node-gtk/Pango-1.0.d.ts +0 -2
  105. package/lib/injection/classes/node-gtk/Pango-1.0.js +0 -31
  106. package/lib/injection/classes/node-gtk/Pango-1.0.js.map +0 -1
  107. package/lib/injection/classes/node-gtk/index.d.ts +0 -2
  108. package/lib/injection/classes/node-gtk/index.js +0 -19
  109. package/lib/injection/classes/node-gtk/index.js.map +0 -1
  110. package/lib/injection/index.d.ts +0 -3
  111. package/lib/injection/index.js +0 -4
  112. package/lib/injection/index.js.map +0 -1
  113. package/lib/injection/injector.d.ts +0 -17
  114. package/lib/injection/injector.js +0 -139
  115. package/lib/injection/injector.js.map +0 -1
  116. package/lib/logger.d.ts +0 -36
  117. package/lib/logger.js +0 -137
  118. package/lib/logger.js.map +0 -1
  119. package/lib/messages.d.ts +0 -30
  120. package/lib/messages.js +0 -45
  121. package/lib/messages.js.map +0 -1
  122. package/lib/symtable.d.ts +0 -24
  123. package/lib/symtable.js +0 -63
  124. package/lib/symtable.js.map +0 -1
  125. package/lib/template-processor.d.ts +0 -75
  126. package/lib/template-processor.js +0 -207
  127. package/lib/template-processor.js.map +0 -1
  128. package/lib/transformation.d.ts +0 -156
  129. package/lib/transformation.js +0 -523
  130. package/lib/transformation.js.map +0 -1
  131. package/lib/type-definition-generator.d.ts +0 -116
  132. package/lib/type-definition-generator.js +0 -989
  133. package/lib/type-definition-generator.js.map +0 -1
  134. package/lib/types/answer-version.d.ts +0 -4
  135. package/lib/types/answer-version.js +0 -2
  136. package/lib/types/answer-version.js.map +0 -1
  137. package/lib/types/build-type.d.ts +0 -1
  138. package/lib/types/build-type.js +0 -2
  139. package/lib/types/build-type.js.map +0 -1
  140. package/lib/types/class-parent.d.ts +0 -11
  141. package/lib/types/class-parent.js +0 -2
  142. package/lib/types/class-parent.js.map +0 -1
  143. package/lib/types/config-flags.d.ts +0 -4
  144. package/lib/types/config-flags.js +0 -2
  145. package/lib/types/config-flags.js.map +0 -1
  146. package/lib/types/conflict-child-element.d.ts +0 -10
  147. package/lib/types/conflict-child-element.js +0 -2
  148. package/lib/types/conflict-child-element.js.map +0 -1
  149. package/lib/types/conflict-grouped-element.d.ts +0 -6
  150. package/lib/types/conflict-grouped-element.js +0 -2
  151. package/lib/types/conflict-grouped-element.js.map +0 -1
  152. package/lib/types/conflict-grouped-elements.d.ts +0 -4
  153. package/lib/types/conflict-grouped-elements.js +0 -2
  154. package/lib/types/conflict-grouped-elements.js.map +0 -1
  155. package/lib/types/construct-name.d.ts +0 -1
  156. package/lib/types/construct-name.js +0 -2
  157. package/lib/types/construct-name.js.map +0 -1
  158. package/lib/types/dependency-map.d.ts +0 -4
  159. package/lib/types/dependency-map.js +0 -2
  160. package/lib/types/dependency-map.js.map +0 -1
  161. package/lib/types/dependency.d.ts +0 -14
  162. package/lib/types/dependency.js +0 -2
  163. package/lib/types/dependency.js.map +0 -1
  164. package/lib/types/environment.d.ts +0 -1
  165. package/lib/types/environment.js +0 -2
  166. package/lib/types/environment.js.map +0 -1
  167. package/lib/types/generate-config.d.ts +0 -34
  168. package/lib/types/generate-config.js +0 -2
  169. package/lib/types/generate-config.js.map +0 -1
  170. package/lib/types/generator-type.d.ts +0 -4
  171. package/lib/types/generator-type.js +0 -6
  172. package/lib/types/generator-type.js.map +0 -1
  173. package/lib/types/gir-alias-element.d.ts +0 -13
  174. package/lib/types/gir-alias-element.js +0 -2
  175. package/lib/types/gir-alias-element.js.map +0 -1
  176. package/lib/types/gir-annotation.d.ts +0 -9
  177. package/lib/types/gir-annotation.js +0 -2
  178. package/lib/types/gir-annotation.js.map +0 -1
  179. package/lib/types/gir-any-element.d.ts +0 -2
  180. package/lib/types/gir-any-element.js +0 -2
  181. package/lib/types/gir-any-element.js.map +0 -1
  182. package/lib/types/gir-any-type.d.ts +0 -5
  183. package/lib/types/gir-any-type.js +0 -2
  184. package/lib/types/gir-any-type.js.map +0 -1
  185. package/lib/types/gir-array-type.d.ts +0 -20
  186. package/lib/types/gir-array-type.js +0 -3
  187. package/lib/types/gir-array-type.js.map +0 -1
  188. package/lib/types/gir-bitfield-element.d.ts +0 -17
  189. package/lib/types/gir-bitfield-element.js +0 -2
  190. package/lib/types/gir-bitfield-element.js.map +0 -1
  191. package/lib/types/gir-boolean.d.ts +0 -1
  192. package/lib/types/gir-boolean.js +0 -2
  193. package/lib/types/gir-boolean.js.map +0 -1
  194. package/lib/types/gir-boxed-element.d.ts +0 -15
  195. package/lib/types/gir-boxed-element.js +0 -2
  196. package/lib/types/gir-boxed-element.js.map +0 -1
  197. package/lib/types/gir-c-include.d.ts +0 -7
  198. package/lib/types/gir-c-include.js +0 -2
  199. package/lib/types/gir-c-include.js.map +0 -1
  200. package/lib/types/gir-callable-attrs.d.ts +0 -15
  201. package/lib/types/gir-callable-attrs.js +0 -3
  202. package/lib/types/gir-callable-attrs.js.map +0 -1
  203. package/lib/types/gir-callable-param-element.d.ts +0 -30
  204. package/lib/types/gir-callable-param-element.js +0 -2
  205. package/lib/types/gir-callable-param-element.js.map +0 -1
  206. package/lib/types/gir-callable-param.d.ts +0 -7
  207. package/lib/types/gir-callable-param.js +0 -2
  208. package/lib/types/gir-callable-param.js.map +0 -1
  209. package/lib/types/gir-callable-return.d.ts +0 -22
  210. package/lib/types/gir-callable-return.js +0 -2
  211. package/lib/types/gir-callable-return.js.map +0 -1
  212. package/lib/types/gir-callback-element.d.ts +0 -15
  213. package/lib/types/gir-callback-element.js +0 -2
  214. package/lib/types/gir-callback-element.js.map +0 -1
  215. package/lib/types/gir-class-element.d.ts +0 -48
  216. package/lib/types/gir-class-element.js +0 -2
  217. package/lib/types/gir-class-element.js.map +0 -1
  218. package/lib/types/gir-constant-element.d.ts +0 -15
  219. package/lib/types/gir-constant-element.js +0 -2
  220. package/lib/types/gir-constant-element.js.map +0 -1
  221. package/lib/types/gir-constructor-element.d.ts +0 -8
  222. package/lib/types/gir-constructor-element.js +0 -2
  223. package/lib/types/gir-constructor-element.js.map +0 -1
  224. package/lib/types/gir-direction.d.ts +0 -5
  225. package/lib/types/gir-direction.js +0 -7
  226. package/lib/types/gir-direction.js.map +0 -1
  227. package/lib/types/gir-doc-element.d.ts +0 -68
  228. package/lib/types/gir-doc-element.js +0 -2
  229. package/lib/types/gir-doc-element.js.map +0 -1
  230. package/lib/types/gir-enum-element.d.ts +0 -19
  231. package/lib/types/gir-enum-element.js +0 -2
  232. package/lib/types/gir-enum-element.js.map +0 -1
  233. package/lib/types/gir-field-element.d.ts +0 -18
  234. package/lib/types/gir-field-element.js +0 -2
  235. package/lib/types/gir-field-element.js.map +0 -1
  236. package/lib/types/gir-function-element.d.ts +0 -8
  237. package/lib/types/gir-function-element.js +0 -2
  238. package/lib/types/gir-function-element.js.map +0 -1
  239. package/lib/types/gir-implements.d.ts +0 -8
  240. package/lib/types/gir-implements.js +0 -2
  241. package/lib/types/gir-implements.js.map +0 -1
  242. package/lib/types/gir-include.d.ts +0 -9
  243. package/lib/types/gir-include.js +0 -2
  244. package/lib/types/gir-include.js.map +0 -1
  245. package/lib/types/gir-info-attrs.d.ts +0 -13
  246. package/lib/types/gir-info-attrs.js +0 -2
  247. package/lib/types/gir-info-attrs.js.map +0 -1
  248. package/lib/types/gir-info-elements.d.ts +0 -5
  249. package/lib/types/gir-info-elements.js +0 -2
  250. package/lib/types/gir-info-elements.js.map +0 -1
  251. package/lib/types/gir-instance-parameter.d.ts +0 -21
  252. package/lib/types/gir-instance-parameter.js +0 -2
  253. package/lib/types/gir-instance-parameter.js.map +0 -1
  254. package/lib/types/gir-interface-element.d.ts +0 -31
  255. package/lib/types/gir-interface-element.js +0 -2
  256. package/lib/types/gir-interface-element.js.map +0 -1
  257. package/lib/types/gir-member-element.d.ts +0 -17
  258. package/lib/types/gir-member-element.js +0 -2
  259. package/lib/types/gir-member-element.js.map +0 -1
  260. package/lib/types/gir-method-element.d.ts +0 -13
  261. package/lib/types/gir-method-element.js +0 -2
  262. package/lib/types/gir-method-element.js.map +0 -1
  263. package/lib/types/gir-module-resolved-by.d.ts +0 -10
  264. package/lib/types/gir-module-resolved-by.js +0 -2
  265. package/lib/types/gir-module-resolved-by.js.map +0 -1
  266. package/lib/types/gir-modules-grouped-map.d.ts +0 -4
  267. package/lib/types/gir-modules-grouped-map.js +0 -2
  268. package/lib/types/gir-modules-grouped-map.js.map +0 -1
  269. package/lib/types/gir-modules-grouped.d.ts +0 -12
  270. package/lib/types/gir-modules-grouped.js +0 -2
  271. package/lib/types/gir-modules-grouped.js.map +0 -1
  272. package/lib/types/gir-namespace.d.ts +0 -30
  273. package/lib/types/gir-namespace.js +0 -2
  274. package/lib/types/gir-namespace.js.map +0 -1
  275. package/lib/types/gir-package.d.ts +0 -7
  276. package/lib/types/gir-package.js +0 -2
  277. package/lib/types/gir-package.js.map +0 -1
  278. package/lib/types/gir-prerequisite.d.ts +0 -5
  279. package/lib/types/gir-prerequisite.js +0 -2
  280. package/lib/types/gir-prerequisite.js.map +0 -1
  281. package/lib/types/gir-property-element.d.ts +0 -21
  282. package/lib/types/gir-property-element.js +0 -2
  283. package/lib/types/gir-property-element.js.map +0 -1
  284. package/lib/types/gir-record-element.d.ts +0 -30
  285. package/lib/types/gir-record-element.js +0 -2
  286. package/lib/types/gir-record-element.js.map +0 -1
  287. package/lib/types/gir-repository.d.ts +0 -16
  288. package/lib/types/gir-repository.js +0 -2
  289. package/lib/types/gir-repository.js.map +0 -1
  290. package/lib/types/gir-signal.d.ts +0 -25
  291. package/lib/types/gir-signal.js +0 -2
  292. package/lib/types/gir-signal.js.map +0 -1
  293. package/lib/types/gir-transfer-ownership-type.d.ts +0 -5
  294. package/lib/types/gir-transfer-ownership-type.js +0 -7
  295. package/lib/types/gir-transfer-ownership-type.js.map +0 -1
  296. package/lib/types/gir-transfer-ownership.d.ts +0 -5
  297. package/lib/types/gir-transfer-ownership.js +0 -2
  298. package/lib/types/gir-transfer-ownership.js.map +0 -1
  299. package/lib/types/gir-type.d.ts +0 -14
  300. package/lib/types/gir-type.js +0 -2
  301. package/lib/types/gir-type.js.map +0 -1
  302. package/lib/types/gir-union-element.d.ts +0 -22
  303. package/lib/types/gir-union-element.js +0 -2
  304. package/lib/types/gir-union-element.js.map +0 -1
  305. package/lib/types/gir-unparsed-number.d.ts +0 -2
  306. package/lib/types/gir-unparsed-number.js +0 -2
  307. package/lib/types/gir-unparsed-number.js.map +0 -1
  308. package/lib/types/gir-var-args.d.ts +0 -5
  309. package/lib/types/gir-var-args.js +0 -2
  310. package/lib/types/gir-var-args.js.map +0 -1
  311. package/lib/types/gir-virtual-method.d.ts +0 -10
  312. package/lib/types/gir-virtual-method.js +0 -2
  313. package/lib/types/gir-virtual-method.js.map +0 -1
  314. package/lib/types/index.d.ts +0 -118
  315. package/lib/types/index.js +0 -119
  316. package/lib/types/index.js.map +0 -1
  317. package/lib/types/inheritance-table.d.ts +0 -3
  318. package/lib/types/inheritance-table.js +0 -2
  319. package/lib/types/inheritance-table.js.map +0 -1
  320. package/lib/types/injection-callback.d.ts +0 -16
  321. package/lib/types/injection-callback.js +0 -2
  322. package/lib/types/injection-callback.js.map +0 -1
  323. package/lib/types/injection-class.d.ts +0 -25
  324. package/lib/types/injection-class.js +0 -2
  325. package/lib/types/injection-class.js.map +0 -1
  326. package/lib/types/injection-function.d.ts +0 -7
  327. package/lib/types/injection-function.js +0 -2
  328. package/lib/types/injection-function.js.map +0 -1
  329. package/lib/types/injection-generic-parameter.d.ts +0 -2
  330. package/lib/types/injection-generic-parameter.js +0 -2
  331. package/lib/types/injection-generic-parameter.js.map +0 -1
  332. package/lib/types/injection-instance-parameter.d.ts +0 -2
  333. package/lib/types/injection-instance-parameter.js +0 -2
  334. package/lib/types/injection-instance-parameter.js.map +0 -1
  335. package/lib/types/injection-parameter.d.ts +0 -8
  336. package/lib/types/injection-parameter.js +0 -2
  337. package/lib/types/injection-parameter.js.map +0 -1
  338. package/lib/types/injection-property.d.ts +0 -4
  339. package/lib/types/injection-property.js +0 -2
  340. package/lib/types/injection-property.js.map +0 -1
  341. package/lib/types/injection-type.d.ts +0 -2
  342. package/lib/types/injection-type.js +0 -2
  343. package/lib/types/injection-type.js.map +0 -1
  344. package/lib/types/injection.d.ts +0 -5
  345. package/lib/types/injection.js +0 -2
  346. package/lib/types/injection.js.map +0 -1
  347. package/lib/types/local-name-check.d.ts +0 -4
  348. package/lib/types/local-name-check.js +0 -2
  349. package/lib/types/local-name-check.js.map +0 -1
  350. package/lib/types/local-name-type.d.ts +0 -1
  351. package/lib/types/local-name-type.js +0 -2
  352. package/lib/types/local-name-type.js.map +0 -1
  353. package/lib/types/local-name.d.ts +0 -7
  354. package/lib/types/local-name.js +0 -2
  355. package/lib/types/local-name.js.map +0 -1
  356. package/lib/types/local-names.d.ts +0 -4
  357. package/lib/types/local-names.js +0 -2
  358. package/lib/types/local-names.js.map +0 -1
  359. package/lib/types/module-type.d.ts +0 -1
  360. package/lib/types/module-type.js +0 -2
  361. package/lib/types/module-type.js.map +0 -1
  362. package/lib/types/parsed-gir.d.ts +0 -4
  363. package/lib/types/parsed-gir.js +0 -2
  364. package/lib/types/parsed-gir.js.map +0 -1
  365. package/lib/types/part-of-class.d.ts +0 -7
  366. package/lib/types/part-of-class.js +0 -2
  367. package/lib/types/part-of-class.js.map +0 -1
  368. package/lib/types/part-of-module.d.ts +0 -6
  369. package/lib/types/part-of-module.js +0 -2
  370. package/lib/types/part-of-module.js.map +0 -1
  371. package/lib/types/resolve-type.d.ts +0 -4
  372. package/lib/types/resolve-type.js +0 -6
  373. package/lib/types/resolve-type.js.map +0 -1
  374. package/lib/types/sym-table-items.d.ts +0 -4
  375. package/lib/types/sym-table-items.js +0 -2
  376. package/lib/types/sym-table-items.js.map +0 -1
  377. package/lib/types/transformation-case.d.ts +0 -1
  378. package/lib/types/transformation-case.js +0 -2
  379. package/lib/types/transformation-case.js.map +0 -1
  380. package/lib/types/transformations.d.ts +0 -11
  381. package/lib/types/transformations.js +0 -2
  382. package/lib/types/transformations.js.map +0 -1
  383. package/lib/types/ts-alias.d.ts +0 -10
  384. package/lib/types/ts-alias.js +0 -2
  385. package/lib/types/ts-alias.js.map +0 -1
  386. package/lib/types/ts-callback-interface.d.ts +0 -10
  387. package/lib/types/ts-callback-interface.js +0 -2
  388. package/lib/types/ts-callback-interface.js.map +0 -1
  389. package/lib/types/ts-callback.d.ts +0 -17
  390. package/lib/types/ts-callback.js +0 -2
  391. package/lib/types/ts-callback.js.map +0 -1
  392. package/lib/types/ts-class.d.ts +0 -85
  393. package/lib/types/ts-class.js +0 -2
  394. package/lib/types/ts-class.js.map +0 -1
  395. package/lib/types/ts-doc-tag.d.ts +0 -21
  396. package/lib/types/ts-doc-tag.js +0 -2
  397. package/lib/types/ts-doc-tag.js.map +0 -1
  398. package/lib/types/ts-doc.d.ts +0 -20
  399. package/lib/types/ts-doc.js +0 -2
  400. package/lib/types/ts-doc.js.map +0 -1
  401. package/lib/types/ts-enum.d.ts +0 -12
  402. package/lib/types/ts-enum.js +0 -2
  403. package/lib/types/ts-enum.js.map +0 -1
  404. package/lib/types/ts-function.d.ts +0 -44
  405. package/lib/types/ts-function.js +0 -2
  406. package/lib/types/ts-function.js.map +0 -1
  407. package/lib/types/ts-generic-parameter.d.ts +0 -8
  408. package/lib/types/ts-generic-parameter.js +0 -2
  409. package/lib/types/ts-generic-parameter.js.map +0 -1
  410. package/lib/types/ts-instance-parameter.d.ts +0 -4
  411. package/lib/types/ts-instance-parameter.js +0 -2
  412. package/lib/types/ts-instance-parameter.js.map +0 -1
  413. package/lib/types/ts-member.d.ts +0 -10
  414. package/lib/types/ts-member.js +0 -2
  415. package/lib/types/ts-member.js.map +0 -1
  416. package/lib/types/ts-method.d.ts +0 -5
  417. package/lib/types/ts-method.js +0 -2
  418. package/lib/types/ts-method.js.map +0 -1
  419. package/lib/types/ts-parameter.d.ts +0 -15
  420. package/lib/types/ts-parameter.js +0 -2
  421. package/lib/types/ts-parameter.js.map +0 -1
  422. package/lib/types/ts-property.d.ts +0 -17
  423. package/lib/types/ts-property.js +0 -2
  424. package/lib/types/ts-property.js.map +0 -1
  425. package/lib/types/ts-signal.d.ts +0 -17
  426. package/lib/types/ts-signal.js +0 -2
  427. package/lib/types/ts-signal.js.map +0 -1
  428. package/lib/types/ts-type-name.d.ts +0 -1
  429. package/lib/types/ts-type-name.js +0 -2
  430. package/lib/types/ts-type-name.js.map +0 -1
  431. package/lib/types/ts-type-separator.d.ts +0 -1
  432. package/lib/types/ts-type-separator.js +0 -2
  433. package/lib/types/ts-type-separator.js.map +0 -1
  434. package/lib/types/ts-type.d.ts +0 -22
  435. package/lib/types/ts-type.js +0 -2
  436. package/lib/types/ts-type.js.map +0 -1
  437. package/lib/types/ts-var.d.ts +0 -17
  438. package/lib/types/ts-var.js +0 -2
  439. package/lib/types/ts-var.js.map +0 -1
  440. package/lib/types/type-gir-alias.d.ts +0 -2
  441. package/lib/types/type-gir-alias.js +0 -2
  442. package/lib/types/type-gir-alias.js.map +0 -1
  443. package/lib/types/type-gir-class.d.ts +0 -2
  444. package/lib/types/type-gir-class.js +0 -2
  445. package/lib/types/type-gir-class.js.map +0 -1
  446. package/lib/types/type-gir-element.d.ts +0 -3
  447. package/lib/types/type-gir-element.js +0 -2
  448. package/lib/types/type-gir-element.js.map +0 -1
  449. package/lib/types/type-gir-enumeration-member.d.ts +0 -2
  450. package/lib/types/type-gir-enumeration-member.js +0 -2
  451. package/lib/types/type-gir-enumeration-member.js.map +0 -1
  452. package/lib/types/type-gir-enumeration.d.ts +0 -2
  453. package/lib/types/type-gir-enumeration.js +0 -2
  454. package/lib/types/type-gir-enumeration.js.map +0 -1
  455. package/lib/types/type-gir-function.d.ts +0 -1
  456. package/lib/types/type-gir-function.js +0 -2
  457. package/lib/types/type-gir-function.js.map +0 -1
  458. package/lib/types/type-gir-interface.d.ts +0 -2
  459. package/lib/types/type-gir-interface.js +0 -2
  460. package/lib/types/type-gir-interface.js.map +0 -1
  461. package/lib/types/type-gir-method.d.ts +0 -2
  462. package/lib/types/type-gir-method.js +0 -2
  463. package/lib/types/type-gir-method.js.map +0 -1
  464. package/lib/types/type-gir-parameter.d.ts +0 -1
  465. package/lib/types/type-gir-parameter.js +0 -2
  466. package/lib/types/type-gir-parameter.js.map +0 -1
  467. package/lib/types/type-gir-property.d.ts +0 -2
  468. package/lib/types/type-gir-property.js +0 -2
  469. package/lib/types/type-gir-property.js.map +0 -1
  470. package/lib/types/type-gir-variable.d.ts +0 -1
  471. package/lib/types/type-gir-variable.js +0 -2
  472. package/lib/types/type-gir-variable.js.map +0 -1
  473. package/lib/types/type-ts-element.d.ts +0 -3
  474. package/lib/types/type-ts-element.js +0 -2
  475. package/lib/types/type-ts-element.js.map +0 -1
  476. package/lib/types/type-ts-enumeration-member.d.ts +0 -2
  477. package/lib/types/type-ts-enumeration-member.js +0 -2
  478. package/lib/types/type-ts-enumeration-member.js.map +0 -1
  479. package/lib/types/type-ts-function.d.ts +0 -1
  480. package/lib/types/type-ts-function.js +0 -2
  481. package/lib/types/type-ts-function.js.map +0 -1
  482. package/lib/types/type-ts-property.d.ts +0 -1
  483. package/lib/types/type-ts-property.js +0 -2
  484. package/lib/types/type-ts-property.js.map +0 -1
  485. package/lib/types/user-config-load-result.d.ts +0 -6
  486. package/lib/types/user-config-load-result.js +0 -2
  487. package/lib/types/user-config-load-result.js.map +0 -1
  488. package/lib/types/user-config.d.ts +0 -42
  489. package/lib/types/user-config.js +0 -2
  490. package/lib/types/user-config.js.map +0 -1
  491. package/src/conflict-resolver.ts +0 -1358
  492. package/src/constants.ts +0 -29
  493. package/src/generator.ts +0 -10
  494. package/src/gir-factory.ts +0 -499
  495. package/src/gir-module.ts +0 -2816
  496. package/src/html-doc-generator.ts +0 -23
  497. package/src/injection/callbacks/gjs/Gio-2.0.ts +0 -37
  498. package/src/injection/callbacks/gjs/index.ts +0 -5
  499. package/src/injection/callbacks/index.ts +0 -6
  500. package/src/injection/callbacks/node-gtk/index.ts +0 -3
  501. package/src/injection/classes/GLib-2-0.ts +0 -36
  502. package/src/injection/classes/gjs/GLib-2.0.ts +0 -201
  503. package/src/injection/classes/gjs/GObject-2.0.ts +0 -635
  504. package/src/injection/classes/gjs/Gio-2.0.ts +0 -219
  505. package/src/injection/classes/gjs/index.ts +0 -7
  506. package/src/injection/classes/index.ts +0 -7
  507. package/src/injection/classes/node-gtk/GLib-2.0.ts +0 -20
  508. package/src/injection/classes/node-gtk/GObject-2.0.ts +0 -67
  509. package/src/injection/classes/node-gtk/Gdk-4.0.ts +0 -33
  510. package/src/injection/classes/node-gtk/Gio-2.0.ts +0 -15
  511. package/src/injection/classes/node-gtk/Graphene-1.0.ts +0 -134
  512. package/src/injection/classes/node-gtk/Gtk-3.0.ts +0 -32
  513. package/src/injection/classes/node-gtk/Gtk-4.0.ts +0 -53
  514. package/src/injection/classes/node-gtk/Pango-1.0.ts +0 -32
  515. package/src/injection/classes/node-gtk/index.ts +0 -21
  516. package/src/injection/index.ts +0 -3
  517. package/src/injection/injector.ts +0 -184
  518. package/src/logger.ts +0 -134
  519. package/src/messages.ts +0 -68
  520. package/src/symtable.ts +0 -70
  521. package/src/template-processor.ts +0 -233
  522. package/src/transformation.ts +0 -583
  523. package/src/type-definition-generator.ts +0 -1458
  524. package/src/types/answer-version.ts +0 -4
  525. package/src/types/build-type.ts +0 -1
  526. package/src/types/class-parent.ts +0 -12
  527. package/src/types/config-flags.ts +0 -5
  528. package/src/types/conflict-child-element.ts +0 -11
  529. package/src/types/conflict-grouped-element.ts +0 -7
  530. package/src/types/conflict-grouped-elements.ts +0 -5
  531. package/src/types/construct-name.ts +0 -11
  532. package/src/types/dependency-map.ts +0 -4
  533. package/src/types/dependency.ts +0 -14
  534. package/src/types/environment.ts +0 -1
  535. package/src/types/generate-config.ts +0 -35
  536. package/src/types/generator-type.ts +0 -4
  537. package/src/types/gir-alias-element.ts +0 -15
  538. package/src/types/gir-annotation.ts +0 -10
  539. package/src/types/gir-any-element.ts +0 -35
  540. package/src/types/gir-any-type.ts +0 -7
  541. package/src/types/gir-array-type.ts +0 -23
  542. package/src/types/gir-bitfield-element.ts +0 -20
  543. package/src/types/gir-boolean.ts +0 -1
  544. package/src/types/gir-boxed-element.ts +0 -19
  545. package/src/types/gir-c-include.ts +0 -7
  546. package/src/types/gir-callable-attrs.ts +0 -19
  547. package/src/types/gir-callable-param-element.ts +0 -45
  548. package/src/types/gir-callable-param.ts +0 -9
  549. package/src/types/gir-callable-return.ts +0 -25
  550. package/src/types/gir-callback-element.ts +0 -28
  551. package/src/types/gir-class-element.ts +0 -71
  552. package/src/types/gir-constant-element.ts +0 -17
  553. package/src/types/gir-constructor-element.ts +0 -18
  554. package/src/types/gir-direction.ts +0 -5
  555. package/src/types/gir-doc-element.ts +0 -73
  556. package/src/types/gir-enum-element.ts +0 -28
  557. package/src/types/gir-field-element.ts +0 -31
  558. package/src/types/gir-function-element.ts +0 -19
  559. package/src/types/gir-implements.ts +0 -9
  560. package/src/types/gir-include.ts +0 -9
  561. package/src/types/gir-info-attrs.ts +0 -16
  562. package/src/types/gir-info-elements.ts +0 -8
  563. package/src/types/gir-instance-parameter.ts +0 -25
  564. package/src/types/gir-interface-element.ts +0 -53
  565. package/src/types/gir-member-element.ts +0 -19
  566. package/src/types/gir-method-element.ts +0 -25
  567. package/src/types/gir-module-resolved-by.ts +0 -11
  568. package/src/types/gir-modules-grouped-map.ts +0 -5
  569. package/src/types/gir-modules-grouped.ts +0 -13
  570. package/src/types/gir-namespace.ts +0 -47
  571. package/src/types/gir-package.ts +0 -7
  572. package/src/types/gir-prerequisite.ts +0 -5
  573. package/src/types/gir-property-element.ts +0 -31
  574. package/src/types/gir-record-element.ts +0 -47
  575. package/src/types/gir-repository.ts +0 -20
  576. package/src/types/gir-signal.ts +0 -43
  577. package/src/types/gir-transfer-ownership-type.ts +0 -5
  578. package/src/types/gir-transfer-ownership.ts +0 -6
  579. package/src/types/gir-type.ts +0 -16
  580. package/src/types/gir-union-element.ts +0 -35
  581. package/src/types/gir-unparsed-number.ts +0 -2
  582. package/src/types/gir-var-args.ts +0 -6
  583. package/src/types/gir-virtual-method.ts +0 -22
  584. package/src/types/index.ts +0 -118
  585. package/src/types/inheritance-table.ts +0 -3
  586. package/src/types/injection-callback.ts +0 -20
  587. package/src/types/injection-class.ts +0 -30
  588. package/src/types/injection-function.ts +0 -23
  589. package/src/types/injection-generic-parameter.ts +0 -3
  590. package/src/types/injection-instance-parameter.ts +0 -3
  591. package/src/types/injection-parameter.ts +0 -9
  592. package/src/types/injection-property.ts +0 -7
  593. package/src/types/injection-type.ts +0 -3
  594. package/src/types/injection.ts +0 -6
  595. package/src/types/local-name-check.ts +0 -5
  596. package/src/types/local-name-type.ts +0 -1
  597. package/src/types/local-name.ts +0 -8
  598. package/src/types/local-names.ts +0 -5
  599. package/src/types/module-type.ts +0 -1
  600. package/src/types/parsed-gir.ts +0 -5
  601. package/src/types/part-of-class.ts +0 -9
  602. package/src/types/part-of-module.ts +0 -8
  603. package/src/types/resolve-type.ts +0 -4
  604. package/src/types/sym-table-items.ts +0 -5
  605. package/src/types/transformation-case.ts +0 -7
  606. package/src/types/transformations.ts +0 -12
  607. package/src/types/ts-alias.ts +0 -11
  608. package/src/types/ts-callback-interface.ts +0 -11
  609. package/src/types/ts-callback.ts +0 -21
  610. package/src/types/ts-class.ts +0 -109
  611. package/src/types/ts-doc-tag.ts +0 -23
  612. package/src/types/ts-doc.ts +0 -23
  613. package/src/types/ts-enum.ts +0 -15
  614. package/src/types/ts-function.ts +0 -59
  615. package/src/types/ts-generic-parameter.ts +0 -8
  616. package/src/types/ts-instance-parameter.ts +0 -4
  617. package/src/types/ts-member.ts +0 -11
  618. package/src/types/ts-method.ts +0 -6
  619. package/src/types/ts-parameter.ts +0 -20
  620. package/src/types/ts-property.ts +0 -22
  621. package/src/types/ts-signal.ts +0 -21
  622. package/src/types/ts-type-name.ts +0 -1
  623. package/src/types/ts-type-separator.ts +0 -1
  624. package/src/types/ts-type.ts +0 -25
  625. package/src/types/ts-var.ts +0 -21
  626. package/src/types/type-gir-alias.ts +0 -2
  627. package/src/types/type-gir-class.ts +0 -2
  628. package/src/types/type-gir-element.ts +0 -25
  629. package/src/types/type-gir-enumeration-member.ts +0 -2
  630. package/src/types/type-gir-enumeration.ts +0 -2
  631. package/src/types/type-gir-function.ts +0 -8
  632. package/src/types/type-gir-interface.ts +0 -2
  633. package/src/types/type-gir-method.ts +0 -2
  634. package/src/types/type-gir-parameter.ts +0 -1
  635. package/src/types/type-gir-property.ts +0 -2
  636. package/src/types/type-gir-variable.ts +0 -1
  637. package/src/types/type-ts-element.ts +0 -13
  638. package/src/types/type-ts-enumeration-member.ts +0 -2
  639. package/src/types/type-ts-function.ts +0 -1
  640. package/src/types/type-ts-property.ts +0 -1
  641. package/src/types/user-config-load-result.ts +0 -6
  642. package/src/types/user-config.ts +0 -43
  643. package/templates/Cogl-2.0.d.ts +0 -0
  644. package/templates/Gjs/GObject-2.0.d.ts +0 -238
  645. package/templates/Gjs/Gio-2.0.d.ts +0 -64
  646. package/templates/Gjs/Gjs.d.ts +0 -137
  647. package/templates/Gjs/Gjs.js +0 -21
  648. package/templates/Gjs/GnomeShell.d.ts +0 -122
  649. package/templates/Gjs/GnomeShell.js +0 -10
  650. package/templates/Gjs/index.d.ts +0 -594
  651. package/templates/Gjs/index.js +0 -4
  652. package/templates/Gjs/misc/dbusUtils.d.ts +0 -15
  653. package/templates/Gjs/misc/dbusUtils.js +0 -6
  654. package/templates/Gjs/misc/extensionUtils.d.ts +0 -99
  655. package/templates/Gjs/misc/extensionUtils.js +0 -6
  656. package/templates/Gjs/misc/fileUtils.d.ts +0 -49
  657. package/templates/Gjs/misc/fileUtils.js +0 -6
  658. package/templates/Gjs/misc/gnomeSession.d.ts +0 -72
  659. package/templates/Gjs/misc/gnomeSession.js +0 -6
  660. package/templates/Gjs/module.d.ts +0 -10
  661. package/templates/Gjs/module.js +0 -16
  662. package/templates/Gjs/ui/userWidget.d.ts +0 -10
  663. package/templates/Gjs/ui/userWidget.js +0 -6
  664. package/templates/Granite-1.0.d.ts +0 -7
  665. package/templates/Granite-7.0.d.ts +0 -7
  666. package/templates/GstBase-0.10.d.ts +0 -5
  667. package/templates/RygelServer-2.6.d.ts +0 -3
  668. package/templates/node-gtk/GObject-2.0.d.ts +0 -57
  669. package/templates/node-gtk/index.d.ts +0 -40
  670. package/templates/node-gtk/index.js +0 -9
  671. package/templates/node-gtk/module.d.ts +0 -10
  672. package/templates/node-gtk/module.js +0 -17
package/lib/gir-module.js DELETED
@@ -1,2075 +0,0 @@
1
- // TODO move this class into a web-worker? https://www.npmjs.com/package/web-worker
2
- import { Transformation, C_TYPE_MAP, FULL_TYPE_MAP, POD_TYPE_MAP, POD_TYPE_MAP_ARRAY, IGNORE_GIR_TYPE_TS_DOC_TYPES, } from './transformation.js';
3
- import { STATIC_NAME_ALREADY_EXISTS, MAX_CLASS_PARENT_DEPTH } from './constants.js';
4
- import { Logger } from './logger.js';
5
- import { Injector } from './injection/injector.js';
6
- import { GirFactory } from './gir-factory.js';
7
- import { ConflictResolver } from './conflict-resolver.js';
8
- import { NO_TSDATA, WARN_NOT_FOUND_TYPE, WARN_CONSTANT_ALREADY_EXPORTED, WARN_DUPLICATE_SYMBOL, WARN_DUPLICATE_PARAMETER, WARN_DUPLICATE_ENUM_IDENTIFIER, } from './messages.js';
9
- import { isEqual, find, clone, girBool, removeNamespace, addNamespace, girElementIsIntrospectable } from './utils.js';
10
- import { SymTable } from './symtable.js';
11
- export class GirModule {
12
- config;
13
- /**
14
- * Array of all gir modules
15
- */
16
- static allGirModules = [];
17
- /**
18
- * E.g. 'Gtk'
19
- */
20
- namespace;
21
- /**
22
- * E.g. '3.0'
23
- */
24
- version = '0.0';
25
- /**
26
- * E.g. 'Gtk-3.0'
27
- */
28
- packageName;
29
- /**
30
- * E.g. 'Gtk30'
31
- * Is used in the generated index.d.ts, for example: `import * as Gtk30 from "./Gtk-3.0.js";`
32
- */
33
- importName;
34
- dependencies = [];
35
- _transitiveDependencies = [];
36
- set transitiveDependencies(deps) {
37
- this._transitiveDependencies = this.checkTransitiveDependencies(deps);
38
- }
39
- get transitiveDependencies() {
40
- return this._transitiveDependencies;
41
- }
42
- get allDependencies() {
43
- return [...new Set([...this.dependencies, ...this.transitiveDependencies])];
44
- }
45
- repo;
46
- ns = { $: { name: '', version: '' } };
47
- /**
48
- * Used to find namespaces that are used in other modules
49
- */
50
- symTable;
51
- transformation;
52
- girFactory = new GirFactory();
53
- conflictResolver;
54
- log;
55
- inject;
56
- extends;
57
- /**
58
- * To prevent constants from being exported twice, the names already exported are saved here for comparison.
59
- * Please note: Such a case is only known for Zeitgeist-2.0 with the constant "ATTACHMENT"
60
- */
61
- constNames = {};
62
- constructor(xml, config) {
63
- this.config = config;
64
- this.repo = xml.repository;
65
- if (!this.repo.namespace || !this.repo.namespace.length) {
66
- throw new Error(`Namespace not found!`);
67
- }
68
- this.dependencies = this.loadDependencies(this.repo.include || []);
69
- this.ns = this.repo.namespace[0];
70
- this.namespace = this.ns.$.name;
71
- this.version = this.ns.$.version;
72
- this.packageName = `${this.namespace}-${this.version}`;
73
- this.transformation = new Transformation(this.packageName, config);
74
- this.log = new Logger(config.environment, config.verbose, this.packageName || 'GirModule');
75
- this.conflictResolver = new ConflictResolver(config.environment, config.verbose);
76
- this.inject = new Injector(this.config.environment);
77
- this.importName = this.transformation.transformModuleNamespaceName(this.packageName);
78
- this.symTable = new SymTable(this.config, this.packageName, this.namespace);
79
- }
80
- loadDependencies(girInclude) {
81
- const dependencies = [];
82
- for (const i of girInclude) {
83
- dependencies.unshift(`${i.$.name}-${i.$.version || ''}`);
84
- }
85
- return dependencies;
86
- }
87
- checkTransitiveDependencies(transitiveDependencies) {
88
- // Always pull in GObject-2.0, as we may need it for e.g. GObject-2.0.type
89
- if (this.packageName !== 'GObject-2.0') {
90
- if (!find(transitiveDependencies, (x) => x === 'GObject-2.0')) {
91
- transitiveDependencies.push('GObject-2.0');
92
- }
93
- }
94
- // Add missing dependencies
95
- if (this.packageName === 'UnityExtras-7.0') {
96
- if (!find(transitiveDependencies, (x) => x === 'Unity-7.0')) {
97
- transitiveDependencies.push('Unity-7.0');
98
- }
99
- }
100
- if (this.packageName === 'UnityExtras-6.0') {
101
- if (!find(transitiveDependencies, (x) => x === 'Unity-6.0')) {
102
- transitiveDependencies.push('Unity-6.0');
103
- }
104
- }
105
- if (this.packageName === 'GTop-2.0') {
106
- if (!find(transitiveDependencies, (x) => x === 'GLib-2.0')) {
107
- transitiveDependencies.push('GLib-2.0');
108
- }
109
- }
110
- return transitiveDependencies;
111
- }
112
- getTsDoc(girDoc) {
113
- const tsDoc = {
114
- text: '',
115
- tags: [],
116
- };
117
- if (girDoc.doc?.[0]?._) {
118
- let text = girDoc.doc?.[0]?._ || '';
119
- text = this.transformation.transformGirDoc(text);
120
- tsDoc.text = text;
121
- }
122
- return tsDoc;
123
- }
124
- getTsDocGirElementTags(tsTypeName, girTypeName) {
125
- const tags = [];
126
- if (!girTypeName || IGNORE_GIR_TYPE_TS_DOC_TYPES.includes(girTypeName)) {
127
- return tags;
128
- }
129
- tags.push({
130
- tagName: girTypeName,
131
- paramName: '',
132
- text: '',
133
- });
134
- return tags;
135
- }
136
- getTsDocInParamTags(inParams) {
137
- const tags = [];
138
- if (!inParams?.length) {
139
- return tags;
140
- }
141
- for (const inParam of inParams) {
142
- if (!inParam._tsData) {
143
- throw new Error(NO_TSDATA('getTsDocInParamTags'));
144
- }
145
- if (!inParam._tsData?.doc) {
146
- inParam._tsData.doc = this.getTsDoc(inParam);
147
- }
148
- if (inParam._tsData?.name) {
149
- tags.push({
150
- paramName: inParam._tsData.name,
151
- tagName: 'param',
152
- text: inParam._tsData.doc.text
153
- ? this.transformation.transformGirDocTagText(inParam._tsData.doc.text)
154
- : '',
155
- });
156
- }
157
- }
158
- return tags;
159
- }
160
- annotateFunctionArguments(girFunc) {
161
- const funcName = girFunc._fullSymName;
162
- if (funcName && girFunc.parameters) {
163
- for (const girParams of girFunc.parameters) {
164
- if (girParams.parameter) {
165
- for (const girParam of girParams.parameter) {
166
- girParam._module = this;
167
- if (girParam.$ && girParam.$.name) {
168
- girParam._fullSymName = `${funcName}.${girParam.$.name}`;
169
- }
170
- }
171
- }
172
- }
173
- }
174
- }
175
- annotateFunctionReturn(girFunc) {
176
- const retVals = girFunc['return-value'];
177
- if (retVals && girFunc._fullSymName)
178
- for (const retVal of retVals) {
179
- retVal._module = this;
180
- retVal.girTypeName = 'callable-return';
181
- if (retVal.$ && retVal.$.name) {
182
- retVal._fullSymName = `${girFunc._fullSymName}.${retVal.$.name}`;
183
- }
184
- }
185
- }
186
- /**
187
- * Functions which are not part of a class
188
- * @param girFuncs
189
- */
190
- annotateFunctions(girFuncs) {
191
- if (Array.isArray(girFuncs))
192
- for (const girFunc of girFuncs) {
193
- if (girFunc?.$?.name) {
194
- // girFunc._girType = girType
195
- girFunc._fullSymName = `${this.namespace}.${girFunc.$.name}`;
196
- this.annotateFunctionArguments(girFunc);
197
- this.annotateFunctionReturn(girFunc);
198
- }
199
- }
200
- }
201
- /**
202
- * Functions and methods of a class
203
- */
204
- annotateMethods(girClass, girFuncs) {
205
- if (Array.isArray(girFuncs))
206
- for (const girFunc of girFuncs) {
207
- if (girFunc?.$?.name) {
208
- // girFunc._girType = girType
209
- // girFunc._tsType = tsType
210
- girFunc._class = girClass;
211
- const nsName = girClass ? girClass._fullSymName : this.namespace;
212
- if (nsName)
213
- girFunc._fullSymName = `${nsName}.${girFunc.$.name}`;
214
- this.annotateFunctionArguments(girFunc);
215
- this.annotateFunctionReturn(girFunc);
216
- }
217
- }
218
- }
219
- /**
220
- * Variables which are not part of a class
221
- */
222
- annotateVariables(girVars) {
223
- for (const girVar of girVars) {
224
- girVar._module = this;
225
- if (girVar.$ && girVar.$.name) {
226
- girVar._fullSymName = `${this.namespace}.${girVar.$.name}`;
227
- }
228
- }
229
- }
230
- /**
231
- * Fields are variables which are part of a class
232
- * @see https://www.typescriptlang.org/docs/handbook/2/classes.html#fields
233
- */
234
- annotateFields(girClass, girVars) {
235
- for (const girVar of girVars) {
236
- const nsName = girClass ? girClass._fullSymName : this.namespace;
237
- girVar._module = this;
238
- if (girClass) {
239
- girVar._class = girClass;
240
- }
241
- if (girVar.$ && girVar.$.name && nsName) {
242
- girVar._fullSymName = `${nsName}.${girVar.$.name}`;
243
- }
244
- }
245
- }
246
- annotateClass(girClass) {
247
- girClass._module = this;
248
- girClass._fullSymName = `${this.namespace}.${girClass.$.name}`;
249
- const constructors = Array.isArray(girClass.constructor) ? girClass.constructor : [];
250
- const signals = (girClass.signal ||
251
- girClass['glib:signal'] ||
252
- []);
253
- const functions = girClass.function || [];
254
- const methods = girClass.method || [];
255
- const vMethods = girClass['virtual-method'] || new Array();
256
- const properties = girClass.property;
257
- const fields = girClass.field;
258
- this.annotateMethods(girClass, constructors);
259
- this.annotateMethods(girClass, functions);
260
- this.annotateMethods(girClass, methods);
261
- this.annotateMethods(girClass, vMethods);
262
- this.annotateMethods(girClass, signals);
263
- if (properties)
264
- this.annotateFields(girClass, properties);
265
- if (fields)
266
- this.annotateFields(girClass, fields);
267
- }
268
- /**
269
- * Annotates the custom `_module`, `_fullSymName` and `_girType` properties.
270
- * Also registers the element on the `symTable`.
271
- * @param girElements
272
- * @param girType
273
- */
274
- annotateAndRegisterGirElement(girElements) {
275
- for (const girElement of girElements) {
276
- if (girElement?.$ && girElement.$.name) {
277
- // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-argument
278
- if (!girElementIsIntrospectable(girElement))
279
- continue;
280
- girElement._module = this;
281
- girElement._fullSymName = `${this.namespace}.${girElement.$.name}`;
282
- if (this.symTable.get(this.allDependencies, girElement._fullSymName)) {
283
- this.log.warn(WARN_DUPLICATE_SYMBOL(girElement._fullSymName));
284
- }
285
- this.symTable.set(this.allDependencies, girElement._fullSymName, girElement);
286
- }
287
- }
288
- }
289
- /**
290
- * TODO: find better name for this method
291
- * @param girVar
292
- * @param fullTypeName
293
- * @returns e.g.
294
- * ```ts
295
- * {
296
- * namespace: "Gtk",
297
- * resValue: "Gtk.Widget"
298
- * }
299
- *
300
- */
301
- fullTypeLookup(girVar, fullTypeName) {
302
- let resValue = '';
303
- let namespace = '';
304
- if (!fullTypeName) {
305
- return {
306
- value: resValue,
307
- fullTypeName,
308
- namespace,
309
- };
310
- }
311
- // Fully qualify our type name
312
- if (!fullTypeName.includes('.')) {
313
- let tryFullTypeName = '';
314
- if (!resValue && girVar._module && girVar._module !== this) {
315
- tryFullTypeName = `${girVar._module.namespace}.${fullTypeName}`;
316
- resValue = this.fullTypeLookupWithNamespace(tryFullTypeName).value;
317
- if (resValue) {
318
- fullTypeName = tryFullTypeName;
319
- namespace = girVar._module.namespace;
320
- }
321
- }
322
- if (!resValue) {
323
- tryFullTypeName = `${this.namespace}.${fullTypeName}`;
324
- resValue = this.fullTypeLookupWithNamespace(tryFullTypeName).value;
325
- if (resValue) {
326
- fullTypeName = tryFullTypeName;
327
- namespace = this.namespace;
328
- }
329
- }
330
- const girClass = girVar._class;
331
- if (!resValue && girClass?._module?.namespace && girClass._module !== this) {
332
- tryFullTypeName = `${girClass._module.namespace}.${fullTypeName}`;
333
- resValue = this.fullTypeLookupWithNamespace(tryFullTypeName).value;
334
- if (resValue) {
335
- fullTypeName = tryFullTypeName;
336
- namespace = girClass?._module?.namespace;
337
- }
338
- }
339
- }
340
- if (!resValue && fullTypeName) {
341
- resValue = this.fullTypeLookupWithNamespace(fullTypeName).value;
342
- }
343
- return {
344
- value: resValue,
345
- namespace,
346
- };
347
- }
348
- /**
349
- * this method needs to be refactored, an array can also be an array of an array for example
350
- * @param girVar
351
- * @returns
352
- */
353
- getArrayData(girVar) {
354
- let arrayType = null;
355
- let arrCType;
356
- let isArray = false;
357
- let overrideTypeName;
358
- let typeArray;
359
- let collection;
360
- if (girVar.array) {
361
- collection = girVar.array;
362
- }
363
- else if (/^GLib.S?List$/.test(girVar.type?.[0].$?.name || '')) {
364
- // This converts GLib.List<T> / GLib.SList<T> to T[]
365
- collection = girVar.type;
366
- }
367
- if (collection && collection.length > 0) {
368
- isArray = true;
369
- typeArray = collection[0].type;
370
- if (collection[0].$) {
371
- const ea = collection[0].$;
372
- arrCType = ea['c:type'];
373
- }
374
- }
375
- if (typeArray && typeArray?.length > 0) {
376
- arrayType = typeArray[0];
377
- }
378
- if (isArray && arrayType?.$?.name && POD_TYPE_MAP_ARRAY[arrayType.$.name]) {
379
- isArray = false;
380
- overrideTypeName = POD_TYPE_MAP_ARRAY[arrayType.$.name];
381
- }
382
- return {
383
- arrCType,
384
- arrayType,
385
- isArray,
386
- overrideTypeName,
387
- };
388
- }
389
- /**
390
- * Get the typescript type of a GirElement like a `GirPropertyElement` or `GirCallableReturn`
391
- * @param girVar
392
- */
393
- getTsType(girVar, tsClass, defaults = {}) {
394
- let type = girVar.type?.[0];
395
- let fullTypeName = null;
396
- let typeName = defaults.type || '';
397
- let isFunction = defaults.isFunction || false;
398
- let isCallback = defaults.isCallback || false;
399
- const nullable = this.typeIsNullable(girVar) || defaults.nullable || false;
400
- const optional = this.typeIsOptional(girVar) || defaults.optional || false;
401
- const girCallbacks = [];
402
- const array = this.getArrayData(girVar);
403
- if (array.overrideTypeName) {
404
- typeName = array.overrideTypeName;
405
- }
406
- if (array.arrayType) {
407
- type = array.arrayType;
408
- }
409
- const cType = type?.$ ? type.$['c:type'] : array.arrCType;
410
- fullTypeName = type?.$?.name || null;
411
- const callbacks = girVar.callback;
412
- if (!typeName && callbacks?.length) {
413
- for (const girCallback of callbacks) {
414
- if (!girElementIsIntrospectable(girCallback))
415
- continue;
416
- if (!girCallback._tsData) {
417
- const tsCallback = this.getFunctionTsData(girCallback, 'callback', tsClass, {
418
- isStatic: false,
419
- isArrowType: true,
420
- isGlobal: false,
421
- isVirtual: false,
422
- returnType: null,
423
- generics: [],
424
- });
425
- if (!tsCallback)
426
- continue;
427
- girCallback._tsData = {
428
- ...tsCallback,
429
- girTypeName: 'callback',
430
- tsTypeName: this.girFactory.girTypeNameToTsTypeName('callback', false),
431
- tsCallbackInterface: this.getCallbackInterfaceTsData(girCallback),
432
- doc: this.getTsDoc(girCallback),
433
- overloads: [],
434
- };
435
- }
436
- if (girCallback._tsData) {
437
- girCallbacks.push(girCallback);
438
- isFunction = true;
439
- isCallback = true;
440
- }
441
- }
442
- }
443
- if (!isFunction) {
444
- const res = this.fullTypeLookup(girVar, fullTypeName);
445
- if (res.value) {
446
- typeName = res.value;
447
- fullTypeName = typeName;
448
- }
449
- }
450
- if (!typeName && type?.$?.name && POD_TYPE_MAP[type.$.name]) {
451
- // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
452
- typeName = POD_TYPE_MAP[type.$.name];
453
- }
454
- if (cType) {
455
- if (!typeName && C_TYPE_MAP(cType)) {
456
- typeName = C_TYPE_MAP(cType) || '';
457
- }
458
- if (!typeName && POD_TYPE_MAP[cType]) {
459
- // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
460
- typeName = POD_TYPE_MAP[cType];
461
- }
462
- }
463
- if (!typeName) {
464
- typeName = 'any';
465
- const logName = cType || fullTypeName || girVar.$.name || '';
466
- this.log.warn(WARN_NOT_FOUND_TYPE(logName));
467
- }
468
- // TODO: transform array to type with generics?
469
- const tsType = this.girFactory.newTsType({
470
- ...defaults,
471
- type: typeName,
472
- optional,
473
- nullable,
474
- callbacks: girCallbacks,
475
- isArray: array.isArray,
476
- isFunction,
477
- isCallback,
478
- });
479
- return tsType;
480
- }
481
- /**
482
- *
483
- * @param girFunc
484
- * @returns
485
- */
486
- getReturnType(girFunc, tsClass, generics = []) {
487
- let outArrayLengthIndex = -1;
488
- if (girFunc['return-value'] && girFunc['return-value'].length > 1) {
489
- throw new Error('Several return values found!');
490
- }
491
- // There are no multiple return values, so we always use index 0
492
- const girVar = girFunc['return-value']?.[0] || null;
493
- // We still use an array to allow multiple return values for later
494
- const returnTypes = [];
495
- if (girVar) {
496
- returnTypes.push(this.getTsType(girVar, tsClass, { generics }));
497
- outArrayLengthIndex = girVar.array && girVar.array[0].$?.length ? Number(girVar.array[0].$.length) : -1;
498
- }
499
- else {
500
- returnTypes.push(this.girFactory.newTsType({ type: 'void', generics }));
501
- }
502
- const retTypeIsVoid = returnTypes.length === 1 && returnTypes[0].type === 'void';
503
- return { returnTypes, outArrayLengthIndex, retTypeIsVoid };
504
- }
505
- arrayLengthIndexLookup(girVar) {
506
- if (!girVar.array)
507
- return -1;
508
- const arr = girVar.array[0];
509
- if (!arr.$)
510
- return -1;
511
- if (arr.$.length) {
512
- return parseInt(arr.$.length);
513
- }
514
- return -1;
515
- }
516
- closureDataIndexLookup(girVar) {
517
- if (!girVar.$.closure)
518
- return -1;
519
- return parseInt(girVar.$.closure);
520
- }
521
- destroyDataIndexLookup(girVar) {
522
- if (!girVar.$.destroy)
523
- return -1;
524
- return parseInt(girVar.$.destroy);
525
- }
526
- processParams(params, skip, getIndex) {
527
- for (const param of params) {
528
- const index = getIndex(param);
529
- if (index < 0)
530
- continue;
531
- if (index >= params.length)
532
- continue;
533
- skip.push(params[index]);
534
- }
535
- }
536
- /**
537
- * Checks if the parameter is nullable (which results in ` | null`).
538
- *
539
- * @param girVar girVar to test
540
- */
541
- typeIsNullable(girVar) {
542
- const a = girVar.$;
543
- if (!a)
544
- return false;
545
- // Ignore depreciated `allow-none` if one of the new implementation `optional` or `nullable` is set
546
- if (girBool(a.optional) || girBool(a.nullable)) {
547
- return girBool(a.nullable);
548
- }
549
- else {
550
- return girBool(a.nullable) || girBool(a['allow-none']);
551
- }
552
- }
553
- /**
554
- * Checks if the parameter is optional (which results in `foo?: bar`).
555
- * @param girVar girVar to test
556
- */
557
- typeIsOptional(girVar) {
558
- const a = girVar.$;
559
- if (!a)
560
- return false;
561
- // Ignore depreciated `allow-none` if one of the new implementation `optional` or `nullable` is set
562
- if (girBool(a.optional) || girBool(a.nullable)) {
563
- return girBool(a.optional);
564
- }
565
- else {
566
- return girBool(a.optional) || girBool(a['allow-none']);
567
- }
568
- }
569
- setParameterTsData(girParam, girParams, paramNames, skip, parent) {
570
- // I think it's safest to force inout params to have the
571
- // same type for in and out
572
- const tsType = this.getTsType(girParam, parent.parent);
573
- // const optDirection = girParam.$.direction
574
- if (girParam._tsData) {
575
- // this.log.warn('[setParameterTsData] _tsData already set!')
576
- return girParam._tsData;
577
- }
578
- if (tsType.isCallback) {
579
- throw new Error('Callback type is not implemented here');
580
- }
581
- let paramName = this.transformation.transformParameterName(girParam, false);
582
- if (paramNames.includes(paramName)) {
583
- this.log.warn(WARN_DUPLICATE_PARAMETER(paramName, girParam._fullSymName));
584
- paramName += '_';
585
- }
586
- paramNames.push(paramName);
587
- // In Typescript no optional parameters are allowed if the following ones are not optional
588
- if (tsType.optional) {
589
- const index = girParams.indexOf(girParam);
590
- const following = girParams
591
- .slice(index)
592
- .filter(() => skip.indexOf(girParam) === -1)
593
- .filter((p) => p.$.direction !== 'out');
594
- if (following.some((p) => !this.typeIsOptional(p))) {
595
- tsType.optional = false;
596
- }
597
- }
598
- const tsParam = {
599
- name: paramName,
600
- type: [tsType],
601
- isRest: false,
602
- girTypeName: 'callable-param',
603
- doc: this.getTsDoc(girParam),
604
- parent,
605
- };
606
- girParam._tsData = tsParam;
607
- // // TODO: remove this, wee need a special solution for Gio.AsyncReadyCallback instead
608
- girParam = this.inject.toParameterType(girParam);
609
- return girParam._tsData;
610
- }
611
- getInstanceParameterTsData(instanceParameter) {
612
- const typeName = instanceParameter.type?.[0]?.$?.name || undefined;
613
- const rec = typeName ? this.ns.record?.find((r) => r.$.name == typeName) : undefined;
614
- const structFor = rec?.$['glib:is-gtype-struct-for'];
615
- if (structFor && instanceParameter.$.name) {
616
- // TODO: Should use of a constructor, and even of an instance, be discouraged?
617
- return {
618
- name: instanceParameter.$.name,
619
- structFor,
620
- };
621
- }
622
- return undefined;
623
- }
624
- setParametersTsData(outArrayLengthIndex, girParams = [], parent) {
625
- const outParams = [];
626
- const inParams = [];
627
- const paramNames = [];
628
- const instanceParameters = [];
629
- if (girParams && girParams.length > 0) {
630
- for (const girParam of girParams) {
631
- const params = girParam?.parameter || [];
632
- // Instance parameter needs to be exposed for class methods (see comment above getClassMethods())
633
- const instanceParameter = girParams[0]['instance-parameter']?.[0];
634
- if (instanceParameter) {
635
- instanceParameter._tsData = this.getInstanceParameterTsData(instanceParameter);
636
- if (instanceParameter._tsData) {
637
- instanceParameters.push(instanceParameter);
638
- }
639
- }
640
- if (params.length) {
641
- const skip = outArrayLengthIndex === -1 ? [] : [params[outArrayLengthIndex]];
642
- this.processParams(params, skip, (girVar) => this.arrayLengthIndexLookup(girVar));
643
- this.processParams(params, skip, (girVar) => this.closureDataIndexLookup(girVar));
644
- this.processParams(params, skip, (girVar) => this.destroyDataIndexLookup(girVar));
645
- for (const param of params) {
646
- if (skip.includes(param)) {
647
- continue;
648
- }
649
- param._tsData = this.setParameterTsData(param, params, paramNames, skip, parent);
650
- const optDirection = param.$.direction;
651
- if (optDirection === 'out' || optDirection === 'inout') {
652
- outParams.push(param);
653
- if (optDirection === 'out')
654
- continue;
655
- }
656
- inParams.push(param);
657
- }
658
- }
659
- }
660
- }
661
- return { outParams, paramNames, inParams, instanceParameters };
662
- }
663
- getVariableTsData(girVar, girTypeName, tsTypeName, tsClass, optional = false, nullable = false, allowQuotes = false, generics = []) {
664
- if (!girVar.$.name)
665
- return undefined;
666
- if (!girVar ||
667
- !girVar.$ ||
668
- !girBool(girVar.$.introspectable, true) ||
669
- girBool(girVar.$.private)) {
670
- return undefined;
671
- }
672
- if (girVar._tsData) {
673
- // this.log.warn('[getVariableTsData] _tsData already set!')
674
- return girVar._tsData;
675
- }
676
- let name = girVar.$.name;
677
- switch (girTypeName) {
678
- case 'property':
679
- name = this.transformation.transformPropertyName(girVar.$.name, allowQuotes);
680
- break;
681
- case 'constant':
682
- name = this.transformation.transformConstantName(girVar.$.name, allowQuotes);
683
- break;
684
- case 'field':
685
- name = this.transformation.transformFieldName(girVar.$.name, allowQuotes);
686
- break;
687
- }
688
- // Use the out type because it can be a union which isn't appropriate
689
- // for a property
690
- const tsType = this.getTsType(girVar, tsClass, { optional, nullable, generics });
691
- const tsData = {
692
- name,
693
- type: [tsType],
694
- isInjected: false,
695
- girTypeName,
696
- tsTypeName,
697
- doc: this.getTsDoc(girVar),
698
- };
699
- tsData.doc.tags.push(...this.getTsDocGirElementTags(tsData.tsTypeName, tsData.girTypeName));
700
- return tsData;
701
- }
702
- /**
703
- *
704
- * @param girProp
705
- * @param girTypeName
706
- * @param tsTypeName
707
- * @param construct construct means include the property even if it's construct-only,
708
- * @param optional optional means if it's construct-only it will also be marked optional (?)
709
- * @param nullable
710
- * @returns
711
- */
712
- getPropertyTsData(girProp, girTypeName, tsTypeName, tsClass, construct = false, optional, nullable) {
713
- if (!girBool(girProp.$.writable) && construct)
714
- return undefined;
715
- if (girBool(girProp.$.private))
716
- return undefined;
717
- if (girProp._tsData) {
718
- // this.log.warn('[getPropertyTsData] _tsData already set!')
719
- return girProp._tsData;
720
- }
721
- if (optional === undefined)
722
- optional = this.typeIsOptional(girProp);
723
- if (nullable === undefined)
724
- nullable = this.typeIsNullable(girProp);
725
- const readonly = !girBool(girProp.$.writable) || (!construct && girBool(girProp.$['construct-only']));
726
- let tsData;
727
- switch (girTypeName) {
728
- case 'property':
729
- tsData = this.getVariableTsData(girProp, girTypeName, tsTypeName, tsClass, construct && optional, construct && nullable, true);
730
- break;
731
- case 'field':
732
- if (tsTypeName !== 'property') {
733
- throw new Error(`Wrong tsType: "${tsTypeName}" for girType: "${girTypeName}`);
734
- }
735
- tsData = this.getVariableTsData(girProp, girTypeName, tsTypeName, tsClass, construct && optional, construct && nullable, true);
736
- break;
737
- default:
738
- throw new Error(`Unknown property type: ${girTypeName}`);
739
- }
740
- if (!tsData?.name) {
741
- return undefined;
742
- }
743
- tsData = {
744
- ...tsData,
745
- readonly,
746
- };
747
- return tsData;
748
- }
749
- /**
750
- *
751
- * @param girFunc
752
- * @param prefix E.g. vfunc
753
- * @param overrideReturnType
754
- * @param isArrowType
755
- * @param indentCount
756
- */
757
- getFunctionTsData(girFunc, girTypeName, tsClass, overwrite) {
758
- if (!girFunc || !girFunc.$ || !girBool(girFunc.$.introspectable, true) || girFunc.$['shadowed-by']) {
759
- return undefined;
760
- }
761
- let hasUnresolvedConflict;
762
- // TODO: Fix that we overwrite tsData every time seems wrong to me, but if I just return the already defined `_tsData` leads to problems with the overload methods
763
- if (girFunc._tsData) {
764
- hasUnresolvedConflict = girFunc._tsData?.hasUnresolvedConflict; // WORKAROUND do not overwrite conflicts
765
- }
766
- let name = girFunc.$.name;
767
- const { returnTypes, outArrayLengthIndex, retTypeIsVoid } = this.getReturnType(girFunc, tsClass);
768
- const shadows = girFunc.$.shadows;
769
- if (shadows) {
770
- name = shadows;
771
- }
772
- // Overwrites
773
- overwrite.isStatic = overwrite.isStatic || girTypeName === 'static-function' || girTypeName === 'constructor';
774
- overwrite.isGlobal = overwrite.isGlobal || girTypeName === 'function';
775
- overwrite.isVirtual = overwrite.isVirtual || girTypeName === 'virtual';
776
- overwrite.isInjected = overwrite.isInjected || false;
777
- // Function name transformation by environment
778
- name = this.transformation.transformFunctionName(name, overwrite.isVirtual);
779
- const tsData = {
780
- isArrowType: overwrite.isArrowType,
781
- isStatic: overwrite.isStatic,
782
- isGlobal: overwrite.isGlobal,
783
- isVirtual: overwrite.isVirtual,
784
- isInjected: overwrite.isInjected,
785
- returnTypes,
786
- retTypeIsVoid,
787
- name,
788
- overrideReturnType: overwrite.returnType || undefined,
789
- inParams: [],
790
- outParams: [],
791
- instanceParameters: [],
792
- generics: overwrite.generics,
793
- hasUnresolvedConflict,
794
- girTypeName,
795
- tsTypeName: this.girFactory.girTypeNameToTsTypeName(girTypeName, overwrite.isStatic),
796
- doc: this.getTsDoc(girFunc),
797
- overloads: [],
798
- parent: tsClass,
799
- };
800
- const { inParams, outParams, instanceParameters } = this.setParametersTsData(outArrayLengthIndex, girFunc.parameters, tsData);
801
- tsData.inParams.push(...inParams);
802
- tsData.outParams.push(...outParams);
803
- tsData.instanceParameters.push(...instanceParameters);
804
- tsData.doc.tags.push(...this.getTsDocGirElementTags(tsData.tsTypeName, tsData.girTypeName));
805
- tsData.doc.tags.push(...this.getTsDocInParamTags(tsData?.inParams));
806
- return tsData;
807
- }
808
- getCallbackInterfaceTsData(girCallback) {
809
- if (!girElementIsIntrospectable(girCallback))
810
- return undefined;
811
- const namespace = this.namespace;
812
- const tsDataInterface = {
813
- name: `${namespace}.${girCallback.$.name}`,
814
- generics: [],
815
- };
816
- return tsDataInterface;
817
- }
818
- setCallbackTsData(girCallback, tsClass) {
819
- const tsFunction = this.getFunctionTsData(girCallback, 'callback', tsClass, {
820
- isStatic: false,
821
- isArrowType: true,
822
- isGlobal: false,
823
- isVirtual: false,
824
- returnType: null,
825
- generics: [],
826
- });
827
- if (tsFunction) {
828
- const tsCallback = {
829
- ...tsFunction,
830
- girTypeName: 'callback',
831
- tsTypeName: this.girFactory.girTypeNameToTsTypeName('callback', false),
832
- tsCallbackInterface: this.getCallbackInterfaceTsData(girCallback),
833
- overloads: [],
834
- };
835
- girCallback._tsData = tsCallback;
836
- this.inject.toCallback(girCallback);
837
- }
838
- return girCallback._tsData;
839
- }
840
- getSignalCallbackInterfaceTsData(girCallback, girClass) {
841
- if (!girElementIsIntrospectable(girCallback))
842
- return undefined;
843
- if (!girClass._tsData || !girClass._module) {
844
- throw new Error(NO_TSDATA('getSignalCallbackTsData'));
845
- }
846
- const className = girClass._tsData.name;
847
- const signalName = girCallback.$.name;
848
- const signalInterfaceName = this.transformation.transformSignalInterfaceName(signalName);
849
- const namespace = girClass._module.namespace;
850
- const tsDataInterface = {
851
- name: `${namespace}.${className}.${signalInterfaceName}SignalCallback`,
852
- generics: [],
853
- overwriteDoc: {
854
- text: `Signal callback interface for \`${signalName}\``,
855
- tags: [],
856
- },
857
- };
858
- return tsDataInterface;
859
- }
860
- getConstructorFunctionTsData(parentClass, girConstructor) {
861
- if (!girElementIsIntrospectable(girConstructor))
862
- return;
863
- const constructorTypeName = addNamespace(parentClass.name, parentClass.namespace);
864
- return this.getFunctionTsData(girConstructor, 'constructor', parentClass, {
865
- isStatic: true,
866
- isArrowType: false,
867
- isGlobal: false,
868
- isVirtual: false,
869
- returnType: constructorTypeName,
870
- generics: [],
871
- });
872
- }
873
- getSignalCallbackTsData(girSignalFunc, girClass) {
874
- if (!girClass._tsData) {
875
- throw new Error(NO_TSDATA('getSignalCallbackTsData'));
876
- }
877
- if (girSignalFunc._tsData) {
878
- return girSignalFunc._tsData;
879
- }
880
- // Leads to errors here
881
- // if (!girElementIsIntrospectable(girSignalFunc)) return undefined
882
- const name = this.transformation.transform('signalName', girSignalFunc.$.name);
883
- const { returnTypes, outArrayLengthIndex, retTypeIsVoid } = this.getReturnType(girSignalFunc, girClass._tsData);
884
- if (this.config.environment === 'node') {
885
- returnTypes[0].type === 'void';
886
- }
887
- const tsCallback = {
888
- name,
889
- returnTypes,
890
- isArrowType: true,
891
- isStatic: false,
892
- isGlobal: false,
893
- isVirtual: false,
894
- isInjected: false,
895
- retTypeIsVoid,
896
- inParams: [],
897
- instanceParameters: [],
898
- outParams: [],
899
- generics: [],
900
- girTypeName: 'callback',
901
- tsTypeName: this.girFactory.girTypeNameToTsTypeName('callback', false),
902
- doc: this.getTsDoc(girSignalFunc),
903
- overloads: [],
904
- parent: girClass._tsData,
905
- };
906
- const { inParams, outParams, instanceParameters } = this.setParametersTsData(outArrayLengthIndex, girSignalFunc.parameters, tsCallback);
907
- if (this.config.environment === 'gjs') {
908
- inParams.unshift(this.girFactory.newGirCallableParamElement({
909
- name: '$obj',
910
- type: [
911
- {
912
- type: girClass._tsData.name,
913
- },
914
- ],
915
- }, tsCallback));
916
- }
917
- tsCallback.inParams.push(...inParams);
918
- tsCallback.outParams.push(...outParams);
919
- tsCallback.instanceParameters.push(...instanceParameters);
920
- tsCallback.doc.tags.push(...this.getTsDocGirElementTags(tsCallback.tsTypeName, tsCallback.girTypeName));
921
- tsCallback.doc.tags.push(...this.getTsDocInParamTags(tsCallback?.inParams));
922
- return tsCallback;
923
- }
924
- /**
925
- * Generates signal methods like `connect`, `connect_after` and `emit` on Gjs or `connect`, `on`, `once`, `off` and `emit` an node-gtk
926
- * for a default gir signal element
927
- * @param girSignal
928
- * @returns
929
- */
930
- getClassSignalMethodsTsData(girSignal, parentClass) {
931
- if (!girSignal._tsData) {
932
- throw new Error(NO_TSDATA('getClassSignalMethodsTsData'));
933
- }
934
- const inParams = girSignal._tsData.inParams.slice(1).map((inParam) => {
935
- const injectParam = {
936
- ...inParam._tsData,
937
- type: inParam._tsData?.type || [],
938
- name: inParam._tsData?.name || 'unknown',
939
- };
940
- return injectParam;
941
- });
942
- return this.girFactory.newTsSignalMethods(girSignal._tsData?.name, girSignal._tsData?.tsCallbackInterface?.name, inParams, parentClass, this.config.environment, false);
943
- }
944
- /**
945
- * Generates signal methods for the GObject properties of a gir class element
946
- * @param girClass
947
- */
948
- getClassPropertySignalsMethods(girClass) {
949
- if (!girClass._tsData) {
950
- throw new Error(NO_TSDATA('getClassPropertySignalsMethods'));
951
- }
952
- const tsMethods = [];
953
- const propertyNames = this.getClassNonStaticPropertyNames(girClass);
954
- const namespacePrefix = this.namespace === 'GObject' ? '' : 'GObject.';
955
- // TODO: Signals: Generate SignalMethods instead of direct types
956
- for (const propertyName of propertyNames) {
957
- let callbackType = 'any';
958
- if (this.config.environment === 'gjs') {
959
- const objParam = `$obj: ${girClass._tsData.name}`;
960
- // TODO: create arrowType object instead of a pure string type, see Pango-1.0.Pango.FontMapClass.load_font for an example
961
- callbackType = `((${objParam}, pspec: ${namespacePrefix}ParamSpec) => void)`;
962
- }
963
- else if (this.config.environment === 'node') {
964
- callbackType = `(...args: any[]) => void`;
965
- }
966
- tsMethods.push(...this.girFactory.newTsSignalMethods(`notify::${propertyName}`, callbackType, [], girClass._tsData, this.config.environment));
967
- }
968
- return tsMethods;
969
- }
970
- getGeneralSignalsMethods(parentClass) {
971
- return this.girFactory.newTsSignalMethods(undefined, undefined, [], parentClass, this.config.environment, true);
972
- }
973
- setSignalTsData(girSignal, girClass) {
974
- if (!girClass._tsData) {
975
- throw NO_TSDATA('setSignalTsData');
976
- }
977
- if (!girSignal._tsData) {
978
- girSignal._tsData = {
979
- ...this.getSignalCallbackTsData(girSignal, girClass),
980
- tsCallbackInterface: this.getSignalCallbackInterfaceTsData(girSignal, girClass),
981
- tsMethods: [],
982
- girTypeName: 'signal',
983
- tsTypeName: this.girFactory.girTypeNameToTsTypeName('signal', false),
984
- doc: this.getTsDoc(girSignal),
985
- overloads: [],
986
- };
987
- girSignal._tsData.doc.tags.push(...this.getTsDocGirElementTags(girSignal._tsData.tsTypeName, girSignal._tsData.girTypeName));
988
- // TODO: this are the callback parameters
989
- girSignal._tsData.doc.tags.push(...this.getTsDocInParamTags(girSignal._tsData?.inParams));
990
- if (!girSignal._tsData) {
991
- throw NO_TSDATA('setSignalTsData');
992
- }
993
- girSignal._tsData.tsMethods = this.getClassSignalMethodsTsData(girSignal, girClass._tsData);
994
- }
995
- return girSignal._tsData;
996
- }
997
- fixEnumerationDuplicateIdentifier(girEnum) {
998
- if (!girElementIsIntrospectable(girEnum))
999
- return girEnum;
1000
- if (!girEnum._tsData) {
1001
- throw new Error(NO_TSDATA('fixEnumerationDuplicateIdentifier'));
1002
- }
1003
- if (!girEnum.member?.length) {
1004
- return girEnum;
1005
- }
1006
- const memberNames = [];
1007
- for (const girEnumMember of girEnum.member) {
1008
- if (!girEnumMember._tsData) {
1009
- throw new Error(NO_TSDATA('fixEnumerationDuplicateIdentifier'));
1010
- }
1011
- if (memberNames.find((name) => name === girEnumMember._tsData?.name)) {
1012
- const renamed = '_' + girEnumMember._tsData.name;
1013
- this.log.warn(WARN_DUPLICATE_ENUM_IDENTIFIER(girEnumMember._tsData.name, renamed));
1014
- girEnumMember._tsData.name = renamed;
1015
- }
1016
- memberNames.push(girEnumMember._tsData.name);
1017
- }
1018
- return girEnum;
1019
- }
1020
- getEnumerationMemberTsData(girEnumMember, girTypeName) {
1021
- const memberName = girEnumMember.$.name || girEnumMember.$['glib:nick'] || girEnumMember.$['c:identifier'];
1022
- if (!girElementIsIntrospectable(girEnumMember, memberName))
1023
- return undefined;
1024
- if (girEnumMember._tsData) {
1025
- // this.log.warn('[getEnumerationMemberTsData] _tsData already set!')
1026
- return girEnumMember._tsData;
1027
- }
1028
- const name = this.transformation.transformEnumMember(memberName);
1029
- const tsData = {
1030
- name,
1031
- girTypeName,
1032
- tsTypeName: this.girFactory.girTypeNameToTsTypeName(girTypeName, false),
1033
- doc: this.getTsDoc(girEnumMember),
1034
- };
1035
- tsData.doc.tags.push(...this.getTsDocGirElementTags(tsData.tsTypeName, tsData.girTypeName));
1036
- return tsData;
1037
- }
1038
- getEnumerationTsData(girEnum, girTypeName) {
1039
- if (!girElementIsIntrospectable(girEnum))
1040
- return undefined;
1041
- if (girEnum._tsData) {
1042
- // this.log.warn('[getEnumerationMemberTsData] _tsData already set!')
1043
- return girEnum._tsData;
1044
- }
1045
- // E.g. the NetworkManager-1.0 has enum names starting with 80211
1046
- const name = this.transformation.transformEnumName(girEnum);
1047
- const tsData = {
1048
- name,
1049
- girTypeName,
1050
- tsTypeName: this.girFactory.girTypeNameToTsTypeName(girTypeName, false),
1051
- doc: this.getTsDoc(girEnum),
1052
- };
1053
- tsData.doc.tags.push(...this.getTsDocGirElementTags(tsData.tsTypeName, tsData.girTypeName));
1054
- return tsData;
1055
- }
1056
- getAliasTsData(girAlias, tsClass) {
1057
- if (!girElementIsIntrospectable(girAlias))
1058
- return undefined;
1059
- if (girAlias._tsData) {
1060
- // this.log.warn('[getEnumerationMemberTsData] _tsData already set!')
1061
- return girAlias._tsData;
1062
- }
1063
- const { type: typeName } = this.getTsType(girAlias, tsClass);
1064
- const name = girAlias.$.name;
1065
- const tsData = {
1066
- name,
1067
- type: typeName,
1068
- girTypeName: 'alias',
1069
- tsTypeName: this.girFactory.girTypeNameToTsTypeName('alias', false),
1070
- };
1071
- return tsData;
1072
- }
1073
- getConstantTsData(girConst, tsClass) {
1074
- if (!girElementIsIntrospectable(girConst))
1075
- return undefined;
1076
- if (girConst._tsData) {
1077
- // this.log.warn('[getConstantTsData] _tsData already set!')
1078
- return girConst._tsData;
1079
- }
1080
- let tsData = this.getVariableTsData(girConst, 'constant', 'constant', tsClass, false, false, false);
1081
- if (tsData?.name) {
1082
- if (!this.constNames[tsData.name]) {
1083
- this.constNames[tsData.name] = girConst;
1084
- }
1085
- else {
1086
- this.log.warn(WARN_CONSTANT_ALREADY_EXPORTED(tsData.name));
1087
- tsData = undefined;
1088
- }
1089
- }
1090
- return tsData;
1091
- }
1092
- getClassConstructPropsTsData(girClass, constructPropNames) {
1093
- const constructProps = [];
1094
- const girProperties = girClass.property;
1095
- if (!girProperties?.length) {
1096
- return constructProps;
1097
- }
1098
- for (const girProp of girProperties) {
1099
- if (!girElementIsIntrospectable(girProp) || !girProp.$.name)
1100
- continue;
1101
- // Do not modify the original girProp, create a new one by clone `girProp` to `girConstrProp`
1102
- const girConstrProp = clone(girProp);
1103
- if (!girClass._tsData)
1104
- continue;
1105
- if (!girConstrProp._tsData) {
1106
- girConstrProp._tsData = this.getPropertyTsData(girConstrProp, 'property', 'constructor-property', girClass._tsData, true, true, true, 0);
1107
- }
1108
- if (!girConstrProp._tsData) {
1109
- continue;
1110
- }
1111
- const localName = this.checkOrSetLocalName(girConstrProp, constructPropNames, 'property');
1112
- if (!localName?.added) {
1113
- continue;
1114
- }
1115
- if (girConstrProp._fullSymName)
1116
- this.symTable.set(this.allDependencies, girConstrProp._fullSymName, girConstrProp);
1117
- constructProps.push(girConstrProp);
1118
- }
1119
- return constructProps;
1120
- }
1121
- /**
1122
- * Some class/static methods are defined in a separate record which is not
1123
- * exported, but the methods are available as members of the JS constructor.
1124
- * In gjs one can use an instance of the object, a JS constructor or a GType
1125
- * as the method's instance-parameter.
1126
- * @see https://discourse.gnome.org/t/using-class-methods-like-gtk-widget-class-get-css-name-from-gjs/4001
1127
- * @param girClass
1128
- */
1129
- getClassRecordMethods(girClass) {
1130
- const girMethods = [];
1131
- if (!girClass.$.name)
1132
- return girMethods;
1133
- const fName = girClass.$.name + 'Class';
1134
- let rec = this.ns.record?.find((r) => r.$.name == fName);
1135
- if (!rec || !this.isGtypeStructFor(girClass, rec)) {
1136
- rec = this.ns.record?.find((r) => this.isGtypeStructFor(girClass, r));
1137
- fName == rec?.$.name;
1138
- }
1139
- if (!rec)
1140
- return girMethods;
1141
- // Record methods
1142
- const methods = rec.method || [];
1143
- for (const girMethod of methods) {
1144
- if (!girElementIsIntrospectable(girMethod) || !girClass._tsData)
1145
- continue;
1146
- if (!girMethod._tsData)
1147
- girMethod._tsData = this.getFunctionTsData(girMethod, 'static-function', girClass._tsData, {
1148
- isStatic: true,
1149
- isArrowType: false,
1150
- isGlobal: false,
1151
- isVirtual: false,
1152
- returnType: null,
1153
- generics: [],
1154
- });
1155
- if (!girMethod._tsData)
1156
- continue;
1157
- if (girMethod._tsData) {
1158
- if (girMethod._fullSymName)
1159
- this.symTable.set(this.allDependencies, girMethod._fullSymName, girMethod);
1160
- girMethods.push(girMethod);
1161
- }
1162
- }
1163
- return girMethods;
1164
- }
1165
- /**
1166
- * Instance methods
1167
- * @param girClass
1168
- * @param localNames
1169
- */
1170
- getClassMethodsTsData(girClass, localNames) {
1171
- const girMethods = [];
1172
- if (girClass.method) {
1173
- for (const girMethod of girClass.method) {
1174
- if (!girElementIsIntrospectable(girMethod) || !girClass._tsData)
1175
- continue;
1176
- if (!girMethod._tsData)
1177
- girMethod._tsData = this.getFunctionTsData(girMethod, 'method', girClass._tsData, {
1178
- isStatic: false,
1179
- isArrowType: false,
1180
- isGlobal: false,
1181
- isVirtual: false,
1182
- returnType: null,
1183
- generics: [],
1184
- });
1185
- if (!girMethod._tsData)
1186
- continue;
1187
- const localName = this.checkOrSetLocalName(girMethod, localNames, 'method');
1188
- if (localName?.added && localName.method) {
1189
- if (girMethod._fullSymName)
1190
- this.symTable.set(this.allDependencies, girMethod._fullSymName, girMethod);
1191
- girMethods.push(localName.method);
1192
- }
1193
- }
1194
- }
1195
- return girMethods;
1196
- }
1197
- getClassFieldsTsData(girClass, localNames) {
1198
- const girFields = [];
1199
- if (!girClass._tsData) {
1200
- this.log.warn(NO_TSDATA('setClassFieldsTsData'));
1201
- return girFields;
1202
- }
1203
- if (girClass.field) {
1204
- for (const girField of girClass.field) {
1205
- if (!girElementIsIntrospectable(girField))
1206
- continue;
1207
- if (!girField._tsData)
1208
- girField._tsData = this.getVariableTsData(girField, 'field', 'property', girClass._tsData, false, false, false);
1209
- if (!girField._tsData) {
1210
- continue;
1211
- }
1212
- const localName = this.checkOrSetLocalName(girField, localNames, 'field');
1213
- if (localName?.added && localName.field) {
1214
- if (girField._fullSymName)
1215
- this.symTable.set(this.allDependencies, girField._fullSymName, girField);
1216
- girFields.push(localName.field);
1217
- }
1218
- }
1219
- }
1220
- return girFields;
1221
- }
1222
- getGObjectProperties(girClass) {
1223
- const girProperties = [];
1224
- if (girClass._fullSymName && !STATIC_NAME_ALREADY_EXISTS.includes(girClass._fullSymName)) {
1225
- // Records, classes and interfaces all have a static name
1226
- const type = this.girFactory.newTsType({ type: 'string' });
1227
- const staticNameProp = this.girFactory.newGirProperty({
1228
- isStatic: true,
1229
- name: 'name',
1230
- type: [type],
1231
- girTypeName: 'property',
1232
- });
1233
- girProperties.push(staticNameProp);
1234
- }
1235
- if (girClass._tsData?.isDerivedFromGObject && girClass._module) {
1236
- if (this.config.environment === 'gjs') {
1237
- const type = this.girFactory.newTsType({
1238
- // TODO: Type not as string
1239
- type: 'GObject.GType',
1240
- generics: this.girFactory.newGenerics([
1241
- {
1242
- value: girClass._tsData.name,
1243
- },
1244
- ]),
1245
- });
1246
- const staticGTypeProp = this.girFactory.newGirProperty({
1247
- isStatic: true,
1248
- name: '$gtype',
1249
- type: [type],
1250
- girTypeName: 'property',
1251
- });
1252
- girProperties.push(staticGTypeProp);
1253
- }
1254
- else if (this.config.environment === 'node') {
1255
- const staticGTypeProp = this.girFactory.newGirProperty({
1256
- isStatic: false,
1257
- name: '__gtype__',
1258
- type: [{ type: 'number' }],
1259
- girTypeName: 'property',
1260
- });
1261
- girProperties.push(staticGTypeProp);
1262
- }
1263
- }
1264
- return girProperties;
1265
- }
1266
- getClassPropertiesTsData(girClass, localNames) {
1267
- const girProperties = [];
1268
- const properties = girClass.property;
1269
- if (properties) {
1270
- for (const girProperty of properties) {
1271
- if (!girElementIsIntrospectable(girProperty) || !girClass._tsData)
1272
- continue;
1273
- girProperty._tsData = this.getPropertyTsData(girProperty, 'property', 'property', girClass._tsData);
1274
- if (!girProperty._tsData)
1275
- continue;
1276
- const localName = this.checkOrSetLocalName(girProperty, localNames, 'property');
1277
- if (localName?.added && localName.property) {
1278
- if (girProperty._fullSymName)
1279
- this.symTable.set(this.allDependencies, girProperty._fullSymName, girProperty);
1280
- girProperties.push(localName.property);
1281
- }
1282
- }
1283
- }
1284
- return girProperties;
1285
- }
1286
- getClassNonStaticPropertyNames(girClass) {
1287
- const propertyNames = [];
1288
- if (!girClass._tsData) {
1289
- return propertyNames;
1290
- }
1291
- const girProperties = girClass._tsData.properties;
1292
- if (girProperties.length > 0) {
1293
- for (const girProperty of girProperties) {
1294
- if (!girElementIsIntrospectable(girProperty))
1295
- continue;
1296
- if (girProperty.$.name &&
1297
- !propertyNames.includes(girProperty.$.name) &&
1298
- !girProperty._tsData?.isStatic) {
1299
- propertyNames.push(girProperty.$.name);
1300
- }
1301
- }
1302
- }
1303
- // Extended property names
1304
- for (const fullSymName of Object.keys(girClass._tsData.inherit)) {
1305
- const girProperties = girClass._tsData.inherit[fullSymName]?.class.properties;
1306
- if (girProperties.length > 0) {
1307
- for (const girProperty of girProperties) {
1308
- if (!girElementIsIntrospectable(girProperty))
1309
- continue;
1310
- if (girProperty.$.name &&
1311
- !propertyNames.includes(girProperty.$.name) &&
1312
- !girProperty._tsData?.isStatic) {
1313
- propertyNames.push(girProperty.$.name);
1314
- }
1315
- }
1316
- }
1317
- }
1318
- // Implemented property names
1319
- for (const fullSymName of Object.keys(girClass._tsData.implements)) {
1320
- const girProperties = girClass._tsData.implements[fullSymName]?.interface.properties;
1321
- if (girProperties.length > 0) {
1322
- for (const girProperty of girProperties) {
1323
- if (!girElementIsIntrospectable(girProperty))
1324
- continue;
1325
- if (girProperty._tsData &&
1326
- girProperty.$.name &&
1327
- !propertyNames.includes(girProperty.$.name) &&
1328
- !girProperty._tsData?.isStatic) {
1329
- propertyNames.push(girProperty.$.name);
1330
- }
1331
- }
1332
- }
1333
- }
1334
- return propertyNames;
1335
- }
1336
- getClassConstructorsTsData(girClass) {
1337
- if (!girClass._tsData) {
1338
- throw new Error(NO_TSDATA('getClassConstructorsTsData'));
1339
- }
1340
- const girConstructors = [];
1341
- // JS constructor(s)
1342
- if (girClass._tsData?.isDerivedFromGObject) {
1343
- const constructorInParam = {
1344
- name: 'config',
1345
- type: [
1346
- {
1347
- optional: true,
1348
- type: girClass._tsData.constructPropInterfaceName,
1349
- },
1350
- ],
1351
- };
1352
- const realConstructor = this.girFactory.newGirFunction({
1353
- name: 'constructor',
1354
- isStatic: true,
1355
- inParams: [constructorInParam],
1356
- girTypeName: 'constructor',
1357
- }, girClass._tsData);
1358
- const initConstructor = this.girFactory.newGirFunction({
1359
- name: '_init',
1360
- inParams: [constructorInParam],
1361
- girTypeName: 'method',
1362
- }, girClass._tsData);
1363
- girConstructors.push(realConstructor, initConstructor);
1364
- }
1365
- if (Array.isArray(girClass.constructor)) {
1366
- for (const girConstructor of girClass.constructor) {
1367
- if (!girElementIsIntrospectable(girConstructor))
1368
- continue;
1369
- girConstructor._tsData = this.getConstructorFunctionTsData(girClass._tsData, girConstructor);
1370
- if (!girConstructor._tsData?.name)
1371
- continue;
1372
- // Also add `new` pseudo constructors
1373
- const ADD_NEW_PSEUDO_CONSTRUCTOR = true;
1374
- // Inject an additional real constructor if static new(...) exists
1375
- if (girConstructor._tsData.name === 'new') {
1376
- const realConstructor = clone(girConstructor);
1377
- realConstructor._tsData = clone(realConstructor._tsData);
1378
- if (realConstructor._tsData) {
1379
- realConstructor._tsData.overloads = [];
1380
- realConstructor.$.name = 'constructor';
1381
- realConstructor._tsData.name = 'constructor';
1382
- girConstructors.push(realConstructor);
1383
- }
1384
- if (ADD_NEW_PSEUDO_CONSTRUCTOR) {
1385
- girConstructors.push(girConstructor);
1386
- }
1387
- }
1388
- else {
1389
- girConstructors.push(girConstructor);
1390
- }
1391
- }
1392
- }
1393
- return girConstructors;
1394
- }
1395
- getClassVirtualMethodsTsData(girClass) {
1396
- const methods = girClass['virtual-method'] || [];
1397
- const girMethods = [];
1398
- for (const girVMethod of methods) {
1399
- if (!girElementIsIntrospectable(girVMethod) || !girClass._tsData)
1400
- continue;
1401
- girVMethod._tsData = this.getFunctionTsData(girVMethod, 'virtual', girClass._tsData, {
1402
- isStatic: false,
1403
- isArrowType: false,
1404
- isGlobal: false,
1405
- isVirtual: true,
1406
- returnType: null,
1407
- generics: [],
1408
- });
1409
- if (!girVMethod._tsData)
1410
- continue;
1411
- if (girVMethod?._tsData?.name) {
1412
- girMethods.push(girVMethod);
1413
- }
1414
- }
1415
- return girMethods;
1416
- }
1417
- /**
1418
- *
1419
- * @param girClass This is the class / interface the `parentClass` implements signals from
1420
- * @returns
1421
- */
1422
- getClassSignalsTsData(girClass) {
1423
- const girSignals = [];
1424
- const signals = girClass.signal ||
1425
- girClass['glib:signal'] ||
1426
- [];
1427
- if (signals) {
1428
- for (const girSignal of signals) {
1429
- girSignal._tsData = this.setSignalTsData(girSignal, girClass);
1430
- if (!girSignal._tsData)
1431
- continue;
1432
- if (girSignal._fullSymName)
1433
- this.symTable.set(this.allDependencies, girSignal._fullSymName, girSignal);
1434
- girSignals.push(girSignal);
1435
- }
1436
- }
1437
- return girSignals;
1438
- }
1439
- getClassParentObject(parentName, namespace, type) {
1440
- let qualifiedParentName;
1441
- let parentModName;
1442
- // Workaround: Fix wrong parent names
1443
- if ((this.packageName === 'GstAudio-0.10' || this.packageName === 'ClutterGst-1.0') &&
1444
- (parentName === 'GstBase.BaseTransform' ||
1445
- parentName === 'GstBase.BaseSink' ||
1446
- parentName === 'GstBase.PushSrc')) {
1447
- const rename = parentName.replace('GstBase.', 'Gst.');
1448
- this.log.warn(`[getClassParentObject] Rename parent class "${parentName}" -> "${rename}"`);
1449
- parentName = rename;
1450
- }
1451
- if (parentName === 'GraniteServicesSettingsSerializable') {
1452
- parentName = 'ServicesSettingsSerializable';
1453
- this.log.warn(`[getClassParentObject] Rename parent class "GraniteServicesSettingsSerializable" -> "ServicesSettingsSerializable"`);
1454
- }
1455
- if (parentName.indexOf('.') < 0) {
1456
- qualifiedParentName = namespace + '.' + parentName;
1457
- parentModName = namespace;
1458
- }
1459
- else {
1460
- qualifiedParentName = parentName;
1461
- const split = parentName.split('.');
1462
- parentName = split[split.length - 1];
1463
- parentModName = split.slice(0, split.length - 1).join('.');
1464
- }
1465
- const localParentName = parentModName == namespace ? parentName : qualifiedParentName;
1466
- const cls = this.getClassParent({
1467
- qualifiedParentName,
1468
- parentName,
1469
- });
1470
- return {
1471
- qualifiedParentName,
1472
- localParentName,
1473
- type,
1474
- parentName,
1475
- cls,
1476
- // TODO: are there other types that can be inherited or implemented?
1477
- girTypeName: type === 'parent' ? 'class' : 'interface',
1478
- };
1479
- }
1480
- getClassParents(girClass) {
1481
- const parents = [];
1482
- if (!girClass._module?.namespace) {
1483
- throw new Error('Namespace not found!');
1484
- }
1485
- if (!girClass._tsData) {
1486
- throw new Error(NO_TSDATA('getClassParents'));
1487
- }
1488
- const prerequisites = girClass?.prerequisite;
1489
- const implmts = girClass?.implements;
1490
- if (implmts) {
1491
- for (const implement of implmts) {
1492
- const parentName = implement.$?.name;
1493
- if (!parentName)
1494
- continue;
1495
- parents.push(this.getClassParentObject(parentName, girClass._module.namespace, 'implements'));
1496
- }
1497
- }
1498
- if (prerequisites) {
1499
- for (const prerequisite of prerequisites) {
1500
- const parentName = prerequisite.$?.name;
1501
- if (!parentName)
1502
- continue;
1503
- parents.push(this.getClassParentObject(parentName, girClass._module.namespace, 'prerequisite'));
1504
- }
1505
- }
1506
- if (girClass.$.parent) {
1507
- const parentName = girClass.$.parent;
1508
- if (parentName) {
1509
- parents.push(this.getClassParentObject(parentName, girClass._module.namespace, 'parent'));
1510
- }
1511
- }
1512
- // Please reply: Do all interfaces always inherit from GObject.Object?
1513
- // If this is a interface and GObject.Object is not in the parents array, add GObject.Object to the parents
1514
- if (girClass._tsData.girTypeName === 'interface' && girClass._fullSymName !== 'GObject.Object') {
1515
- if (!parents.find((parent) => parent.qualifiedParentName === 'GObject.Object')) {
1516
- // TODO make sure this class exists in symTable
1517
- const gObjectObjectCls = this.symTable.getByHand('GObject-2.0.GObject.Object') || undefined;
1518
- parents.push({
1519
- qualifiedParentName: 'GObject.Object',
1520
- localParentName: girClass._module.namespace === 'GObject' ? 'Object' : 'GObject.Object',
1521
- type: 'parent',
1522
- parentName: 'Object',
1523
- cls: gObjectObjectCls,
1524
- girTypeName: 'class',
1525
- });
1526
- }
1527
- }
1528
- return parents;
1529
- }
1530
- setClassBaseTsData(girClass, girTypeName) {
1531
- if (!girClass?.$?.name)
1532
- return undefined;
1533
- const girModule = girClass._module ? girClass._module : this;
1534
- let className = this.transformation.transformClassName(girClass.$.name);
1535
- /**
1536
- * E.g. 'Gtk'
1537
- */
1538
- const namespace = girModule.namespace;
1539
- /**
1540
- * E.g. '3.0'
1541
- */
1542
- const version = girModule.version;
1543
- let qualifiedName;
1544
- if (!className.includes('.')) {
1545
- qualifiedName = namespace + '.' + className;
1546
- }
1547
- else {
1548
- qualifiedName = className;
1549
- const split = className.split('.');
1550
- className = split[split.length - 1];
1551
- }
1552
- girClass._tsData = {
1553
- name: className,
1554
- qualifiedName,
1555
- parents: [],
1556
- namespace,
1557
- version,
1558
- isAbstract: this.isAbstractClass(girClass),
1559
- localNames: {},
1560
- constructPropNames: {},
1561
- inheritConstructPropInterfaceNames: [],
1562
- constructPropInterfaceName: `${namespace}.${className}.ConstructorProperties`,
1563
- fields: [],
1564
- properties: [],
1565
- conflictProperties: [],
1566
- constructProps: [],
1567
- propertySignalMethods: [],
1568
- methods: [],
1569
- conflictMethods: [],
1570
- virtualMethods: [],
1571
- constructors: [],
1572
- staticFunctions: [],
1573
- signals: [],
1574
- generics: [],
1575
- inherit: {},
1576
- implements: {},
1577
- girTypeName,
1578
- tsTypeName: this.girFactory.girTypeNameToTsTypeName(girTypeName, false),
1579
- doc: this.getTsDoc(girClass),
1580
- };
1581
- girClass._tsData.doc.tags.push(...this.getTsDocGirElementTags(girClass._tsData.tsTypeName, girClass._tsData.girTypeName));
1582
- girClass._tsData.parents = this.getClassParents(girClass);
1583
- if (girClass._tsData.parents.length) {
1584
- for (const parent of girClass._tsData.parents) {
1585
- girClass._tsData.inheritConstructPropInterfaceNames.push(`${parent.qualifiedParentName}.ConstructorProperties`);
1586
- }
1587
- }
1588
- girClass._tsData.isDerivedFromGObject = this.isDerivedFromGObject(girClass);
1589
- return girClass._tsData;
1590
- }
1591
- setClassTsData(girClass, girTypeName) {
1592
- if (!girClass?.$?.name)
1593
- return undefined;
1594
- if (girClass._tsData) {
1595
- return girClass._tsData;
1596
- }
1597
- girClass._tsData = this.setClassBaseTsData(girClass, girTypeName);
1598
- if (!girClass._tsData) {
1599
- return undefined;
1600
- }
1601
- // BASE
1602
- if (girClass._tsData.isDerivedFromGObject) {
1603
- girClass._tsData.constructProps.push(...this.getClassConstructPropsTsData(girClass, girClass._tsData.constructPropNames));
1604
- }
1605
- girClass._tsData.constructors.push(...this.getClassConstructorsTsData(girClass));
1606
- girClass._tsData.staticFunctions.push(...this.getClassStaticFunctionsTsData(girClass, girClass._tsData));
1607
- girClass._tsData.fields.push(...this.getClassFieldsTsData(girClass, girClass._tsData.localNames));
1608
- girClass._tsData.properties.push(...this.getClassPropertiesTsData(girClass, girClass._tsData.localNames));
1609
- girClass._tsData.methods.push(...this.getClassMethodsTsData(girClass, girClass._tsData.localNames));
1610
- girClass._tsData.virtualMethods.push(...this.getClassVirtualMethodsTsData(girClass));
1611
- girClass._tsData.signals.push(...this.getClassSignalsTsData(girClass));
1612
- girClass._tsData.properties.push(...this.getGObjectProperties(girClass));
1613
- // Copy fields, properties, methods, virtual methods and signals from inheritance tree
1614
- this.traverseInheritanceTree(girClass, girClass._tsData.girTypeName, (extendsCls, depth) => {
1615
- if (!girClass._tsData || !extendsCls._tsData || !extendsCls._fullSymName || !extendsCls._module) {
1616
- return;
1617
- }
1618
- if (girClass._fullSymName === extendsCls._fullSymName) {
1619
- return;
1620
- }
1621
- const key = extendsCls._module.packageName + '.' + extendsCls._fullSymName;
1622
- if (girClass._tsData.inherit[key])
1623
- return;
1624
- girClass._tsData.inherit[key] = {
1625
- depth,
1626
- class: extendsCls._tsData,
1627
- };
1628
- });
1629
- // Copy properties, methods and signals from implemented interface
1630
- this.forEachInterface(girClass, girClass._tsData.girTypeName, (iface, depth) => {
1631
- if (!girClass._tsData || !iface._tsData || !iface._fullSymName || !iface._module) {
1632
- return;
1633
- }
1634
- if (girClass._fullSymName === iface._fullSymName) {
1635
- return;
1636
- }
1637
- const key = iface._module.packageName + '.' + iface._fullSymName;
1638
- if (girClass._tsData.implements[key])
1639
- return;
1640
- girClass._tsData.implements[key] = {
1641
- depth,
1642
- interface: iface._tsData,
1643
- };
1644
- });
1645
- this.inject.toClass(girClass);
1646
- girClass._tsData.propertySignalMethods.push(...this.getClassPropertySignalsMethods(girClass), ...this.getGeneralSignalsMethods(girClass._tsData));
1647
- if (this.config.fixConflicts) {
1648
- this.conflictResolver.repairClass(girClass);
1649
- }
1650
- return girClass._tsData;
1651
- }
1652
- isDerivedFromGObject(girClass) {
1653
- if (typeof girClass._tsData?.isDerivedFromGObject === 'boolean')
1654
- return girClass._tsData.isDerivedFromGObject;
1655
- let ret = false;
1656
- const onClassOrInterface = (cls) => {
1657
- if (cls._tsData?.isDerivedFromGObject === true || cls._fullSymName === 'GObject.Object') {
1658
- ret = true;
1659
- }
1660
- };
1661
- if (!girClass._tsData)
1662
- throw new Error(NO_TSDATA('isDerivedFromGObject'));
1663
- this.traverseInheritanceTree(girClass, girClass._tsData.tsTypeName, onClassOrInterface);
1664
- this.forEachInterface(girClass, girClass._tsData.tsTypeName, onClassOrInterface);
1665
- return ret;
1666
- }
1667
- getClassParent(parent) {
1668
- let parentPtr = undefined;
1669
- if (this.symTable.get(this.allDependencies, parent.qualifiedParentName)) {
1670
- parentPtr =
1671
- this.symTable.get(this.allDependencies, parent.qualifiedParentName) || undefined;
1672
- }
1673
- if (!parentPtr && parent.parentName == 'Object') {
1674
- parentPtr = this.symTable.getByHand('GObject-2.0.GObject.Object') || undefined;
1675
- }
1676
- return parentPtr;
1677
- }
1678
- traverseInheritanceTree(girClass, gitTypeName, callback, depth = 0, recursive = true) {
1679
- if (!girClass.$.name)
1680
- return;
1681
- if (!girClass._tsData)
1682
- girClass._tsData = this.setClassTsData(girClass, gitTypeName);
1683
- if (!girClass._tsData)
1684
- return;
1685
- callback(girClass, depth);
1686
- const parents = girClass._tsData.parents;
1687
- if (recursive && parents.length) {
1688
- ++depth;
1689
- if (depth >= MAX_CLASS_PARENT_DEPTH) {
1690
- this.log.error('[traverseInheritanceTree] Maximum recursion depth reached');
1691
- return;
1692
- }
1693
- for (const parent of parents) {
1694
- if (!parent.parentName || parent.type !== 'parent') {
1695
- continue;
1696
- }
1697
- if (parent.cls) {
1698
- if (parent.cls === girClass) {
1699
- this.log.warn('[traverseInheritanceTree] A class cannot inherit itself');
1700
- continue;
1701
- }
1702
- this.traverseInheritanceTree(parent.cls, parent.girTypeName, callback, depth, recursive);
1703
- }
1704
- }
1705
- }
1706
- }
1707
- forEachInterface(girIface, girTypeName, callback, recursive = true, depth = 0) {
1708
- if (!girIface.$.name)
1709
- return;
1710
- if (!girIface._tsData)
1711
- girIface._tsData = this.setClassTsData(girIface, girTypeName);
1712
- if (!girIface._tsData) {
1713
- throw new Error(NO_TSDATA('forEachInterface'));
1714
- }
1715
- const parents = girIface._tsData.parents;
1716
- if (parents.length) {
1717
- ++depth;
1718
- for (const parent of parents) {
1719
- if (!parent.parentName || parent.type === 'parent') {
1720
- continue;
1721
- }
1722
- if (parent.cls) {
1723
- callback(parent.cls, depth);
1724
- // iface's prerequisite is also an interface, or it's
1725
- // a class and we also want to recurse classes
1726
- if (recursive)
1727
- this.forEachInterface(parent.cls, parent.girTypeName, callback, recursive, depth);
1728
- }
1729
- }
1730
- }
1731
- }
1732
- /**
1733
- *
1734
- * @param girElement
1735
- * @param localNames Can be (constructor) properties, fields or methods
1736
- * @param type
1737
- */
1738
- checkOrSetLocalName(girElement, localNames, type) {
1739
- let isOverloadable = false;
1740
- if (!girElement._tsData) {
1741
- return null;
1742
- }
1743
- const name = girElement._tsData?.name;
1744
- if (!name) {
1745
- return null;
1746
- }
1747
- // Methods are overloadable by typescript
1748
- // TODO Add support for properties
1749
- if (type === 'method') {
1750
- isOverloadable = true;
1751
- }
1752
- // Only names of the same type are overloadable
1753
- if (localNames[name]?.type && localNames[name].type !== type) {
1754
- // In GIO there are some methods and properties with the same name
1755
- // E.g. on `WebKit2.WebView.isLoading` and `WebKit2.WebView.isLoading()`
1756
- // See Gjs doc https://gjs-docs.gnome.org/webkit240~4.0_api/webkit2.webview#property-is_loading
1757
- // TODO prefer functions over properties (Overwrite the properties with the functions if they have the same name)
1758
- return null;
1759
- }
1760
- // If name is found in localNames this variable was already defined
1761
- if (localNames?.[name]?.[type]?._tsData) {
1762
- // Ignore duplicates with the same type
1763
- // TODO should we use `this.functionSignaturesMatch` here?
1764
- if (type === 'method') {
1765
- const tsMethod1 = girElement._tsData;
1766
- const tsMethod2 = localNames[name][type]._tsData;
1767
- if (!tsMethod1 || !tsMethod2) {
1768
- return null;
1769
- }
1770
- // if (ConflictResolver.functionConflict(tsMethod1, tsMethod2)) {
1771
- // return null
1772
- // }
1773
- }
1774
- else {
1775
- // TODO better handling of property and field
1776
- if (isEqual(localNames[name][type]?._tsData, girElement._tsData)) {
1777
- return null;
1778
- }
1779
- }
1780
- // Ignore if current method is not overloadable
1781
- if (!isOverloadable) {
1782
- return null;
1783
- }
1784
- }
1785
- localNames[name] = localNames[name] || {};
1786
- const localName = {
1787
- ...localNames[name],
1788
- [type]: girElement,
1789
- type,
1790
- };
1791
- localNames[name] = localName;
1792
- return { ...localName, added: true };
1793
- }
1794
- isGtypeStructFor(e, rec) {
1795
- const isFor = rec.$['glib:is-gtype-struct-for'];
1796
- return isFor && isFor == e.$.name;
1797
- }
1798
- /**
1799
- * E.g GObject.ObjectClass is a abstract class and required by UPowerGlib-1.0, UDisks-2.0 and others
1800
- * @param girClass
1801
- * @returns `true` if this is this a abstract class.
1802
- */
1803
- isAbstractClass(girClass) {
1804
- return girClass.$?.['glib:is-gtype-struct-for'] ? true : false;
1805
- }
1806
- /**
1807
- *
1808
- * @param girClass
1809
- * @returns
1810
- */
1811
- getOtherStaticFunctions(girClass) {
1812
- const girFunctions = [];
1813
- if (!girClass._tsData)
1814
- return girFunctions;
1815
- if (girClass.function?.length) {
1816
- for (const girFunction of girClass.function) {
1817
- girFunction._tsData = this.getFunctionTsData(girFunction, 'static-function', girClass._tsData, {
1818
- isStatic: true,
1819
- isArrowType: false,
1820
- isGlobal: false,
1821
- isVirtual: false,
1822
- returnType: null,
1823
- generics: [],
1824
- });
1825
- if (!girFunction._tsData?.name)
1826
- continue;
1827
- if (girFunction._tsData.name.startsWith('new'))
1828
- continue;
1829
- girFunctions.push(girFunction);
1830
- }
1831
- }
1832
- return girFunctions;
1833
- }
1834
- getStaticNewFunctions(girClass, parentClass) {
1835
- const girFunctions = [];
1836
- if (girClass.function?.length) {
1837
- for (const girFunction of girClass.function) {
1838
- girFunction._tsData = this.getConstructorFunctionTsData(parentClass, girFunction);
1839
- if (!girFunction._tsData?.name.startsWith('new'))
1840
- continue;
1841
- girFunctions.push(girFunction);
1842
- }
1843
- }
1844
- return girFunctions;
1845
- }
1846
- /**
1847
- * Static methods, <constructor> and <function>
1848
- * @param girClass
1849
- * @param constructorTypeName Used to overwrite the constructor return type
1850
- * @param useReference This value should be `false` for inherited and implemented classes / interfaces.
1851
- * Otherwise other modules would overwrite the return value of the constructor methods
1852
- */
1853
- getClassStaticFunctionsTsData(girClass, parentClass) {
1854
- const girStaticFuncs = [];
1855
- girStaticFuncs.push(...this.getStaticNewFunctions(girClass, parentClass));
1856
- girStaticFuncs.push(...this.getOtherStaticFunctions(girClass));
1857
- girStaticFuncs.push(...this.getClassRecordMethods(girClass));
1858
- return girStaticFuncs;
1859
- }
1860
- setModuleTsData() {
1861
- if (this.ns.enumeration) {
1862
- for (const girEnum of this.ns.enumeration) {
1863
- if (girEnum.member) {
1864
- for (const girEnumMember of girEnum.member) {
1865
- girEnumMember._tsData = this.getEnumerationMemberTsData(girEnumMember, 'enum-member');
1866
- if (!girEnumMember._tsData)
1867
- continue;
1868
- }
1869
- }
1870
- girEnum._tsData = this.getEnumerationTsData(girEnum, 'enum');
1871
- this.fixEnumerationDuplicateIdentifier(girEnum);
1872
- if (!girEnum._tsData)
1873
- continue;
1874
- }
1875
- }
1876
- if (this.ns.bitfield)
1877
- for (const girBitfield of this.ns.bitfield) {
1878
- if (girBitfield.member)
1879
- for (const girEnumMember of girBitfield.member) {
1880
- girEnumMember._tsData = this.getEnumerationMemberTsData(girEnumMember, 'bitfield-member');
1881
- }
1882
- girBitfield._tsData = this.getEnumerationTsData(girBitfield, 'bitfield');
1883
- if (!girBitfield._tsData)
1884
- continue;
1885
- this.fixEnumerationDuplicateIdentifier(girBitfield);
1886
- }
1887
- if (this.ns.constant)
1888
- for (const girConst of this.ns.constant) {
1889
- girConst._tsData = this.getConstantTsData(girConst, null);
1890
- if (!girConst._tsData)
1891
- continue;
1892
- }
1893
- if (this.ns.function) {
1894
- for (const girFunc of this.ns.function) {
1895
- girFunc._tsData = this.getFunctionTsData(girFunc, 'function', null, {
1896
- isStatic: false,
1897
- isArrowType: false,
1898
- isGlobal: true,
1899
- isVirtual: false,
1900
- returnType: null,
1901
- generics: [],
1902
- });
1903
- if (!girFunc._tsData)
1904
- continue;
1905
- }
1906
- }
1907
- if (this.ns.callback)
1908
- for (const girCallback of this.ns.callback) {
1909
- girCallback._tsData = this.setCallbackTsData(girCallback, null);
1910
- }
1911
- if (this.ns.interface)
1912
- for (const girIface of this.ns.interface) {
1913
- girIface._tsData = this.setClassTsData(girIface, 'interface');
1914
- }
1915
- if (this.ns.class)
1916
- for (const girClass of this.ns.class) {
1917
- girClass._tsData = this.setClassTsData(girClass, 'class');
1918
- if (!girClass._tsData)
1919
- continue;
1920
- }
1921
- if (this.ns.record)
1922
- for (const girRecord of this.ns.record) {
1923
- girRecord._tsData = this.setClassTsData(girRecord, 'record');
1924
- if (!girRecord._tsData)
1925
- continue;
1926
- }
1927
- if (this.ns.union)
1928
- for (const girUnion of this.ns.union) {
1929
- girUnion._tsData = this.setClassTsData(girUnion, 'union');
1930
- if (!girUnion._tsData)
1931
- continue;
1932
- }
1933
- if (this.ns.alias) {
1934
- for (const girAlias of this.ns.alias) {
1935
- // GType is not a number in GJS
1936
- if (this.packageName !== 'GObject-2.0' || girAlias.$.name !== 'Type')
1937
- girAlias._tsData = this.getAliasTsData(girAlias, null);
1938
- if (!girAlias._tsData)
1939
- continue;
1940
- }
1941
- }
1942
- }
1943
- /**
1944
- * TODO: find better name for this method
1945
- * @param fullTypeName
1946
- * @returns
1947
- */
1948
- fullTypeLookupWithNamespace(fullTypeName) {
1949
- let resValue = '';
1950
- let namespace = '';
1951
- // Check overwrites first
1952
- if (!resValue && fullTypeName && FULL_TYPE_MAP(this.config.environment, fullTypeName)) {
1953
- resValue = FULL_TYPE_MAP(this.config.environment, fullTypeName) || '';
1954
- }
1955
- // Only use the fullTypeName as the type if it is found in the symTable
1956
- if (!resValue && this.symTable.get(this.allDependencies, fullTypeName)) {
1957
- if (fullTypeName.startsWith(this.namespace + '.')) {
1958
- resValue = removeNamespace(fullTypeName, this.namespace);
1959
- resValue = this.transformation.transformTypeName(resValue);
1960
- // TODO: check if resValue is a class, enum or interface before transformClassName
1961
- resValue = this.transformation.transformClassName(resValue);
1962
- namespace = this.namespace;
1963
- resValue = namespace + '.' + resValue;
1964
- }
1965
- else {
1966
- const resValues = fullTypeName.split('.');
1967
- resValues.map((name) => this.transformation.transformTypeName(name));
1968
- // TODO: check if resValues[resValues.length - 1] is a class, enum, interface before transformClassName
1969
- resValues[resValues.length - 1] = this.transformation.transformClassName(resValues[resValues.length - 1]);
1970
- resValue = resValues.join('.');
1971
- namespace = resValues[0];
1972
- }
1973
- }
1974
- return {
1975
- value: resValue,
1976
- namespace,
1977
- };
1978
- }
1979
- loadInheritance(inheritanceTable) {
1980
- // Class hierarchy
1981
- for (const girClass of this.ns.class ? this.ns.class : []) {
1982
- let parent = null;
1983
- if (girClass.$ && girClass.$.parent)
1984
- parent = girClass.$.parent;
1985
- if (!parent)
1986
- continue;
1987
- if (!girClass._fullSymName)
1988
- continue;
1989
- if (!parent.includes('.')) {
1990
- parent = addNamespace(parent, this.namespace);
1991
- }
1992
- const className = girClass._fullSymName;
1993
- const arr = inheritanceTable[className] || [];
1994
- arr.push(parent);
1995
- inheritanceTable[className] = arr;
1996
- }
1997
- // Class interface implementations
1998
- for (const girClass of this.ns.class ? this.ns.class : []) {
1999
- if (!girClass._fullSymName)
2000
- continue;
2001
- const names = [];
2002
- if (girClass.implements) {
2003
- for (const girImplements of girClass.implements) {
2004
- if (girImplements.$.name) {
2005
- let name = girImplements.$.name;
2006
- if (!name.includes('.')) {
2007
- name = girClass._fullSymName.substring(0, girClass._fullSymName.indexOf('.') + 1) + name;
2008
- }
2009
- names.push(name);
2010
- }
2011
- }
2012
- }
2013
- if (names.length > 0) {
2014
- const className = girClass._fullSymName;
2015
- const arr = inheritanceTable[className] || [];
2016
- inheritanceTable[className] = arr.concat(names);
2017
- }
2018
- }
2019
- }
2020
- loadTypes() {
2021
- if (this.ns.bitfield)
2022
- this.annotateAndRegisterGirElement(this.ns.bitfield);
2023
- if (this.ns.callback)
2024
- this.annotateAndRegisterGirElement(this.ns.callback);
2025
- if (this.ns.class)
2026
- this.annotateAndRegisterGirElement(this.ns.class);
2027
- if (this.ns.constant)
2028
- this.annotateAndRegisterGirElement(this.ns.constant);
2029
- if (this.ns.enumeration)
2030
- this.annotateAndRegisterGirElement(this.ns.enumeration);
2031
- if (this.ns.function)
2032
- this.annotateAndRegisterGirElement(this.ns.function);
2033
- if (this.ns.interface)
2034
- this.annotateAndRegisterGirElement(this.ns.interface);
2035
- if (this.ns.record)
2036
- this.annotateAndRegisterGirElement(this.ns.record);
2037
- if (this.ns.union)
2038
- this.annotateAndRegisterGirElement(this.ns.union);
2039
- if (this.ns.alias)
2040
- this.annotateAndRegisterGirElement(this.ns.alias);
2041
- if (this.ns.callback)
2042
- for (const girCallback of this.ns.callback)
2043
- this.annotateFunctionArguments(girCallback);
2044
- for (const girClass of this.ns.class || []) {
2045
- this.annotateClass(girClass, 'class');
2046
- }
2047
- for (const girClass of this.ns.record || []) {
2048
- this.annotateClass(girClass, 'record');
2049
- }
2050
- for (const girClass of this.ns.interface || []) {
2051
- this.annotateClass(girClass, 'interface');
2052
- }
2053
- if (this.ns.function)
2054
- this.annotateFunctions(this.ns.function);
2055
- if (this.ns.callback)
2056
- this.annotateFunctions(this.ns.callback);
2057
- if (this.ns.constant)
2058
- this.annotateVariables(this.ns.constant);
2059
- }
2060
- /**
2061
- * Before processing the typescript data, each module should be initialized first.
2062
- * This is done in the `GenerationHandler`.
2063
- */
2064
- init(inheritanceTable) {
2065
- this.loadTypes();
2066
- this.loadInheritance(inheritanceTable);
2067
- }
2068
- /**
2069
- * Start processing the typescript data
2070
- */
2071
- start() {
2072
- this.setModuleTsData();
2073
- }
2074
- }
2075
- //# sourceMappingURL=gir-module.js.map