@ts-for-gir/cli 3.0.0-beta.9 → 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 (760) hide show
  1. package/README.md +160 -35
  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 -37
  6. package/lib/commands/generate.js +8 -24
  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 +21 -5
  12. package/lib/config.js +164 -86
  13. package/lib/config.js.map +1 -1
  14. package/lib/generation-handler.d.ts +3 -4
  15. package/lib/generation-handler.js +7 -11
  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 +35 -24
  21. package/lib/module-loader.js +3 -8
  22. package/lib/module-loader.js.map +1 -1
  23. package/lib/utils.d.ts +0 -262
  24. package/lib/utils.js +8 -371
  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 -24
  29. package/src/commands/list.ts +8 -10
  30. package/src/config.ts +178 -92
  31. package/src/generation-handler.ts +11 -12
  32. package/src/index.ts +0 -12
  33. package/src/module-loader.ts +39 -31
  34. package/src/utils.ts +8 -401
  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/dependency-manager.d.ts +0 -34
  42. package/lib/dependency-manager.js +0 -78
  43. package/lib/dependency-manager.js.map +0 -1
  44. package/lib/generator.d.ts +0 -5
  45. package/lib/generator.js +0 -2
  46. package/lib/generator.js.map +0 -1
  47. package/lib/gir-factory.d.ts +0 -51
  48. package/lib/gir-factory.js +0 -361
  49. package/lib/gir-factory.js.map +0 -1
  50. package/lib/gir-module.d.ts +0 -257
  51. package/lib/gir-module.js +0 -2086
  52. package/lib/gir-module.js.map +0 -1
  53. package/lib/html-doc-generator.d.ts +0 -13
  54. package/lib/html-doc-generator.js +0 -18
  55. package/lib/html-doc-generator.js.map +0 -1
  56. package/lib/injection/callbacks/gjs/Gio-2.0.d.ts +0 -2
  57. package/lib/injection/callbacks/gjs/Gio-2.0.js +0 -36
  58. package/lib/injection/callbacks/gjs/Gio-2.0.js.map +0 -1
  59. package/lib/injection/callbacks/gjs/index.d.ts +0 -2
  60. package/lib/injection/callbacks/gjs/index.js +0 -3
  61. package/lib/injection/callbacks/gjs/index.js.map +0 -1
  62. package/lib/injection/callbacks/index.d.ts +0 -4
  63. package/lib/injection/callbacks/index.js +0 -4
  64. package/lib/injection/callbacks/index.js.map +0 -1
  65. package/lib/injection/callbacks/node-gtk/index.d.ts +0 -2
  66. package/lib/injection/callbacks/node-gtk/index.js +0 -2
  67. package/lib/injection/callbacks/node-gtk/index.js.map +0 -1
  68. package/lib/injection/classes/GLib-2-0.d.ts +0 -2
  69. package/lib/injection/classes/GLib-2-0.js +0 -35
  70. package/lib/injection/classes/GLib-2-0.js.map +0 -1
  71. package/lib/injection/classes/gjs/GLib-2.0.d.ts +0 -2
  72. package/lib/injection/classes/gjs/GLib-2.0.js +0 -200
  73. package/lib/injection/classes/gjs/GLib-2.0.js.map +0 -1
  74. package/lib/injection/classes/gjs/GObject-2.0.d.ts +0 -2
  75. package/lib/injection/classes/gjs/GObject-2.0.js +0 -634
  76. package/lib/injection/classes/gjs/GObject-2.0.js.map +0 -1
  77. package/lib/injection/classes/gjs/Gio-2.0.d.ts +0 -5
  78. package/lib/injection/classes/gjs/Gio-2.0.js +0 -218
  79. package/lib/injection/classes/gjs/Gio-2.0.js.map +0 -1
  80. package/lib/injection/classes/gjs/index.d.ts +0 -2
  81. package/lib/injection/classes/gjs/index.js +0 -5
  82. package/lib/injection/classes/gjs/index.js.map +0 -1
  83. package/lib/injection/classes/index.d.ts +0 -4
  84. package/lib/injection/classes/index.js +0 -5
  85. package/lib/injection/classes/index.js.map +0 -1
  86. package/lib/injection/classes/node-gtk/GLib-2.0.d.ts +0 -2
  87. package/lib/injection/classes/node-gtk/GLib-2.0.js +0 -19
  88. package/lib/injection/classes/node-gtk/GLib-2.0.js.map +0 -1
  89. package/lib/injection/classes/node-gtk/GObject-2.0.d.ts +0 -2
  90. package/lib/injection/classes/node-gtk/GObject-2.0.js +0 -66
  91. package/lib/injection/classes/node-gtk/GObject-2.0.js.map +0 -1
  92. package/lib/injection/classes/node-gtk/Gdk-4.0.d.ts +0 -2
  93. package/lib/injection/classes/node-gtk/Gdk-4.0.js +0 -32
  94. package/lib/injection/classes/node-gtk/Gdk-4.0.js.map +0 -1
  95. package/lib/injection/classes/node-gtk/Gio-2.0.d.ts +0 -2
  96. package/lib/injection/classes/node-gtk/Gio-2.0.js +0 -14
  97. package/lib/injection/classes/node-gtk/Gio-2.0.js.map +0 -1
  98. package/lib/injection/classes/node-gtk/Graphene-1.0.d.ts +0 -2
  99. package/lib/injection/classes/node-gtk/Graphene-1.0.js +0 -133
  100. package/lib/injection/classes/node-gtk/Graphene-1.0.js.map +0 -1
  101. package/lib/injection/classes/node-gtk/Gtk-3.0.d.ts +0 -2
  102. package/lib/injection/classes/node-gtk/Gtk-3.0.js +0 -31
  103. package/lib/injection/classes/node-gtk/Gtk-3.0.js.map +0 -1
  104. package/lib/injection/classes/node-gtk/Gtk-4.0.d.ts +0 -2
  105. package/lib/injection/classes/node-gtk/Gtk-4.0.js +0 -52
  106. package/lib/injection/classes/node-gtk/Gtk-4.0.js.map +0 -1
  107. package/lib/injection/classes/node-gtk/Pango-1.0.d.ts +0 -2
  108. package/lib/injection/classes/node-gtk/Pango-1.0.js +0 -31
  109. package/lib/injection/classes/node-gtk/Pango-1.0.js.map +0 -1
  110. package/lib/injection/classes/node-gtk/index.d.ts +0 -2
  111. package/lib/injection/classes/node-gtk/index.js +0 -19
  112. package/lib/injection/classes/node-gtk/index.js.map +0 -1
  113. package/lib/injection/index.d.ts +0 -3
  114. package/lib/injection/index.js +0 -4
  115. package/lib/injection/index.js.map +0 -1
  116. package/lib/injection/injector.d.ts +0 -17
  117. package/lib/injection/injector.js +0 -139
  118. package/lib/injection/injector.js.map +0 -1
  119. package/lib/logger.d.ts +0 -36
  120. package/lib/logger.js +0 -137
  121. package/lib/logger.js.map +0 -1
  122. package/lib/messages.d.ts +0 -31
  123. package/lib/messages.js +0 -46
  124. package/lib/messages.js.map +0 -1
  125. package/lib/symtable.d.ts +0 -24
  126. package/lib/symtable.js +0 -63
  127. package/lib/symtable.js.map +0 -1
  128. package/lib/template-processor.d.ts +0 -74
  129. package/lib/template-processor.js +0 -165
  130. package/lib/template-processor.js.map +0 -1
  131. package/lib/transformation.d.ts +0 -156
  132. package/lib/transformation.js +0 -523
  133. package/lib/transformation.js.map +0 -1
  134. package/lib/type-definition-generator.d.ts +0 -116
  135. package/lib/type-definition-generator.js +0 -991
  136. package/lib/type-definition-generator.js.map +0 -1
  137. package/lib/types/answer-version.d.ts +0 -4
  138. package/lib/types/answer-version.js +0 -2
  139. package/lib/types/answer-version.js.map +0 -1
  140. package/lib/types/build-type.d.ts +0 -1
  141. package/lib/types/build-type.js +0 -2
  142. package/lib/types/build-type.js.map +0 -1
  143. package/lib/types/class-parent.d.ts +0 -13
  144. package/lib/types/class-parent.js +0 -2
  145. package/lib/types/class-parent.js.map +0 -1
  146. package/lib/types/config-flags.d.ts +0 -4
  147. package/lib/types/config-flags.js +0 -2
  148. package/lib/types/config-flags.js.map +0 -1
  149. package/lib/types/conflict-child-element.d.ts +0 -10
  150. package/lib/types/conflict-child-element.js +0 -2
  151. package/lib/types/conflict-child-element.js.map +0 -1
  152. package/lib/types/conflict-grouped-element.d.ts +0 -6
  153. package/lib/types/conflict-grouped-element.js +0 -2
  154. package/lib/types/conflict-grouped-element.js.map +0 -1
  155. package/lib/types/conflict-grouped-elements.d.ts +0 -4
  156. package/lib/types/conflict-grouped-elements.js +0 -2
  157. package/lib/types/conflict-grouped-elements.js.map +0 -1
  158. package/lib/types/construct-name.d.ts +0 -1
  159. package/lib/types/construct-name.js +0 -2
  160. package/lib/types/construct-name.js.map +0 -1
  161. package/lib/types/dependency-map.d.ts +0 -4
  162. package/lib/types/dependency-map.js +0 -2
  163. package/lib/types/dependency-map.js.map +0 -1
  164. package/lib/types/dependency.d.ts +0 -15
  165. package/lib/types/dependency.js +0 -2
  166. package/lib/types/dependency.js.map +0 -1
  167. package/lib/types/environment.d.ts +0 -1
  168. package/lib/types/environment.js +0 -2
  169. package/lib/types/environment.js.map +0 -1
  170. package/lib/types/file-info.d.ts +0 -14
  171. package/lib/types/file-info.js +0 -2
  172. package/lib/types/file-info.js.map +0 -1
  173. package/lib/types/generate-config.d.ts +0 -32
  174. package/lib/types/generate-config.js +0 -2
  175. package/lib/types/generate-config.js.map +0 -1
  176. package/lib/types/generator-type.d.ts +0 -4
  177. package/lib/types/generator-type.js +0 -6
  178. package/lib/types/generator-type.js.map +0 -1
  179. package/lib/types/gir-alias-element.d.ts +0 -13
  180. package/lib/types/gir-alias-element.js +0 -2
  181. package/lib/types/gir-alias-element.js.map +0 -1
  182. package/lib/types/gir-annotation.d.ts +0 -9
  183. package/lib/types/gir-annotation.js +0 -2
  184. package/lib/types/gir-annotation.js.map +0 -1
  185. package/lib/types/gir-any-element.d.ts +0 -2
  186. package/lib/types/gir-any-element.js +0 -2
  187. package/lib/types/gir-any-element.js.map +0 -1
  188. package/lib/types/gir-any-type.d.ts +0 -5
  189. package/lib/types/gir-any-type.js +0 -2
  190. package/lib/types/gir-any-type.js.map +0 -1
  191. package/lib/types/gir-array-type.d.ts +0 -20
  192. package/lib/types/gir-array-type.js +0 -3
  193. package/lib/types/gir-array-type.js.map +0 -1
  194. package/lib/types/gir-bitfield-element.d.ts +0 -17
  195. package/lib/types/gir-bitfield-element.js +0 -2
  196. package/lib/types/gir-bitfield-element.js.map +0 -1
  197. package/lib/types/gir-boolean.d.ts +0 -1
  198. package/lib/types/gir-boolean.js +0 -2
  199. package/lib/types/gir-boolean.js.map +0 -1
  200. package/lib/types/gir-boxed-element.d.ts +0 -15
  201. package/lib/types/gir-boxed-element.js +0 -2
  202. package/lib/types/gir-boxed-element.js.map +0 -1
  203. package/lib/types/gir-c-include.d.ts +0 -7
  204. package/lib/types/gir-c-include.js +0 -2
  205. package/lib/types/gir-c-include.js.map +0 -1
  206. package/lib/types/gir-callable-attrs.d.ts +0 -15
  207. package/lib/types/gir-callable-attrs.js +0 -3
  208. package/lib/types/gir-callable-attrs.js.map +0 -1
  209. package/lib/types/gir-callable-param-element.d.ts +0 -30
  210. package/lib/types/gir-callable-param-element.js +0 -2
  211. package/lib/types/gir-callable-param-element.js.map +0 -1
  212. package/lib/types/gir-callable-param.d.ts +0 -7
  213. package/lib/types/gir-callable-param.js +0 -2
  214. package/lib/types/gir-callable-param.js.map +0 -1
  215. package/lib/types/gir-callable-return.d.ts +0 -22
  216. package/lib/types/gir-callable-return.js +0 -2
  217. package/lib/types/gir-callable-return.js.map +0 -1
  218. package/lib/types/gir-callback-element.d.ts +0 -15
  219. package/lib/types/gir-callback-element.js +0 -2
  220. package/lib/types/gir-callback-element.js.map +0 -1
  221. package/lib/types/gir-class-element.d.ts +0 -48
  222. package/lib/types/gir-class-element.js +0 -2
  223. package/lib/types/gir-class-element.js.map +0 -1
  224. package/lib/types/gir-constant-element.d.ts +0 -15
  225. package/lib/types/gir-constant-element.js +0 -2
  226. package/lib/types/gir-constant-element.js.map +0 -1
  227. package/lib/types/gir-constructor-element.d.ts +0 -8
  228. package/lib/types/gir-constructor-element.js +0 -2
  229. package/lib/types/gir-constructor-element.js.map +0 -1
  230. package/lib/types/gir-direction.d.ts +0 -5
  231. package/lib/types/gir-direction.js +0 -7
  232. package/lib/types/gir-direction.js.map +0 -1
  233. package/lib/types/gir-doc-element.d.ts +0 -68
  234. package/lib/types/gir-doc-element.js +0 -2
  235. package/lib/types/gir-doc-element.js.map +0 -1
  236. package/lib/types/gir-enum-element.d.ts +0 -19
  237. package/lib/types/gir-enum-element.js +0 -2
  238. package/lib/types/gir-enum-element.js.map +0 -1
  239. package/lib/types/gir-field-element.d.ts +0 -18
  240. package/lib/types/gir-field-element.js +0 -2
  241. package/lib/types/gir-field-element.js.map +0 -1
  242. package/lib/types/gir-function-element.d.ts +0 -8
  243. package/lib/types/gir-function-element.js +0 -2
  244. package/lib/types/gir-function-element.js.map +0 -1
  245. package/lib/types/gir-implements.d.ts +0 -8
  246. package/lib/types/gir-implements.js +0 -2
  247. package/lib/types/gir-implements.js.map +0 -1
  248. package/lib/types/gir-include.d.ts +0 -9
  249. package/lib/types/gir-include.js +0 -2
  250. package/lib/types/gir-include.js.map +0 -1
  251. package/lib/types/gir-info-attrs.d.ts +0 -13
  252. package/lib/types/gir-info-attrs.js +0 -2
  253. package/lib/types/gir-info-attrs.js.map +0 -1
  254. package/lib/types/gir-info-elements.d.ts +0 -5
  255. package/lib/types/gir-info-elements.js +0 -2
  256. package/lib/types/gir-info-elements.js.map +0 -1
  257. package/lib/types/gir-instance-parameter.d.ts +0 -21
  258. package/lib/types/gir-instance-parameter.js +0 -2
  259. package/lib/types/gir-instance-parameter.js.map +0 -1
  260. package/lib/types/gir-interface-element.d.ts +0 -31
  261. package/lib/types/gir-interface-element.js +0 -2
  262. package/lib/types/gir-interface-element.js.map +0 -1
  263. package/lib/types/gir-member-element.d.ts +0 -17
  264. package/lib/types/gir-member-element.js +0 -2
  265. package/lib/types/gir-member-element.js.map +0 -1
  266. package/lib/types/gir-method-element.d.ts +0 -13
  267. package/lib/types/gir-method-element.js +0 -2
  268. package/lib/types/gir-method-element.js.map +0 -1
  269. package/lib/types/gir-module-resolved-by.d.ts +0 -10
  270. package/lib/types/gir-module-resolved-by.js +0 -2
  271. package/lib/types/gir-module-resolved-by.js.map +0 -1
  272. package/lib/types/gir-modules-grouped-map.d.ts +0 -4
  273. package/lib/types/gir-modules-grouped-map.js +0 -2
  274. package/lib/types/gir-modules-grouped-map.js.map +0 -1
  275. package/lib/types/gir-modules-grouped.d.ts +0 -12
  276. package/lib/types/gir-modules-grouped.js +0 -2
  277. package/lib/types/gir-modules-grouped.js.map +0 -1
  278. package/lib/types/gir-namespace.d.ts +0 -30
  279. package/lib/types/gir-namespace.js +0 -2
  280. package/lib/types/gir-namespace.js.map +0 -1
  281. package/lib/types/gir-package.d.ts +0 -7
  282. package/lib/types/gir-package.js +0 -2
  283. package/lib/types/gir-package.js.map +0 -1
  284. package/lib/types/gir-prerequisite.d.ts +0 -5
  285. package/lib/types/gir-prerequisite.js +0 -2
  286. package/lib/types/gir-prerequisite.js.map +0 -1
  287. package/lib/types/gir-property-element.d.ts +0 -21
  288. package/lib/types/gir-property-element.js +0 -2
  289. package/lib/types/gir-property-element.js.map +0 -1
  290. package/lib/types/gir-record-element.d.ts +0 -30
  291. package/lib/types/gir-record-element.js +0 -2
  292. package/lib/types/gir-record-element.js.map +0 -1
  293. package/lib/types/gir-repository.d.ts +0 -16
  294. package/lib/types/gir-repository.js +0 -2
  295. package/lib/types/gir-repository.js.map +0 -1
  296. package/lib/types/gir-signal.d.ts +0 -25
  297. package/lib/types/gir-signal.js +0 -2
  298. package/lib/types/gir-signal.js.map +0 -1
  299. package/lib/types/gir-transfer-ownership-type.d.ts +0 -5
  300. package/lib/types/gir-transfer-ownership-type.js +0 -7
  301. package/lib/types/gir-transfer-ownership-type.js.map +0 -1
  302. package/lib/types/gir-transfer-ownership.d.ts +0 -5
  303. package/lib/types/gir-transfer-ownership.js +0 -2
  304. package/lib/types/gir-transfer-ownership.js.map +0 -1
  305. package/lib/types/gir-type.d.ts +0 -14
  306. package/lib/types/gir-type.js +0 -2
  307. package/lib/types/gir-type.js.map +0 -1
  308. package/lib/types/gir-union-element.d.ts +0 -22
  309. package/lib/types/gir-union-element.js +0 -2
  310. package/lib/types/gir-union-element.js.map +0 -1
  311. package/lib/types/gir-unparsed-number.d.ts +0 -2
  312. package/lib/types/gir-unparsed-number.js +0 -2
  313. package/lib/types/gir-unparsed-number.js.map +0 -1
  314. package/lib/types/gir-var-args.d.ts +0 -5
  315. package/lib/types/gir-var-args.js +0 -2
  316. package/lib/types/gir-var-args.js.map +0 -1
  317. package/lib/types/gir-virtual-method.d.ts +0 -10
  318. package/lib/types/gir-virtual-method.js +0 -2
  319. package/lib/types/gir-virtual-method.js.map +0 -1
  320. package/lib/types/index.d.ts +0 -119
  321. package/lib/types/index.js +0 -120
  322. package/lib/types/index.js.map +0 -1
  323. package/lib/types/inheritance-table.d.ts +0 -3
  324. package/lib/types/inheritance-table.js +0 -2
  325. package/lib/types/inheritance-table.js.map +0 -1
  326. package/lib/types/injection-callback.d.ts +0 -16
  327. package/lib/types/injection-callback.js +0 -2
  328. package/lib/types/injection-callback.js.map +0 -1
  329. package/lib/types/injection-class.d.ts +0 -25
  330. package/lib/types/injection-class.js +0 -2
  331. package/lib/types/injection-class.js.map +0 -1
  332. package/lib/types/injection-function.d.ts +0 -7
  333. package/lib/types/injection-function.js +0 -2
  334. package/lib/types/injection-function.js.map +0 -1
  335. package/lib/types/injection-generic-parameter.d.ts +0 -2
  336. package/lib/types/injection-generic-parameter.js +0 -2
  337. package/lib/types/injection-generic-parameter.js.map +0 -1
  338. package/lib/types/injection-instance-parameter.d.ts +0 -2
  339. package/lib/types/injection-instance-parameter.js +0 -2
  340. package/lib/types/injection-instance-parameter.js.map +0 -1
  341. package/lib/types/injection-parameter.d.ts +0 -8
  342. package/lib/types/injection-parameter.js +0 -2
  343. package/lib/types/injection-parameter.js.map +0 -1
  344. package/lib/types/injection-property.d.ts +0 -4
  345. package/lib/types/injection-property.js +0 -2
  346. package/lib/types/injection-property.js.map +0 -1
  347. package/lib/types/injection-type.d.ts +0 -2
  348. package/lib/types/injection-type.js +0 -2
  349. package/lib/types/injection-type.js.map +0 -1
  350. package/lib/types/injection.d.ts +0 -5
  351. package/lib/types/injection.js +0 -2
  352. package/lib/types/injection.js.map +0 -1
  353. package/lib/types/local-name-check.d.ts +0 -4
  354. package/lib/types/local-name-check.js +0 -2
  355. package/lib/types/local-name-check.js.map +0 -1
  356. package/lib/types/local-name-type.d.ts +0 -1
  357. package/lib/types/local-name-type.js +0 -2
  358. package/lib/types/local-name-type.js.map +0 -1
  359. package/lib/types/local-name.d.ts +0 -7
  360. package/lib/types/local-name.js +0 -2
  361. package/lib/types/local-name.js.map +0 -1
  362. package/lib/types/local-names.d.ts +0 -4
  363. package/lib/types/local-names.js +0 -2
  364. package/lib/types/local-names.js.map +0 -1
  365. package/lib/types/module-type.d.ts +0 -1
  366. package/lib/types/module-type.js +0 -2
  367. package/lib/types/module-type.js.map +0 -1
  368. package/lib/types/parsed-gir.d.ts +0 -4
  369. package/lib/types/parsed-gir.js +0 -2
  370. package/lib/types/parsed-gir.js.map +0 -1
  371. package/lib/types/part-of-class.d.ts +0 -7
  372. package/lib/types/part-of-class.js +0 -2
  373. package/lib/types/part-of-class.js.map +0 -1
  374. package/lib/types/part-of-module.d.ts +0 -6
  375. package/lib/types/part-of-module.js +0 -2
  376. package/lib/types/part-of-module.js.map +0 -1
  377. package/lib/types/promisify-func.d.ts +0 -5
  378. package/lib/types/promisify-func.js +0 -2
  379. package/lib/types/promisify-func.js.map +0 -1
  380. package/lib/types/resolve-type.d.ts +0 -4
  381. package/lib/types/resolve-type.js +0 -6
  382. package/lib/types/resolve-type.js.map +0 -1
  383. package/lib/types/sym-table-items.d.ts +0 -4
  384. package/lib/types/sym-table-items.js +0 -2
  385. package/lib/types/sym-table-items.js.map +0 -1
  386. package/lib/types/transformation-case.d.ts +0 -1
  387. package/lib/types/transformation-case.js +0 -2
  388. package/lib/types/transformation-case.js.map +0 -1
  389. package/lib/types/transformations.d.ts +0 -11
  390. package/lib/types/transformations.js +0 -2
  391. package/lib/types/transformations.js.map +0 -1
  392. package/lib/types/ts-alias.d.ts +0 -10
  393. package/lib/types/ts-alias.js +0 -2
  394. package/lib/types/ts-alias.js.map +0 -1
  395. package/lib/types/ts-callback-interface.d.ts +0 -10
  396. package/lib/types/ts-callback-interface.js +0 -2
  397. package/lib/types/ts-callback-interface.js.map +0 -1
  398. package/lib/types/ts-callback.d.ts +0 -17
  399. package/lib/types/ts-callback.js +0 -2
  400. package/lib/types/ts-callback.js.map +0 -1
  401. package/lib/types/ts-class.d.ts +0 -85
  402. package/lib/types/ts-class.js +0 -2
  403. package/lib/types/ts-class.js.map +0 -1
  404. package/lib/types/ts-doc-tag.d.ts +0 -21
  405. package/lib/types/ts-doc-tag.js +0 -2
  406. package/lib/types/ts-doc-tag.js.map +0 -1
  407. package/lib/types/ts-doc.d.ts +0 -20
  408. package/lib/types/ts-doc.js +0 -2
  409. package/lib/types/ts-doc.js.map +0 -1
  410. package/lib/types/ts-enum.d.ts +0 -12
  411. package/lib/types/ts-enum.js +0 -2
  412. package/lib/types/ts-enum.js.map +0 -1
  413. package/lib/types/ts-function.d.ts +0 -44
  414. package/lib/types/ts-function.js +0 -2
  415. package/lib/types/ts-function.js.map +0 -1
  416. package/lib/types/ts-generic-parameter.d.ts +0 -8
  417. package/lib/types/ts-generic-parameter.js +0 -2
  418. package/lib/types/ts-generic-parameter.js.map +0 -1
  419. package/lib/types/ts-instance-parameter.d.ts +0 -4
  420. package/lib/types/ts-instance-parameter.js +0 -2
  421. package/lib/types/ts-instance-parameter.js.map +0 -1
  422. package/lib/types/ts-member.d.ts +0 -10
  423. package/lib/types/ts-member.js +0 -2
  424. package/lib/types/ts-member.js.map +0 -1
  425. package/lib/types/ts-method.d.ts +0 -5
  426. package/lib/types/ts-method.js +0 -2
  427. package/lib/types/ts-method.js.map +0 -1
  428. package/lib/types/ts-parameter.d.ts +0 -15
  429. package/lib/types/ts-parameter.js +0 -2
  430. package/lib/types/ts-parameter.js.map +0 -1
  431. package/lib/types/ts-property.d.ts +0 -17
  432. package/lib/types/ts-property.js +0 -2
  433. package/lib/types/ts-property.js.map +0 -1
  434. package/lib/types/ts-signal.d.ts +0 -17
  435. package/lib/types/ts-signal.js +0 -2
  436. package/lib/types/ts-signal.js.map +0 -1
  437. package/lib/types/ts-type-name.d.ts +0 -1
  438. package/lib/types/ts-type-name.js +0 -2
  439. package/lib/types/ts-type-name.js.map +0 -1
  440. package/lib/types/ts-type-separator.d.ts +0 -1
  441. package/lib/types/ts-type-separator.js +0 -2
  442. package/lib/types/ts-type-separator.js.map +0 -1
  443. package/lib/types/ts-type.d.ts +0 -22
  444. package/lib/types/ts-type.js +0 -2
  445. package/lib/types/ts-type.js.map +0 -1
  446. package/lib/types/ts-var.d.ts +0 -17
  447. package/lib/types/ts-var.js +0 -2
  448. package/lib/types/ts-var.js.map +0 -1
  449. package/lib/types/type-gir-alias.d.ts +0 -2
  450. package/lib/types/type-gir-alias.js +0 -2
  451. package/lib/types/type-gir-alias.js.map +0 -1
  452. package/lib/types/type-gir-class.d.ts +0 -2
  453. package/lib/types/type-gir-class.js +0 -2
  454. package/lib/types/type-gir-class.js.map +0 -1
  455. package/lib/types/type-gir-element.d.ts +0 -3
  456. package/lib/types/type-gir-element.js +0 -2
  457. package/lib/types/type-gir-element.js.map +0 -1
  458. package/lib/types/type-gir-enumeration-member.d.ts +0 -2
  459. package/lib/types/type-gir-enumeration-member.js +0 -2
  460. package/lib/types/type-gir-enumeration-member.js.map +0 -1
  461. package/lib/types/type-gir-enumeration.d.ts +0 -2
  462. package/lib/types/type-gir-enumeration.js +0 -2
  463. package/lib/types/type-gir-enumeration.js.map +0 -1
  464. package/lib/types/type-gir-function.d.ts +0 -1
  465. package/lib/types/type-gir-function.js +0 -2
  466. package/lib/types/type-gir-function.js.map +0 -1
  467. package/lib/types/type-gir-interface.d.ts +0 -2
  468. package/lib/types/type-gir-interface.js +0 -2
  469. package/lib/types/type-gir-interface.js.map +0 -1
  470. package/lib/types/type-gir-method.d.ts +0 -2
  471. package/lib/types/type-gir-method.js +0 -2
  472. package/lib/types/type-gir-method.js.map +0 -1
  473. package/lib/types/type-gir-parameter.d.ts +0 -1
  474. package/lib/types/type-gir-parameter.js +0 -2
  475. package/lib/types/type-gir-parameter.js.map +0 -1
  476. package/lib/types/type-gir-property.d.ts +0 -2
  477. package/lib/types/type-gir-property.js +0 -2
  478. package/lib/types/type-gir-property.js.map +0 -1
  479. package/lib/types/type-gir-variable.d.ts +0 -1
  480. package/lib/types/type-gir-variable.js +0 -2
  481. package/lib/types/type-gir-variable.js.map +0 -1
  482. package/lib/types/type-ts-element.d.ts +0 -3
  483. package/lib/types/type-ts-element.js +0 -2
  484. package/lib/types/type-ts-element.js.map +0 -1
  485. package/lib/types/type-ts-enumeration-member.d.ts +0 -2
  486. package/lib/types/type-ts-enumeration-member.js +0 -2
  487. package/lib/types/type-ts-enumeration-member.js.map +0 -1
  488. package/lib/types/type-ts-function.d.ts +0 -1
  489. package/lib/types/type-ts-function.js +0 -2
  490. package/lib/types/type-ts-function.js.map +0 -1
  491. package/lib/types/type-ts-property.d.ts +0 -1
  492. package/lib/types/type-ts-property.js +0 -2
  493. package/lib/types/type-ts-property.js.map +0 -1
  494. package/lib/types/user-config-load-result.d.ts +0 -6
  495. package/lib/types/user-config-load-result.js +0 -2
  496. package/lib/types/user-config-load-result.js.map +0 -1
  497. package/lib/types/user-config.d.ts +0 -40
  498. package/lib/types/user-config.js +0 -2
  499. package/lib/types/user-config.js.map +0 -1
  500. package/src/conflict-resolver.ts +0 -1358
  501. package/src/constants.ts +0 -29
  502. package/src/dependency-manager.ts +0 -91
  503. package/src/generator.ts +0 -10
  504. package/src/gir-factory.ts +0 -499
  505. package/src/gir-module.ts +0 -2827
  506. package/src/html-doc-generator.ts +0 -23
  507. package/src/injection/callbacks/gjs/Gio-2.0.ts +0 -37
  508. package/src/injection/callbacks/gjs/index.ts +0 -5
  509. package/src/injection/callbacks/index.ts +0 -6
  510. package/src/injection/callbacks/node-gtk/index.ts +0 -3
  511. package/src/injection/classes/GLib-2-0.ts +0 -36
  512. package/src/injection/classes/gjs/GLib-2.0.ts +0 -201
  513. package/src/injection/classes/gjs/GObject-2.0.ts +0 -635
  514. package/src/injection/classes/gjs/Gio-2.0.ts +0 -219
  515. package/src/injection/classes/gjs/index.ts +0 -7
  516. package/src/injection/classes/index.ts +0 -7
  517. package/src/injection/classes/node-gtk/GLib-2.0.ts +0 -20
  518. package/src/injection/classes/node-gtk/GObject-2.0.ts +0 -67
  519. package/src/injection/classes/node-gtk/Gdk-4.0.ts +0 -33
  520. package/src/injection/classes/node-gtk/Gio-2.0.ts +0 -15
  521. package/src/injection/classes/node-gtk/Graphene-1.0.ts +0 -134
  522. package/src/injection/classes/node-gtk/Gtk-3.0.ts +0 -32
  523. package/src/injection/classes/node-gtk/Gtk-4.0.ts +0 -53
  524. package/src/injection/classes/node-gtk/Pango-1.0.ts +0 -32
  525. package/src/injection/classes/node-gtk/index.ts +0 -21
  526. package/src/injection/index.ts +0 -3
  527. package/src/injection/injector.ts +0 -184
  528. package/src/logger.ts +0 -134
  529. package/src/messages.ts +0 -69
  530. package/src/symtable.ts +0 -72
  531. package/src/template-processor.ts +0 -199
  532. package/src/transformation.ts +0 -583
  533. package/src/type-definition-generator.ts +0 -1460
  534. package/src/types/answer-version.ts +0 -4
  535. package/src/types/build-type.ts +0 -1
  536. package/src/types/class-parent.ts +0 -14
  537. package/src/types/config-flags.ts +0 -5
  538. package/src/types/conflict-child-element.ts +0 -11
  539. package/src/types/conflict-grouped-element.ts +0 -7
  540. package/src/types/conflict-grouped-elements.ts +0 -5
  541. package/src/types/construct-name.ts +0 -11
  542. package/src/types/dependency-map.ts +0 -4
  543. package/src/types/dependency.ts +0 -16
  544. package/src/types/environment.ts +0 -1
  545. package/src/types/file-info.ts +0 -14
  546. package/src/types/generate-config.ts +0 -33
  547. package/src/types/generator-type.ts +0 -4
  548. package/src/types/gir-alias-element.ts +0 -15
  549. package/src/types/gir-annotation.ts +0 -10
  550. package/src/types/gir-any-element.ts +0 -35
  551. package/src/types/gir-any-type.ts +0 -7
  552. package/src/types/gir-array-type.ts +0 -23
  553. package/src/types/gir-bitfield-element.ts +0 -20
  554. package/src/types/gir-boolean.ts +0 -1
  555. package/src/types/gir-boxed-element.ts +0 -19
  556. package/src/types/gir-c-include.ts +0 -7
  557. package/src/types/gir-callable-attrs.ts +0 -19
  558. package/src/types/gir-callable-param-element.ts +0 -45
  559. package/src/types/gir-callable-param.ts +0 -9
  560. package/src/types/gir-callable-return.ts +0 -25
  561. package/src/types/gir-callback-element.ts +0 -28
  562. package/src/types/gir-class-element.ts +0 -71
  563. package/src/types/gir-constant-element.ts +0 -17
  564. package/src/types/gir-constructor-element.ts +0 -18
  565. package/src/types/gir-direction.ts +0 -5
  566. package/src/types/gir-doc-element.ts +0 -73
  567. package/src/types/gir-enum-element.ts +0 -28
  568. package/src/types/gir-field-element.ts +0 -31
  569. package/src/types/gir-function-element.ts +0 -19
  570. package/src/types/gir-implements.ts +0 -9
  571. package/src/types/gir-include.ts +0 -9
  572. package/src/types/gir-info-attrs.ts +0 -16
  573. package/src/types/gir-info-elements.ts +0 -8
  574. package/src/types/gir-instance-parameter.ts +0 -25
  575. package/src/types/gir-interface-element.ts +0 -53
  576. package/src/types/gir-member-element.ts +0 -19
  577. package/src/types/gir-method-element.ts +0 -25
  578. package/src/types/gir-module-resolved-by.ts +0 -11
  579. package/src/types/gir-modules-grouped-map.ts +0 -5
  580. package/src/types/gir-modules-grouped.ts +0 -13
  581. package/src/types/gir-namespace.ts +0 -47
  582. package/src/types/gir-package.ts +0 -7
  583. package/src/types/gir-prerequisite.ts +0 -5
  584. package/src/types/gir-property-element.ts +0 -31
  585. package/src/types/gir-record-element.ts +0 -47
  586. package/src/types/gir-repository.ts +0 -20
  587. package/src/types/gir-signal.ts +0 -43
  588. package/src/types/gir-transfer-ownership-type.ts +0 -5
  589. package/src/types/gir-transfer-ownership.ts +0 -6
  590. package/src/types/gir-type.ts +0 -16
  591. package/src/types/gir-union-element.ts +0 -35
  592. package/src/types/gir-unparsed-number.ts +0 -2
  593. package/src/types/gir-var-args.ts +0 -6
  594. package/src/types/gir-virtual-method.ts +0 -22
  595. package/src/types/index.ts +0 -119
  596. package/src/types/inheritance-table.ts +0 -3
  597. package/src/types/injection-callback.ts +0 -20
  598. package/src/types/injection-class.ts +0 -30
  599. package/src/types/injection-function.ts +0 -23
  600. package/src/types/injection-generic-parameter.ts +0 -3
  601. package/src/types/injection-instance-parameter.ts +0 -3
  602. package/src/types/injection-parameter.ts +0 -9
  603. package/src/types/injection-property.ts +0 -7
  604. package/src/types/injection-type.ts +0 -3
  605. package/src/types/injection.ts +0 -6
  606. package/src/types/local-name-check.ts +0 -5
  607. package/src/types/local-name-type.ts +0 -1
  608. package/src/types/local-name.ts +0 -8
  609. package/src/types/local-names.ts +0 -5
  610. package/src/types/module-type.ts +0 -1
  611. package/src/types/parsed-gir.ts +0 -5
  612. package/src/types/part-of-class.ts +0 -9
  613. package/src/types/part-of-module.ts +0 -8
  614. package/src/types/resolve-type.ts +0 -4
  615. package/src/types/sym-table-items.ts +0 -5
  616. package/src/types/transformation-case.ts +0 -7
  617. package/src/types/transformations.ts +0 -12
  618. package/src/types/ts-alias.ts +0 -11
  619. package/src/types/ts-callback-interface.ts +0 -11
  620. package/src/types/ts-callback.ts +0 -21
  621. package/src/types/ts-class.ts +0 -109
  622. package/src/types/ts-doc-tag.ts +0 -23
  623. package/src/types/ts-doc.ts +0 -23
  624. package/src/types/ts-enum.ts +0 -15
  625. package/src/types/ts-function.ts +0 -59
  626. package/src/types/ts-generic-parameter.ts +0 -8
  627. package/src/types/ts-instance-parameter.ts +0 -4
  628. package/src/types/ts-member.ts +0 -11
  629. package/src/types/ts-method.ts +0 -6
  630. package/src/types/ts-parameter.ts +0 -20
  631. package/src/types/ts-property.ts +0 -22
  632. package/src/types/ts-signal.ts +0 -21
  633. package/src/types/ts-type-name.ts +0 -1
  634. package/src/types/ts-type-separator.ts +0 -1
  635. package/src/types/ts-type.ts +0 -25
  636. package/src/types/ts-var.ts +0 -21
  637. package/src/types/type-gir-alias.ts +0 -2
  638. package/src/types/type-gir-class.ts +0 -2
  639. package/src/types/type-gir-element.ts +0 -25
  640. package/src/types/type-gir-enumeration-member.ts +0 -2
  641. package/src/types/type-gir-enumeration.ts +0 -2
  642. package/src/types/type-gir-function.ts +0 -8
  643. package/src/types/type-gir-interface.ts +0 -2
  644. package/src/types/type-gir-method.ts +0 -2
  645. package/src/types/type-gir-parameter.ts +0 -1
  646. package/src/types/type-gir-property.ts +0 -2
  647. package/src/types/type-gir-variable.ts +0 -1
  648. package/src/types/type-ts-element.ts +0 -13
  649. package/src/types/type-ts-enumeration-member.ts +0 -2
  650. package/src/types/type-ts-function.ts +0 -1
  651. package/src/types/type-ts-property.ts +0 -1
  652. package/src/types/user-config-load-result.ts +0 -6
  653. package/src/types/user-config.ts +0 -41
  654. package/templates/Cogl-2.0.d.ts +0 -0
  655. package/templates/Gjs/GObject-2.0.d.ts +0 -238
  656. package/templates/Gjs/Gio-2.0.d.ts +0 -64
  657. package/templates/Gjs/Gjs.d.ts +0 -204
  658. package/templates/Gjs/Gjs.js +0 -21
  659. package/templates/Gjs/GnomeShell.d.ts +0 -152
  660. package/templates/Gjs/GnomeShell.js +0 -10
  661. package/templates/Gjs/index.d.ts +0 -594
  662. package/templates/Gjs/index.js +0 -4
  663. package/templates/Gjs/misc/dbusUtils.d.ts +0 -15
  664. package/templates/Gjs/misc/dbusUtils.js +0 -6
  665. package/templates/Gjs/misc/extensionUtils.d.ts +0 -99
  666. package/templates/Gjs/misc/extensionUtils.js +0 -6
  667. package/templates/Gjs/misc/fileUtils.d.ts +0 -51
  668. package/templates/Gjs/misc/fileUtils.js +0 -6
  669. package/templates/Gjs/misc/gnomeSession.d.ts +0 -74
  670. package/templates/Gjs/misc/gnomeSession.js +0 -6
  671. package/templates/Gjs/misc/parentalControlsManager.d.ts +0 -42
  672. package/templates/Gjs/misc/parentalControlsManager.js +0 -6
  673. package/templates/Gjs/misc/signals.d.ts +0 -15
  674. package/templates/Gjs/misc/signals.js +0 -6
  675. package/templates/Gjs/module.d.ts +0 -6
  676. package/templates/Gjs/module.js +0 -16
  677. package/templates/Gjs/tsconfig.alias.json +0 -10
  678. package/templates/Gjs/ui/accessDialog.d.ts +0 -19
  679. package/templates/Gjs/ui/accessDialog.js +0 -6
  680. package/templates/Gjs/ui/altTab.d.ts +0 -124
  681. package/templates/Gjs/ui/altTab.js +0 -6
  682. package/templates/Gjs/ui/animation.d.ts +0 -58
  683. package/templates/Gjs/ui/animation.js +0 -6
  684. package/templates/Gjs/ui/appDisplay.d.ts +0 -204
  685. package/templates/Gjs/ui/appDisplay.js +0 -6
  686. package/templates/Gjs/ui/appFavorites.d.ts +0 -34
  687. package/templates/Gjs/ui/appFavorites.js +0 -6
  688. package/templates/Gjs/ui/appMenu.d.ts +0 -74
  689. package/templates/Gjs/ui/appMenu.js +0 -6
  690. package/templates/Gjs/ui/audioDeviceSelection.d.ts +0 -51
  691. package/templates/Gjs/ui/audioDeviceSelection.js +0 -6
  692. package/templates/Gjs/ui/background.d.ts +0 -255
  693. package/templates/Gjs/ui/background.js +0 -5
  694. package/templates/Gjs/ui/backgroundMenu.d.ts +0 -19
  695. package/templates/Gjs/ui/backgroundMenu.js +0 -5
  696. package/templates/Gjs/ui/barLevel.d.ts +0 -42
  697. package/templates/Gjs/ui/barLevel.js +0 -5
  698. package/templates/Gjs/ui/boxpointer.d.ts +0 -103
  699. package/templates/Gjs/ui/boxpointer.js +0 -5
  700. package/templates/Gjs/ui/calendar.d.ts +0 -261
  701. package/templates/Gjs/ui/calendar.js +0 -5
  702. package/templates/Gjs/ui/components/__init__.d.ts +0 -9
  703. package/templates/Gjs/ui/components/__init__.js +0 -6
  704. package/templates/Gjs/ui/components/automountManager.d.ts +0 -8
  705. package/templates/Gjs/ui/components/automountManager.js +0 -6
  706. package/templates/Gjs/ui/components/autorunManager.d.ts +0 -8
  707. package/templates/Gjs/ui/components/autorunManager.js +0 -6
  708. package/templates/Gjs/ui/components/index.d.ts +0 -6
  709. package/templates/Gjs/ui/components/index.js +0 -6
  710. package/templates/Gjs/ui/components/keyring.d.ts +0 -19
  711. package/templates/Gjs/ui/components/keyring.js +0 -6
  712. package/templates/Gjs/ui/components/networkAgent.d.ts +0 -10
  713. package/templates/Gjs/ui/components/networkAgent.js +0 -6
  714. package/templates/Gjs/ui/components/polkitAgent.d.ts +0 -19
  715. package/templates/Gjs/ui/components/polkitAgent.js +0 -6
  716. package/templates/Gjs/ui/components/telepathyClient.d.ts +0 -10
  717. package/templates/Gjs/ui/components/telepathyClient.js +0 -6
  718. package/templates/Gjs/ui/dialog.d.ts +0 -78
  719. package/templates/Gjs/ui/dialog.js +0 -0
  720. package/templates/Gjs/ui/dnd.d.ts +0 -127
  721. package/templates/Gjs/ui/dnd.js +0 -6
  722. package/templates/Gjs/ui/iconGrid.d.ts +0 -172
  723. package/templates/Gjs/ui/iconGrid.js +0 -6
  724. package/templates/Gjs/ui/layout.d.ts +0 -311
  725. package/templates/Gjs/ui/layout.js +0 -6
  726. package/templates/Gjs/ui/main.d.ts +0 -215
  727. package/templates/Gjs/ui/main.js +0 -6
  728. package/templates/Gjs/ui/messageList.d.ts +0 -113
  729. package/templates/Gjs/ui/messageList.js +0 -6
  730. package/templates/Gjs/ui/messageTray.d.ts +0 -423
  731. package/templates/Gjs/ui/messageTray.js +0 -6
  732. package/templates/Gjs/ui/modalDialog.d.ts +0 -96
  733. package/templates/Gjs/ui/modalDialog.js +0 -6
  734. package/templates/Gjs/ui/mpris.d.ts +0 -78
  735. package/templates/Gjs/ui/mpris.js +0 -6
  736. package/templates/Gjs/ui/notificationDaemon.d.ts +0 -5
  737. package/templates/Gjs/ui/notificationDaemon.js +0 -6
  738. package/templates/Gjs/ui/panel.d.ts +0 -65
  739. package/templates/Gjs/ui/panel.js +0 -6
  740. package/templates/Gjs/ui/panelMenu.d.ts +0 -51
  741. package/templates/Gjs/ui/panelMenu.js +0 -6
  742. package/templates/Gjs/ui/popupMenu.d.ts +0 -228
  743. package/templates/Gjs/ui/popupMenu.js +0 -6
  744. package/templates/Gjs/ui/ripples.d.ts +0 -44
  745. package/templates/Gjs/ui/ripples.js +0 -6
  746. package/templates/Gjs/ui/search.d.ts +0 -158
  747. package/templates/Gjs/ui/search.js +0 -6
  748. package/templates/Gjs/ui/switcherPopup.d.ts +0 -107
  749. package/templates/Gjs/ui/switcherPopup.js +0 -6
  750. package/templates/Gjs/ui/userWidget.d.ts +0 -13
  751. package/templates/Gjs/ui/userWidget.js +0 -6
  752. package/templates/Granite-1.0.d.ts +0 -7
  753. package/templates/Granite-7.0.d.ts +0 -7
  754. package/templates/GstBase-0.10.d.ts +0 -5
  755. package/templates/RygelServer-2.6.d.ts +0 -3
  756. package/templates/node-gtk/GObject-2.0.d.ts +0 -57
  757. package/templates/node-gtk/index.d.ts +0 -40
  758. package/templates/node-gtk/index.js +0 -9
  759. package/templates/node-gtk/module.d.ts +0 -6
  760. package/templates/node-gtk/module.js +0 -17
package/src/gir-module.ts DELETED
@@ -1,2827 +0,0 @@
1
- // TODO move this class into a web-worker? https://www.npmjs.com/package/web-worker
2
-
3
- import {
4
- Transformation,
5
- C_TYPE_MAP,
6
- FULL_TYPE_MAP,
7
- POD_TYPE_MAP,
8
- POD_TYPE_MAP_ARRAY,
9
- IGNORE_GIR_TYPE_TS_DOC_TYPES,
10
- } from './transformation.js'
11
- import { STATIC_NAME_ALREADY_EXISTS, MAX_CLASS_PARENT_DEPTH } from './constants.js'
12
- import { Logger } from './logger.js'
13
- import { Injector } from './injection/injector.js'
14
- import { GirFactory } from './gir-factory.js'
15
- import { ConflictResolver } from './conflict-resolver.js'
16
- import { DependencyManager } from './dependency-manager.js'
17
- import {
18
- NO_TSDATA,
19
- WARN_NOT_FOUND_TYPE,
20
- WARN_CONSTANT_ALREADY_EXPORTED,
21
- WARN_DUPLICATE_SYMBOL,
22
- WARN_DUPLICATE_PARAMETER,
23
- WARN_DUPLICATE_ENUM_IDENTIFIER,
24
- } from './messages.js'
25
- import { isEqual, find, clone, girBool, removeNamespace, addNamespace, girElementIsIntrospectable } from './utils.js'
26
- import { SymTable } from './symtable.js'
27
- import type {
28
- Dependency,
29
- GirRepository,
30
- GirNamespace,
31
- GirAliasElement,
32
- GirEnumElement,
33
- GirMemberElement,
34
- GirFunctionElement,
35
- GirClassElement,
36
- GirArrayType,
37
- GirType,
38
- GirCallableParams,
39
- GirCallableParamElement,
40
- GirVirtualMethodElement,
41
- GirSignalElement,
42
- GirCallableReturn,
43
- GirRecordElement,
44
- GirCallbackElement,
45
- GirConstantElement,
46
- GirBitfieldElement,
47
- GirFieldElement,
48
- GirMethodElement,
49
- GirPropertyElement,
50
- GirAnyElement,
51
- GirUnionElement,
52
- GirInstanceParameter,
53
- GirInterfaceElement,
54
- GirConstructorElement,
55
- GirDocElement,
56
- TypeGirVariable,
57
- TypeGirClass,
58
- TypeGirEnumerationMember,
59
- LocalNameCheck,
60
- LocalNameType,
61
- LocalName,
62
- LocalNames,
63
- TsDoc,
64
- TsDocTag,
65
- TsClass,
66
- TsMethod,
67
- TsFunction,
68
- TsProperty,
69
- TsVar,
70
- TsParameter,
71
- TsInstanceParameter,
72
- TsCallbackInterface,
73
- TsMember,
74
- TsEnum,
75
- TsAlias,
76
- TsType,
77
- TsGenericParameter,
78
- TsCallback,
79
- InheritanceTable,
80
- ParsedGir,
81
- GenerateConfig,
82
- ClassParent,
83
- InjectionParameter,
84
- TsSignal,
85
- } from './types/index.js'
86
-
87
- export class GirModule {
88
- /**
89
- * Array of all gir modules
90
- */
91
- static allGirModules: GirModule[] = []
92
- /**
93
- * E.g. 'Gtk'
94
- */
95
- namespace: string
96
- /**
97
- * E.g. '3.0'
98
- */
99
- version = '0.0'
100
- /**
101
- * E.g. 'Gtk-3.0'
102
- */
103
- packageName: string
104
- /**
105
- * E.g. 'Gtk30'
106
- * Is used in the generated index.d.ts, for example: `import * as Gtk30 from "./Gtk-3.0.js";`
107
- */
108
- importName: string
109
-
110
- dependencies: Dependency[] = []
111
- private _transitiveDependencies: Dependency[] = []
112
-
113
- set transitiveDependencies(deps: Dependency[]) {
114
- this._transitiveDependencies = this.checkTransitiveDependencies(deps)
115
- }
116
-
117
- get transitiveDependencies(): Dependency[] {
118
- return this._transitiveDependencies
119
- }
120
-
121
- get allDependencies(): Dependency[] {
122
- return [...new Set([...this.dependencies, ...this.transitiveDependencies])]
123
- }
124
-
125
- repo: GirRepository
126
- ns: GirNamespace = { $: { name: '', version: '0.0' } }
127
- /**
128
- * Used to find namespaces that are used in other modules
129
- */
130
- symTable: SymTable
131
-
132
- transformation: Transformation
133
-
134
- girFactory = new GirFactory()
135
-
136
- dependencyManager: DependencyManager
137
-
138
- conflictResolver: ConflictResolver
139
-
140
- log: Logger
141
-
142
- inject: Injector
143
-
144
- extends?: string
145
-
146
- /**
147
- * To prevent constants from being exported twice, the names already exported are saved here for comparison.
148
- * Please note: Such a case is only known for Zeitgeist-2.0 with the constant "ATTACHMENT"
149
- */
150
- constNames: { [varName: string]: GirConstantElement } = {}
151
-
152
- constructor(xml: ParsedGir, private readonly config: GenerateConfig) {
153
- this.repo = xml.repository
154
-
155
- if (!this.repo.namespace || !this.repo.namespace.length) {
156
- throw new Error(`Namespace not found!`)
157
- }
158
-
159
- this.dependencyManager = DependencyManager.getInstance(this.config)
160
- this.dependencies = this.dependencyManager.fromGirIncludes(this.repo.include || [])
161
- this.ns = this.repo.namespace[0]
162
- this.namespace = this.ns.$.name
163
- this.version = this.ns.$.version
164
- this.packageName = `${this.namespace}-${this.version}`
165
- this.transformation = new Transformation(this.packageName, config)
166
- this.log = new Logger(config.environment, config.verbose, this.packageName || 'GirModule')
167
- this.conflictResolver = new ConflictResolver(config.environment, config.verbose)
168
- this.inject = new Injector(this.config.environment)
169
- this.importName = this.transformation.transformModuleNamespaceName(this.packageName)
170
-
171
- this.symTable = new SymTable(this.config, this.packageName, this.namespace)
172
- }
173
-
174
- private checkTransitiveDependencies(transitiveDependencies: Dependency[]) {
175
- // Always pull in GObject-2.0, as we may need it for e.g. GObject-2.0.type
176
- if (this.packageName !== 'GObject-2.0') {
177
- if (!find(transitiveDependencies, (x) => x.packageName === 'GObject-2.0')) {
178
- transitiveDependencies.push(this.dependencyManager.get('GObject', '2.0'))
179
- }
180
- }
181
-
182
- // Add missing dependencies
183
- if (this.packageName === 'UnityExtras-7.0') {
184
- if (!find(transitiveDependencies, (x) => x.packageName === 'Unity-7.0')) {
185
- transitiveDependencies.push(this.dependencyManager.get('Unity', '7.0'))
186
- }
187
- }
188
- if (this.packageName === 'UnityExtras-6.0') {
189
- if (!find(transitiveDependencies, (x) => x.packageName === 'Unity-6.0')) {
190
- transitiveDependencies.push(this.dependencyManager.get('Unity', '6.0'))
191
- }
192
- }
193
- if (this.packageName === 'GTop-2.0') {
194
- if (!find(transitiveDependencies, (x) => x.packageName === 'GLib-2.0')) {
195
- transitiveDependencies.push(this.dependencyManager.get('GLib', '2.0'))
196
- }
197
- }
198
-
199
- return transitiveDependencies
200
- }
201
-
202
- private getTsDoc(girDoc: GirDocElement) {
203
- const tsDoc: TsDoc = {
204
- text: '',
205
- tags: [],
206
- }
207
- if (girDoc.doc?.[0]?._) {
208
- let text = girDoc.doc?.[0]?._ || ''
209
- text = this.transformation.transformGirDoc(text)
210
- tsDoc.text = text
211
- }
212
- return tsDoc
213
- }
214
-
215
- private getTsDocGirElementTags(tsTypeName?: string, girTypeName?: string): TsDocTag[] {
216
- const tags: TsDocTag[] = []
217
-
218
- if (!girTypeName || IGNORE_GIR_TYPE_TS_DOC_TYPES.includes(girTypeName)) {
219
- return tags
220
- }
221
-
222
- tags.push({
223
- tagName: girTypeName,
224
- paramName: '',
225
- text: '',
226
- })
227
-
228
- return tags
229
- }
230
-
231
- private getTsDocInParamTags(inParams?: GirCallableParamElement[]): TsDocTag[] {
232
- const tags: TsDocTag[] = []
233
- if (!inParams?.length) {
234
- return tags
235
- }
236
-
237
- for (const inParam of inParams) {
238
- if (!inParam._tsData) {
239
- throw new Error(NO_TSDATA('getTsDocInParamTags'))
240
- }
241
- if (!inParam._tsData?.doc) {
242
- inParam._tsData.doc = this.getTsDoc(inParam)
243
- }
244
- if (inParam._tsData?.name) {
245
- tags.push({
246
- paramName: inParam._tsData.name,
247
- tagName: 'param',
248
- text: inParam._tsData.doc.text
249
- ? this.transformation.transformGirDocTagText(inParam._tsData.doc.text)
250
- : '',
251
- })
252
- }
253
- }
254
-
255
- return tags
256
- }
257
-
258
- private annotateFunctionArguments(
259
- girFunc:
260
- | GirMethodElement
261
- | GirFunctionElement
262
- | GirConstructorElement
263
- | GirVirtualMethodElement
264
- | GirCallbackElement
265
- | GirSignalElement,
266
- ): void {
267
- const funcName = girFunc._fullSymName
268
- if (funcName && girFunc.parameters) {
269
- for (const girParams of girFunc.parameters) {
270
- if (girParams.parameter) {
271
- for (const girParam of girParams.parameter) {
272
- girParam._module = this
273
- if (girParam.$ && girParam.$.name) {
274
- girParam._fullSymName = `${funcName}.${girParam.$.name}`
275
- }
276
- }
277
- }
278
- }
279
- }
280
- }
281
-
282
- private annotateFunctionReturn(
283
- girFunc:
284
- | GirMethodElement
285
- | GirFunctionElement
286
- | GirConstructorElement
287
- | GirVirtualMethodElement
288
- | GirCallbackElement
289
- | GirSignalElement,
290
- ): void {
291
- const retVals = girFunc['return-value']
292
- if (retVals && girFunc._fullSymName)
293
- for (const retVal of retVals) {
294
- retVal._module = this
295
- retVal.girTypeName = 'callable-return'
296
- if (retVal.$ && retVal.$.name) {
297
- retVal._fullSymName = `${girFunc._fullSymName}.${retVal.$.name}`
298
- }
299
- }
300
- }
301
-
302
- /**
303
- * Functions which are not part of a class
304
- * @param girFuncs
305
- */
306
- private annotateFunctions(girFuncs: GirFunctionElement[] | GirCallbackElement[]): void {
307
- if (Array.isArray(girFuncs))
308
- for (const girFunc of girFuncs) {
309
- if (girFunc?.$?.name) {
310
- // girFunc._girType = girType
311
- girFunc._fullSymName = `${this.namespace}.${girFunc.$.name}`
312
- this.annotateFunctionArguments(girFunc)
313
- this.annotateFunctionReturn(girFunc)
314
- }
315
- }
316
- }
317
-
318
- /**
319
- * Functions and methods of a class
320
- */
321
- private annotateMethods(
322
- girClass: GirClassElement | GirRecordElement | GirInterfaceElement,
323
- girFuncs:
324
- | GirMethodElement[]
325
- | GirFunctionElement[]
326
- | GirConstructorElement[]
327
- | GirVirtualMethodElement[]
328
- | GirSignalElement[],
329
- ): void {
330
- if (Array.isArray(girFuncs))
331
- for (const girFunc of girFuncs) {
332
- if (girFunc?.$?.name) {
333
- // girFunc._girType = girType
334
- // girFunc._tsType = tsType
335
- girFunc._class = girClass
336
- const nsName = girClass ? girClass._fullSymName : this.namespace
337
- if (nsName) girFunc._fullSymName = `${nsName}.${girFunc.$.name}`
338
- this.annotateFunctionArguments(girFunc)
339
- this.annotateFunctionReturn(girFunc)
340
- }
341
- }
342
- }
343
-
344
- /**
345
- * Variables which are not part of a class
346
- */
347
- private annotateVariables(girVars: GirConstantElement[]): void {
348
- for (const girVar of girVars) {
349
- girVar._module = this
350
- if (girVar.$ && girVar.$.name) {
351
- girVar._fullSymName = `${this.namespace}.${girVar.$.name}`
352
- }
353
- }
354
- }
355
-
356
- private annotateFields(
357
- girClass: GirClassElement | GirRecordElement | GirInterfaceElement | null,
358
- girVars: GirPropertyElement[],
359
- ): void
360
-
361
- private annotateFields(
362
- girClass: GirClassElement | GirRecordElement | GirInterfaceElement | null,
363
- girVars: GirFieldElement[],
364
- ): void
365
-
366
- /**
367
- * Fields are variables which are part of a class
368
- * @see https://www.typescriptlang.org/docs/handbook/2/classes.html#fields
369
- */
370
- private annotateFields(
371
- girClass: GirClassElement | GirRecordElement | GirInterfaceElement,
372
- girVars: GirPropertyElement[] | GirFieldElement[],
373
- ): void {
374
- for (const girVar of girVars) {
375
- const nsName = girClass ? girClass._fullSymName : this.namespace
376
- girVar._module = this
377
- if (girClass) {
378
- girVar._class = girClass
379
- }
380
-
381
- if (girVar.$ && girVar.$.name && nsName) {
382
- girVar._fullSymName = `${nsName}.${girVar.$.name}`
383
- }
384
- }
385
- }
386
-
387
- private annotateClass(girClass: GirClassElement, girTypeName: 'class'): void
388
- private annotateClass(girClass: GirRecordElement, girTypeName: 'record'): void
389
- private annotateClass(girClass: GirInterfaceElement, girTypeName: 'interface'): void
390
-
391
- private annotateClass(girClass: GirClassElement | GirRecordElement | GirInterfaceElement) {
392
- girClass._module = this
393
- girClass._fullSymName = `${this.namespace}.${girClass.$.name}`
394
-
395
- const constructors = Array.isArray(girClass.constructor) ? girClass.constructor : []
396
- const signals = ((girClass as GirClassElement | GirInterfaceElement).signal ||
397
- girClass['glib:signal'] ||
398
- []) as GirSignalElement[]
399
- const functions = girClass.function || []
400
- const methods = girClass.method || []
401
- const vMethods = (girClass as GirClassElement)['virtual-method'] || new Array<GirVirtualMethodElement>()
402
- const properties = girClass.property
403
- const fields = girClass.field
404
-
405
- this.annotateMethods(girClass, constructors)
406
- this.annotateMethods(girClass, functions)
407
- this.annotateMethods(girClass, methods)
408
- this.annotateMethods(girClass, vMethods)
409
- this.annotateMethods(girClass, signals)
410
- if (properties) this.annotateFields(girClass, properties)
411
- if (fields) this.annotateFields(girClass, fields)
412
- }
413
-
414
- /**
415
- * Annotates the custom `_module`, `_fullSymName` and `_girType` properties.
416
- * Also registers the element on the `symTable`.
417
- * @param girElements
418
- * @param girType
419
- */
420
- private annotateAndRegisterGirElement(girElements: GirAnyElement[]): void {
421
- for (const girElement of girElements) {
422
- if (girElement?.$ && girElement.$.name) {
423
- // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-argument
424
- if (!girElementIsIntrospectable(girElement as any)) continue
425
-
426
- girElement._module = this
427
- girElement._fullSymName = `${this.namespace}.${girElement.$.name}`
428
- if (this.symTable.get(this.allDependencies, girElement._fullSymName)) {
429
- this.log.warn(WARN_DUPLICATE_SYMBOL(girElement._fullSymName))
430
- }
431
-
432
- this.symTable.set(this.allDependencies, girElement._fullSymName, girElement)
433
- }
434
- }
435
- }
436
-
437
- /**
438
- * TODO: find better name for this method
439
- * @param girVar
440
- * @param fullTypeName
441
- * @returns e.g.
442
- * ```ts
443
- * {
444
- * namespace: "Gtk",
445
- * resValue: "Gtk.Widget"
446
- * }
447
- *
448
- */
449
- private fullTypeLookup(
450
- girVar:
451
- | GirCallableParamElement
452
- | GirCallableReturn
453
- | GirFieldElement
454
- | GirAliasElement
455
- | GirFieldElement
456
- | GirPropertyElement
457
- | GirConstantElement,
458
- fullTypeName: string | null,
459
- ) {
460
- let resValue = ''
461
- let namespace = ''
462
-
463
- if (!fullTypeName) {
464
- return {
465
- value: resValue,
466
- fullTypeName,
467
- namespace,
468
- }
469
- }
470
-
471
- // Fully qualify our type name
472
- if (!fullTypeName.includes('.')) {
473
- let tryFullTypeName = ''
474
-
475
- if (!resValue && girVar._module && girVar._module !== this) {
476
- tryFullTypeName = `${girVar._module.namespace}.${fullTypeName}`
477
- resValue = this.fullTypeLookupWithNamespace(tryFullTypeName).value
478
- if (resValue) {
479
- fullTypeName = tryFullTypeName
480
- namespace = girVar._module.namespace
481
- }
482
- }
483
-
484
- if (!resValue) {
485
- tryFullTypeName = `${this.namespace}.${fullTypeName}`
486
- resValue = this.fullTypeLookupWithNamespace(tryFullTypeName).value
487
- if (resValue) {
488
- fullTypeName = tryFullTypeName
489
- namespace = this.namespace
490
- }
491
- }
492
-
493
- const girClass = (
494
- girVar as
495
- | GirCallableParamElement
496
- | GirCallableReturn
497
- | GirFieldElement
498
- | GirAliasElement
499
- | GirFieldElement
500
- | GirPropertyElement
501
- )._class as GirClassElement | undefined
502
-
503
- if (!resValue && girClass?._module?.namespace && girClass._module !== this) {
504
- tryFullTypeName = `${girClass._module.namespace}.${fullTypeName}`
505
- resValue = this.fullTypeLookupWithNamespace(tryFullTypeName).value
506
- if (resValue) {
507
- fullTypeName = tryFullTypeName
508
- namespace = girClass?._module?.namespace
509
- }
510
- }
511
- }
512
-
513
- if (!resValue && fullTypeName) {
514
- resValue = this.fullTypeLookupWithNamespace(fullTypeName).value
515
- }
516
-
517
- return {
518
- value: resValue,
519
- namespace,
520
- }
521
- }
522
-
523
- /**
524
- * this method needs to be refactored, an array can also be an array of an array for example
525
- * @param girVar
526
- * @returns
527
- */
528
- getArrayData(
529
- girVar:
530
- | GirCallableReturn
531
- | GirAliasElement
532
- | GirFieldElement
533
- | GirCallableParamElement
534
- | GirPropertyElement
535
- | GirConstantElement,
536
- ) {
537
- let arrayType: GirType | null = null
538
- let arrCType: string | undefined
539
- let isArray = false
540
- let overrideTypeName: string | undefined
541
- let typeArray: GirType[] | undefined
542
-
543
- let collection: GirArrayType[] | GirType[] | undefined
544
-
545
- if ((girVar as GirCallableReturn | GirFieldElement).array) {
546
- collection = (girVar as GirCallableReturn | GirFieldElement).array
547
- } else if (/^GLib.S?List$/.test(girVar.type?.[0].$?.name || '')) {
548
- // This converts GLib.List<T> / GLib.SList<T> to T[]
549
- collection = girVar.type
550
- }
551
-
552
- if (collection && collection.length > 0) {
553
- isArray = true
554
- typeArray = collection[0].type
555
- if (collection[0].$) {
556
- const ea = collection[0].$
557
- arrCType = ea['c:type']
558
- }
559
- }
560
-
561
- if (typeArray && typeArray?.length > 0) {
562
- arrayType = typeArray[0]
563
- }
564
-
565
- if (isArray && arrayType?.$?.name && POD_TYPE_MAP_ARRAY[arrayType.$.name]) {
566
- isArray = false
567
- overrideTypeName = POD_TYPE_MAP_ARRAY[arrayType.$.name] as string | undefined
568
- }
569
-
570
- return {
571
- arrCType,
572
- arrayType,
573
- isArray,
574
- overrideTypeName,
575
- }
576
- }
577
-
578
- /**
579
- * Get the typescript type of a GirElement like a `GirPropertyElement` or `GirCallableReturn`
580
- * @param girVar
581
- */
582
- private getTsType(
583
- girVar:
584
- | GirCallableReturn
585
- | GirAliasElement
586
- | GirFieldElement
587
- | GirCallableParamElement
588
- | GirPropertyElement
589
- | GirConstantElement,
590
- tsClass: TsClass | null,
591
- defaults: Partial<TsType> = {},
592
- ) {
593
- let type: GirType | undefined = girVar.type?.[0]
594
- let fullTypeName: string | null = null
595
- let typeName = defaults.type || ''
596
- let isFunction = defaults.isFunction || false
597
- let isCallback = defaults.isCallback || false
598
- const nullable = this.typeIsNullable(girVar) || defaults.nullable || false
599
- const optional = this.typeIsOptional(girVar) || defaults.optional || false
600
-
601
- const girCallbacks: GirCallbackElement[] = []
602
- const array = this.getArrayData(girVar)
603
-
604
- if (array.overrideTypeName) {
605
- typeName = array.overrideTypeName
606
- }
607
-
608
- if (array.arrayType) {
609
- type = array.arrayType
610
- }
611
-
612
- const cType = type?.$ ? type.$['c:type'] : array.arrCType
613
- fullTypeName = type?.$?.name || null
614
- const callbacks = (girVar as GirFieldElement).callback
615
-
616
- if (!typeName && callbacks?.length) {
617
- for (const girCallback of callbacks) {
618
- if (!girElementIsIntrospectable(girCallback)) continue
619
-
620
- if (!girCallback._tsData) {
621
- const tsCallback = this.getFunctionTsData(girCallback, 'callback', tsClass, {
622
- isStatic: false,
623
- isArrowType: true,
624
- isGlobal: false,
625
- isVirtual: false,
626
- returnType: null,
627
- generics: [],
628
- })
629
-
630
- if (!tsCallback) continue
631
-
632
- girCallback._tsData = {
633
- ...tsCallback,
634
- girTypeName: 'callback',
635
- tsTypeName: this.girFactory.girTypeNameToTsTypeName('callback', false),
636
- tsCallbackInterface: this.getCallbackInterfaceTsData(girCallback),
637
- doc: this.getTsDoc(girCallback),
638
- overloads: [],
639
- }
640
- }
641
-
642
- if (girCallback._tsData) {
643
- girCallbacks.push(girCallback)
644
- isFunction = true
645
- isCallback = true
646
- }
647
- }
648
- }
649
-
650
- if (!isFunction) {
651
- const res = this.fullTypeLookup(girVar, fullTypeName)
652
- if (res.value) {
653
- typeName = res.value
654
- fullTypeName = typeName
655
- }
656
- }
657
-
658
- if (!typeName && type?.$?.name && POD_TYPE_MAP[type.$.name]) {
659
- // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
660
- typeName = POD_TYPE_MAP[type.$.name]
661
- }
662
-
663
- if (cType) {
664
- if (!typeName && C_TYPE_MAP(cType)) {
665
- typeName = C_TYPE_MAP(cType) || ''
666
- }
667
-
668
- if (!typeName && POD_TYPE_MAP[cType]) {
669
- // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
670
- typeName = POD_TYPE_MAP[cType]
671
- }
672
- }
673
-
674
- if (!typeName) {
675
- typeName = 'any'
676
- const logName = cType || fullTypeName || girVar.$.name || ''
677
- this.log.warn(WARN_NOT_FOUND_TYPE(logName))
678
- }
679
-
680
- // TODO: transform array to type with generics?
681
- const tsType = this.girFactory.newTsType({
682
- ...defaults,
683
- type: typeName,
684
- optional,
685
- nullable,
686
- callbacks: girCallbacks,
687
- isArray: array.isArray,
688
- isFunction,
689
- isCallback,
690
- })
691
-
692
- return tsType
693
- }
694
-
695
- /**
696
- *
697
- * @param girFunc
698
- * @returns
699
- */
700
- private getReturnType(
701
- girFunc:
702
- | GirMethodElement
703
- | GirFunctionElement
704
- | GirConstructorElement
705
- | GirCallbackElement
706
- | GirSignalElement
707
- | GirVirtualMethodElement,
708
- tsClass: TsClass | null,
709
- generics: TsGenericParameter[] = [],
710
- ) {
711
- let outArrayLengthIndex = -1
712
-
713
- if (girFunc['return-value'] && girFunc['return-value'].length > 1) {
714
- throw new Error('Several return values found!')
715
- }
716
-
717
- // There are no multiple return values, so we always use index 0
718
- const girVar = girFunc['return-value']?.[0] || null
719
-
720
- // We still use an array to allow multiple return values for later
721
- const returnTypes: TsType[] = []
722
-
723
- if (girVar) {
724
- returnTypes.push(this.getTsType(girVar, tsClass, { generics }))
725
-
726
- outArrayLengthIndex = girVar.array && girVar.array[0].$?.length ? Number(girVar.array[0].$.length) : -1
727
- } else {
728
- returnTypes.push(this.girFactory.newTsType({ type: 'void', generics }))
729
- }
730
-
731
- const retTypeIsVoid = returnTypes.length === 1 && returnTypes[0].type === 'void'
732
-
733
- return { returnTypes, outArrayLengthIndex, retTypeIsVoid }
734
- }
735
-
736
- private arrayLengthIndexLookup(girVar: GirCallableParamElement): number {
737
- if (!girVar.array) return -1
738
-
739
- const arr: GirArrayType = girVar.array[0]
740
- if (!arr.$) return -1
741
-
742
- if (arr.$.length) {
743
- return parseInt(arr.$.length)
744
- }
745
-
746
- return -1
747
- }
748
-
749
- private closureDataIndexLookup(girVar: GirCallableParamElement): number {
750
- if (!girVar.$.closure) return -1
751
-
752
- return parseInt(girVar.$.closure)
753
- }
754
-
755
- private destroyDataIndexLookup(girVar: GirCallableParamElement): number {
756
- if (!girVar.$.destroy) return -1
757
-
758
- return parseInt(girVar.$.destroy)
759
- }
760
-
761
- private processParams(
762
- params: GirCallableParamElement[],
763
- skip: GirCallableParamElement[],
764
- getIndex: (param: GirCallableParamElement) => number,
765
- ): void {
766
- for (const param of params) {
767
- const index = getIndex(param)
768
- if (index < 0) continue
769
- if (index >= params.length) continue
770
- skip.push(params[index])
771
- }
772
- }
773
-
774
- /**
775
- * Checks if the parameter is nullable (which results in ` | null`).
776
- *
777
- * @param girVar girVar to test
778
- */
779
- private typeIsNullable(
780
- girVar:
781
- | GirCallableParamElement
782
- | GirCallableReturn
783
- | GirAliasElement
784
- | GirFieldElement
785
- | GirConstantElement
786
- | GirPropertyElement,
787
- ): boolean {
788
- const a = (girVar as GirCallableParamElement).$
789
-
790
- if (!a) return false
791
-
792
- // Ignore depreciated `allow-none` if one of the new implementation `optional` or `nullable` is set
793
- if (girBool(a.optional) || girBool(a.nullable)) {
794
- return girBool(a.nullable)
795
- } else {
796
- return girBool(a.nullable) || girBool(a['allow-none'])
797
- }
798
- }
799
-
800
- /**
801
- * Checks if the parameter is optional (which results in `foo?: bar`).
802
- * @param girVar girVar to test
803
- */
804
- private typeIsOptional(
805
- girVar:
806
- | GirCallableParamElement
807
- | GirCallableReturn
808
- | GirAliasElement
809
- | GirFieldElement
810
- | GirConstantElement
811
- | GirPropertyElement,
812
- ): boolean {
813
- const a = (girVar as GirCallableParamElement).$
814
- if (!a) return false
815
-
816
- // Ignore depreciated `allow-none` if one of the new implementation `optional` or `nullable` is set
817
- if (girBool(a.optional) || girBool(a.nullable)) {
818
- return girBool(a.optional)
819
- } else {
820
- return girBool(a.optional) || girBool(a['allow-none'])
821
- }
822
- }
823
-
824
- private setParameterTsData(
825
- girParam: GirCallableParamElement,
826
- girParams: GirCallableParamElement[],
827
- paramNames: string[],
828
- skip: GirCallableParamElement[],
829
- parent: TsFunction | TsSignal,
830
- ) {
831
- // I think it's safest to force inout params to have the
832
- // same type for in and out
833
- const tsType = this.getTsType(girParam, parent.parent)
834
- // const optDirection = girParam.$.direction
835
-
836
- if (girParam._tsData) {
837
- // this.log.warn('[setParameterTsData] _tsData already set!')
838
- return girParam._tsData
839
- }
840
-
841
- if (tsType.isCallback) {
842
- throw new Error('Callback type is not implemented here')
843
- }
844
-
845
- let paramName = this.transformation.transformParameterName(girParam, false)
846
-
847
- if (paramNames.includes(paramName)) {
848
- this.log.warn(WARN_DUPLICATE_PARAMETER(paramName, girParam._fullSymName))
849
- paramName += '_'
850
- }
851
- paramNames.push(paramName)
852
-
853
- // In Typescript no optional parameters are allowed if the following ones are not optional
854
- if (tsType.optional) {
855
- const index = girParams.indexOf(girParam)
856
- const following = girParams
857
- .slice(index)
858
- .filter(() => skip.indexOf(girParam) === -1)
859
- .filter((p) => p.$.direction !== 'out')
860
-
861
- if (following.some((p) => !this.typeIsOptional(p))) {
862
- tsType.optional = false
863
- }
864
- }
865
-
866
- const tsParam: TsParameter = {
867
- name: paramName,
868
- type: [tsType],
869
- isRest: false,
870
- girTypeName: 'callable-param',
871
- doc: this.getTsDoc(girParam),
872
- parent,
873
- }
874
-
875
- girParam._tsData = tsParam
876
-
877
- // // TODO: remove this, wee need a special solution for Gio.AsyncReadyCallback instead
878
- girParam = this.inject.toParameterType(girParam)
879
-
880
- return girParam._tsData
881
- }
882
-
883
- private getInstanceParameterTsData(instanceParameter: GirInstanceParameter): TsInstanceParameter | undefined {
884
- const typeName = instanceParameter.type?.[0]?.$?.name || undefined
885
- const rec = typeName ? this.ns.record?.find((r) => r.$.name == typeName) : undefined
886
- const structFor = rec?.$['glib:is-gtype-struct-for']
887
- if (structFor && instanceParameter.$.name) {
888
- // TODO: Should use of a constructor, and even of an instance, be discouraged?
889
- return {
890
- name: instanceParameter.$.name,
891
- structFor,
892
- }
893
- }
894
- return undefined
895
- }
896
-
897
- private setParametersTsData(
898
- outArrayLengthIndex: number,
899
- girParams: GirCallableParams[] = [],
900
- parent: TsFunction | TsCallback,
901
- ) {
902
- const outParams: GirCallableParamElement[] = []
903
- const inParams: GirCallableParamElement[] = []
904
- const paramNames: string[] = []
905
- const instanceParameters: GirInstanceParameter[] = []
906
-
907
- if (girParams && girParams.length > 0) {
908
- for (const girParam of girParams) {
909
- const params = girParam?.parameter || []
910
-
911
- // Instance parameter needs to be exposed for class methods (see comment above getClassMethods())
912
- const instanceParameter = girParams[0]['instance-parameter']?.[0]
913
- if (instanceParameter) {
914
- instanceParameter._tsData = this.getInstanceParameterTsData(instanceParameter)
915
- if (instanceParameter._tsData) {
916
- instanceParameters.push(instanceParameter)
917
- }
918
- }
919
- if (params.length) {
920
- const skip = outArrayLengthIndex === -1 ? [] : [params[outArrayLengthIndex]]
921
-
922
- this.processParams(params, skip, (girVar) => this.arrayLengthIndexLookup(girVar))
923
- this.processParams(params, skip, (girVar) => this.closureDataIndexLookup(girVar))
924
- this.processParams(params, skip, (girVar) => this.destroyDataIndexLookup(girVar))
925
-
926
- for (const param of params) {
927
- if (skip.includes(param)) {
928
- continue
929
- }
930
-
931
- param._tsData = this.setParameterTsData(param, params, paramNames, skip, parent)
932
-
933
- const optDirection = param.$.direction
934
- if (optDirection === 'out' || optDirection === 'inout') {
935
- outParams.push(param)
936
- if (optDirection === 'out') continue
937
- }
938
- inParams.push(param)
939
- }
940
- }
941
- }
942
- }
943
-
944
- return { outParams, paramNames, inParams, instanceParameters }
945
- }
946
-
947
- private getVariableTsData(
948
- girVar: GirPropertyElement,
949
- girTypeName: 'property',
950
- tsTypeName: 'property' | 'constructor-property' | 'static-property',
951
- tsClass: TsClass | null,
952
- optional: boolean,
953
- nullable: boolean,
954
- allowQuotes: boolean,
955
- ): GirPropertyElement['_tsData']
956
-
957
- private getVariableTsData(
958
- girVar: GirConstantElement,
959
- girTypeName: 'constant',
960
- tsTypeName: 'constant',
961
- tsClass: TsClass | null,
962
- optional: boolean,
963
- nullable: boolean,
964
- allowQuotes: boolean,
965
- ): GirConstantElement['_tsData']
966
-
967
- private getVariableTsData(
968
- girVar: GirFieldElement,
969
- girTypeName: 'field',
970
- tsTypeName: 'property' | 'static-property',
971
- tsClass: TsClass | null,
972
- optional: boolean,
973
- nullable: boolean,
974
- allowQuotes: boolean,
975
- ): GirFieldElement['_tsData']
976
-
977
- private getVariableTsData(
978
- girVar: GirPropertyElement | GirFieldElement | GirConstantElement,
979
- girTypeName: 'property' | TypeGirVariable | 'field',
980
- tsTypeName: 'constant' | 'property' | 'constructor-property' | 'static-property',
981
- tsClass: TsClass | null,
982
- optional = false,
983
- nullable = false,
984
- allowQuotes = false,
985
- generics: TsGenericParameter[] = [],
986
- ) {
987
- if (!girVar.$.name) return undefined
988
- if (
989
- !girVar ||
990
- !girVar.$ ||
991
- !girBool(girVar.$.introspectable, true) ||
992
- girBool((girVar as GirFieldElement).$.private)
993
- ) {
994
- return undefined
995
- }
996
-
997
- if (girVar._tsData) {
998
- // this.log.warn('[getVariableTsData] _tsData already set!')
999
- return girVar._tsData
1000
- }
1001
-
1002
- let name = girVar.$.name
1003
-
1004
- switch (girTypeName) {
1005
- case 'property':
1006
- name = this.transformation.transformPropertyName(girVar.$.name, allowQuotes)
1007
- break
1008
- case 'constant':
1009
- name = this.transformation.transformConstantName(girVar.$.name, allowQuotes)
1010
- break
1011
- case 'field':
1012
- name = this.transformation.transformFieldName(girVar.$.name, allowQuotes)
1013
- break
1014
- }
1015
- // Use the out type because it can be a union which isn't appropriate
1016
- // for a property
1017
- const tsType = this.getTsType(girVar, tsClass, { optional, nullable, generics })
1018
-
1019
- const tsData: TsProperty | TsVar = {
1020
- name,
1021
- type: [tsType],
1022
- isInjected: false,
1023
- girTypeName,
1024
- tsTypeName,
1025
- doc: this.getTsDoc(girVar),
1026
- }
1027
-
1028
- tsData.doc.tags.push(...this.getTsDocGirElementTags(tsData.tsTypeName, tsData.girTypeName))
1029
-
1030
- return tsData
1031
- }
1032
-
1033
- private getPropertyTsData(
1034
- girProp: GirPropertyElement,
1035
- girTypeName: 'property',
1036
- tsTypeName: 'property' | 'constructor-property' | 'static-property',
1037
- tsClass: TsClass,
1038
- construct?: boolean,
1039
- optional?: boolean,
1040
- nullable?: boolean,
1041
- indentCount?: number,
1042
- ): TsProperty | undefined
1043
-
1044
- private getPropertyTsData(
1045
- girProp: GirFieldElement,
1046
- girTypeName: 'field',
1047
- tsTypeName: 'property' | 'static-property',
1048
- tsClass: TsClass,
1049
- construct?: boolean,
1050
- optional?: boolean,
1051
- nullable?: boolean,
1052
- indentCount?: number,
1053
- ): TsVar | undefined
1054
-
1055
- /**
1056
- *
1057
- * @param girProp
1058
- * @param girTypeName
1059
- * @param tsTypeName
1060
- * @param construct construct means include the property even if it's construct-only,
1061
- * @param optional optional means if it's construct-only it will also be marked optional (?)
1062
- * @param nullable
1063
- * @returns
1064
- */
1065
- private getPropertyTsData(
1066
- girProp: GirPropertyElement | GirFieldElement,
1067
- girTypeName: 'property' | 'field',
1068
- tsTypeName: 'constructor-property' | 'property' | 'static-property',
1069
- tsClass: TsClass,
1070
- construct = false,
1071
- optional?: boolean,
1072
- nullable?: boolean,
1073
- ): TsProperty | undefined {
1074
- if (!girBool(girProp.$.writable) && construct) return undefined
1075
- if (girBool((girProp as GirFieldElement).$.private)) return undefined
1076
-
1077
- if (girProp._tsData) {
1078
- // this.log.warn('[getPropertyTsData] _tsData already set!')
1079
- return girProp._tsData as TsProperty
1080
- }
1081
-
1082
- if (optional === undefined) optional = this.typeIsOptional(girProp)
1083
- if (nullable === undefined) nullable = this.typeIsNullable(girProp)
1084
-
1085
- const readonly =
1086
- !girBool(girProp.$.writable) || (!construct && girBool((girProp as GirPropertyElement).$['construct-only']))
1087
-
1088
- let tsData: TsProperty | undefined
1089
-
1090
- switch (girTypeName) {
1091
- case 'property':
1092
- tsData = this.getVariableTsData(
1093
- girProp as GirPropertyElement,
1094
- girTypeName,
1095
- tsTypeName,
1096
- tsClass,
1097
- construct && optional,
1098
- construct && nullable,
1099
- true,
1100
- ) as TsProperty
1101
- break
1102
- case 'field':
1103
- if (tsTypeName !== 'property') {
1104
- throw new Error(`Wrong tsType: "${tsTypeName}" for girType: "${girTypeName}`)
1105
- }
1106
- tsData = this.getVariableTsData(
1107
- girProp as GirFieldElement,
1108
- girTypeName,
1109
- tsTypeName,
1110
- tsClass,
1111
- construct && optional,
1112
- construct && nullable,
1113
- true,
1114
- ) as TsProperty
1115
- break
1116
- default:
1117
- throw new Error(`Unknown property type: ${girTypeName as string}`)
1118
- }
1119
-
1120
- if (!tsData?.name) {
1121
- return undefined
1122
- }
1123
-
1124
- tsData = {
1125
- ...tsData,
1126
- readonly,
1127
- }
1128
- return tsData
1129
- }
1130
-
1131
- /**
1132
- *
1133
- * @param girFunc
1134
- * @param prefix E.g. vfunc
1135
- * @param overrideReturnType
1136
- * @param isArrowType
1137
- * @param indentCount
1138
- */
1139
- private getFunctionTsData(
1140
- girFunc:
1141
- | GirMethodElement
1142
- | GirFunctionElement
1143
- | GirConstructorElement
1144
- | GirCallbackElement
1145
- | GirVirtualMethodElement,
1146
- girTypeName: 'virtual' | 'method' | 'constructor' | 'function' | 'callback' | 'static-function',
1147
- tsClass: TsClass | null,
1148
- overwrite: {
1149
- isStatic: boolean
1150
- isArrowType: boolean
1151
- isGlobal: boolean
1152
- isVirtual: boolean
1153
- isInjected?: boolean
1154
- returnType: string | null
1155
- generics: TsGenericParameter[]
1156
- },
1157
- ): TsFunction | undefined {
1158
- if (!girFunc || !girFunc.$ || !girBool(girFunc.$.introspectable, true) || girFunc.$['shadowed-by']) {
1159
- return undefined
1160
- }
1161
-
1162
- let hasUnresolvedConflict: boolean | undefined
1163
-
1164
- // 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
1165
- if (girFunc._tsData) {
1166
- hasUnresolvedConflict = girFunc._tsData?.hasUnresolvedConflict // WORKAROUND do not overwrite conflicts
1167
- }
1168
-
1169
- let name = girFunc.$.name
1170
- const { returnTypes, outArrayLengthIndex, retTypeIsVoid } = this.getReturnType(girFunc, tsClass)
1171
-
1172
- const shadows = (girFunc as GirMethodElement).$.shadows
1173
-
1174
- if (shadows) {
1175
- name = shadows
1176
- }
1177
-
1178
- // Overwrites
1179
- overwrite.isStatic = overwrite.isStatic || girTypeName === 'static-function' || girTypeName === 'constructor'
1180
- overwrite.isGlobal = overwrite.isGlobal || girTypeName === 'function'
1181
- overwrite.isVirtual = overwrite.isVirtual || girTypeName === 'virtual'
1182
- overwrite.isInjected = overwrite.isInjected || false
1183
-
1184
- // Function name transformation by environment
1185
- name = this.transformation.transformFunctionName(name, overwrite.isVirtual)
1186
-
1187
- const tsData: TsFunction = {
1188
- isArrowType: overwrite.isArrowType,
1189
- isStatic: overwrite.isStatic,
1190
- isGlobal: overwrite.isGlobal,
1191
- isVirtual: overwrite.isVirtual,
1192
- isInjected: overwrite.isInjected,
1193
- returnTypes,
1194
- retTypeIsVoid,
1195
- name,
1196
- overrideReturnType: overwrite.returnType || undefined,
1197
- inParams: [],
1198
- outParams: [],
1199
- instanceParameters: [],
1200
- generics: overwrite.generics,
1201
- hasUnresolvedConflict,
1202
- girTypeName,
1203
- tsTypeName: this.girFactory.girTypeNameToTsTypeName(girTypeName, overwrite.isStatic),
1204
- doc: this.getTsDoc(girFunc as GirDocElement),
1205
- overloads: [],
1206
- parent: tsClass,
1207
- }
1208
-
1209
- const { inParams, outParams, instanceParameters } = this.setParametersTsData(
1210
- outArrayLengthIndex,
1211
- girFunc.parameters,
1212
- tsData,
1213
- )
1214
-
1215
- tsData.inParams.push(...inParams)
1216
- tsData.outParams.push(...outParams)
1217
- tsData.instanceParameters.push(...instanceParameters)
1218
-
1219
- tsData.doc.tags.push(...this.getTsDocGirElementTags(tsData.tsTypeName, tsData.girTypeName))
1220
- tsData.doc.tags.push(...this.getTsDocInParamTags(tsData?.inParams))
1221
-
1222
- return tsData
1223
- }
1224
-
1225
- private getCallbackInterfaceTsData(girCallback: GirCallbackElement | GirConstructorElement) {
1226
- if (!girElementIsIntrospectable(girCallback)) return undefined
1227
-
1228
- const namespace = this.namespace
1229
-
1230
- const tsDataInterface: TsCallbackInterface = {
1231
- name: `${namespace}.${girCallback.$.name}`,
1232
- generics: [],
1233
- }
1234
-
1235
- return tsDataInterface
1236
- }
1237
-
1238
- private setCallbackTsData(girCallback: GirCallbackElement, tsClass: TsClass | null) {
1239
- const tsFunction = this.getFunctionTsData(girCallback, 'callback', tsClass, {
1240
- isStatic: false,
1241
- isArrowType: true,
1242
- isGlobal: false,
1243
- isVirtual: false,
1244
- returnType: null,
1245
- generics: [],
1246
- })
1247
- if (tsFunction) {
1248
- const tsCallback: TsCallback = {
1249
- ...tsFunction,
1250
- girTypeName: 'callback',
1251
- tsTypeName: this.girFactory.girTypeNameToTsTypeName('callback', false),
1252
- tsCallbackInterface: this.getCallbackInterfaceTsData(girCallback),
1253
- overloads: [],
1254
- }
1255
- girCallback._tsData = tsCallback
1256
-
1257
- this.inject.toCallback(girCallback)
1258
- }
1259
- return girCallback._tsData
1260
- }
1261
-
1262
- private getSignalCallbackInterfaceTsData(
1263
- girCallback: GirSignalElement,
1264
- girClass: GirClassElement | GirUnionElement | GirInterfaceElement | GirRecordElement,
1265
- ) {
1266
- if (!girElementIsIntrospectable(girCallback)) return undefined
1267
-
1268
- if (!girClass._tsData || !girClass._module) {
1269
- throw new Error(NO_TSDATA('getSignalCallbackTsData'))
1270
- }
1271
-
1272
- const className = girClass._tsData.name
1273
- const signalName = girCallback.$.name
1274
- const signalInterfaceName = this.transformation.transformSignalInterfaceName(signalName)
1275
- const namespace = girClass._module.namespace
1276
-
1277
- const tsDataInterface: TsCallbackInterface = {
1278
- name: `${namespace}.${className}.${signalInterfaceName}SignalCallback`,
1279
- generics: [],
1280
- overwriteDoc: {
1281
- text: `Signal callback interface for \`${signalName}\``,
1282
- tags: [],
1283
- },
1284
- }
1285
-
1286
- return tsDataInterface
1287
- }
1288
-
1289
- private getConstructorFunctionTsData(parentClass: TsClass, girConstructor: GirConstructorElement) {
1290
- if (!girElementIsIntrospectable(girConstructor)) return
1291
-
1292
- const constructorTypeName = addNamespace(parentClass.name, parentClass.namespace)
1293
-
1294
- return this.getFunctionTsData(girConstructor, 'constructor', parentClass, {
1295
- isStatic: true,
1296
- isArrowType: false,
1297
- isGlobal: false,
1298
- isVirtual: false,
1299
- returnType: constructorTypeName,
1300
- generics: [],
1301
- })
1302
- }
1303
-
1304
- private getSignalCallbackTsData(
1305
- girSignalFunc: GirSignalElement,
1306
- girClass: GirClassElement | GirUnionElement | GirInterfaceElement | GirRecordElement,
1307
- ) {
1308
- if (!girClass._tsData) {
1309
- throw new Error(NO_TSDATA('getSignalCallbackTsData'))
1310
- }
1311
-
1312
- if (girSignalFunc._tsData) {
1313
- return girSignalFunc._tsData
1314
- }
1315
-
1316
- // Leads to errors here
1317
- // if (!girElementIsIntrospectable(girSignalFunc)) return undefined
1318
-
1319
- const name = this.transformation.transform('signalName', girSignalFunc.$.name)
1320
-
1321
- const { returnTypes, outArrayLengthIndex, retTypeIsVoid } = this.getReturnType(girSignalFunc, girClass._tsData)
1322
-
1323
- if (this.config.environment === 'node') {
1324
- returnTypes[0].type === 'void'
1325
- }
1326
-
1327
- const tsCallback: TsCallback = {
1328
- name, // TODO: 'callback'?
1329
- returnTypes,
1330
- isArrowType: true,
1331
- isStatic: false,
1332
- isGlobal: false,
1333
- isVirtual: false,
1334
- isInjected: false,
1335
- retTypeIsVoid,
1336
- inParams: [],
1337
- instanceParameters: [],
1338
- outParams: [],
1339
- generics: [],
1340
- girTypeName: 'callback',
1341
- tsTypeName: this.girFactory.girTypeNameToTsTypeName('callback', false),
1342
- doc: this.getTsDoc(girSignalFunc),
1343
- overloads: [],
1344
- parent: girClass._tsData,
1345
- }
1346
-
1347
- const { inParams, outParams, instanceParameters } = this.setParametersTsData(
1348
- outArrayLengthIndex,
1349
- girSignalFunc.parameters,
1350
- tsCallback,
1351
- )
1352
-
1353
- if (this.config.environment === 'gjs') {
1354
- inParams.unshift(
1355
- this.girFactory.newGirCallableParamElement(
1356
- {
1357
- name: '$obj',
1358
- type: [
1359
- {
1360
- type: girClass._tsData.name,
1361
- },
1362
- ],
1363
- },
1364
- tsCallback,
1365
- ),
1366
- )
1367
- }
1368
-
1369
- tsCallback.inParams.push(...inParams)
1370
- tsCallback.outParams.push(...outParams)
1371
- tsCallback.instanceParameters.push(...instanceParameters)
1372
-
1373
- tsCallback.doc.tags.push(...this.getTsDocGirElementTags(tsCallback.tsTypeName, tsCallback.girTypeName))
1374
- tsCallback.doc.tags.push(...this.getTsDocInParamTags(tsCallback?.inParams))
1375
-
1376
- return tsCallback
1377
- }
1378
-
1379
- /**
1380
- * Generates signal methods like `connect`, `connect_after` and `emit` on Gjs or `connect`, `on`, `once`, `off` and `emit` an node-gtk
1381
- * for a default gir signal element
1382
- * @param girSignal
1383
- * @returns
1384
- */
1385
- private getClassSignalMethodsTsData(girSignal: GirSignalElement, parentClass: TsClass) {
1386
- if (!girSignal._tsData) {
1387
- throw new Error(NO_TSDATA('getClassSignalMethodsTsData'))
1388
- }
1389
-
1390
- const inParams = girSignal._tsData.inParams.slice(1).map((inParam) => {
1391
- const injectParam: InjectionParameter = {
1392
- ...inParam._tsData,
1393
- type: inParam._tsData?.type || [],
1394
- name: inParam._tsData?.name || 'unknown',
1395
- }
1396
- return injectParam
1397
- })
1398
-
1399
- return this.girFactory.newTsSignalMethods(
1400
- girSignal._tsData?.name,
1401
- girSignal._tsData?.tsCallbackInterface?.name,
1402
- inParams,
1403
- parentClass,
1404
- this.config.environment,
1405
- false,
1406
- )
1407
- }
1408
-
1409
- /**
1410
- * Generates signal methods for the GObject properties of a gir class element
1411
- * @param girClass
1412
- */
1413
- private getClassPropertySignalsMethods(
1414
- girClass: GirClassElement | GirUnionElement | GirInterfaceElement | GirRecordElement,
1415
- ) {
1416
- if (!girClass._tsData) {
1417
- throw new Error(NO_TSDATA('getClassPropertySignalsMethods'))
1418
- }
1419
-
1420
- const tsMethods: TsMethod[] = []
1421
-
1422
- const propertyNames = this.getClassNonStaticPropertyNames(girClass)
1423
- const namespacePrefix = this.namespace === 'GObject' ? '' : 'GObject.'
1424
-
1425
- // TODO: Signals: Generate SignalMethods instead of direct types
1426
- for (const propertyName of propertyNames) {
1427
- let callbackType = 'any'
1428
- if (this.config.environment === 'gjs') {
1429
- const objParam = `$obj: ${girClass._tsData.name}`
1430
- // TODO: create arrowType object instead of a pure string type, see Pango-1.0.Pango.FontMapClass.load_font for an example
1431
- callbackType = `((${objParam}, pspec: ${namespacePrefix}ParamSpec) => void)`
1432
- } else if (this.config.environment === 'node') {
1433
- callbackType = `(...args: any[]) => void`
1434
- }
1435
- tsMethods.push(
1436
- ...this.girFactory.newTsSignalMethods(
1437
- `notify::${propertyName}`,
1438
- callbackType,
1439
- [],
1440
- girClass._tsData,
1441
- this.config.environment,
1442
- ),
1443
- )
1444
- }
1445
-
1446
- return tsMethods
1447
- }
1448
-
1449
- private getGeneralSignalsMethods(parentClass: TsClass) {
1450
- return this.girFactory.newTsSignalMethods(undefined, undefined, [], parentClass, this.config.environment, true)
1451
- }
1452
-
1453
- private setSignalTsData(
1454
- girSignal: GirSignalElement,
1455
- girClass: GirClassElement | GirUnionElement | GirInterfaceElement | GirRecordElement,
1456
- ) {
1457
- if (!girClass._tsData) {
1458
- throw NO_TSDATA('setSignalTsData')
1459
- }
1460
-
1461
- if (!girSignal._tsData) {
1462
- girSignal._tsData = {
1463
- ...this.getSignalCallbackTsData(girSignal, girClass),
1464
- tsCallbackInterface: this.getSignalCallbackInterfaceTsData(girSignal, girClass),
1465
- tsMethods: [],
1466
- girTypeName: 'signal',
1467
- tsTypeName: this.girFactory.girTypeNameToTsTypeName('signal', false),
1468
- doc: this.getTsDoc(girSignal),
1469
- overloads: [],
1470
- }
1471
-
1472
- girSignal._tsData.doc.tags.push(
1473
- ...this.getTsDocGirElementTags(girSignal._tsData.tsTypeName, girSignal._tsData.girTypeName),
1474
- )
1475
- // TODO: this are the callback parameters
1476
- girSignal._tsData.doc.tags.push(...this.getTsDocInParamTags(girSignal._tsData?.inParams))
1477
-
1478
- if (!girSignal._tsData) {
1479
- throw NO_TSDATA('setSignalTsData')
1480
- }
1481
-
1482
- girSignal._tsData.tsMethods = this.getClassSignalMethodsTsData(girSignal, girClass._tsData)
1483
- }
1484
-
1485
- return girSignal._tsData
1486
- }
1487
-
1488
- private fixEnumerationDuplicateIdentifier(girEnum: GirEnumElement | GirBitfieldElement) {
1489
- if (!girElementIsIntrospectable(girEnum)) return girEnum
1490
-
1491
- if (!girEnum._tsData) {
1492
- throw new Error(NO_TSDATA('fixEnumerationDuplicateIdentifier'))
1493
- }
1494
-
1495
- if (!girEnum.member?.length) {
1496
- return girEnum
1497
- }
1498
-
1499
- const memberNames: string[] = []
1500
-
1501
- for (const girEnumMember of girEnum.member) {
1502
- if (!girEnumMember._tsData) {
1503
- throw new Error(NO_TSDATA('fixEnumerationDuplicateIdentifier'))
1504
- }
1505
- if (memberNames.find((name) => name === girEnumMember._tsData?.name)) {
1506
- const renamed = '_' + girEnumMember._tsData.name
1507
- this.log.warn(WARN_DUPLICATE_ENUM_IDENTIFIER(girEnumMember._tsData.name, renamed))
1508
- girEnumMember._tsData.name = renamed
1509
- }
1510
- memberNames.push(girEnumMember._tsData.name)
1511
- }
1512
- return girEnum
1513
- }
1514
-
1515
- private getEnumerationMemberTsData(girEnumMember: GirMemberElement, girTypeName: TypeGirEnumerationMember) {
1516
- const memberName = girEnumMember.$.name || girEnumMember.$['glib:nick'] || girEnumMember.$['c:identifier']
1517
- if (!girElementIsIntrospectable(girEnumMember, memberName)) return undefined
1518
-
1519
- if (girEnumMember._tsData) {
1520
- // this.log.warn('[getEnumerationMemberTsData] _tsData already set!')
1521
- return girEnumMember._tsData
1522
- }
1523
-
1524
- const name = this.transformation.transformEnumMember(memberName)
1525
- const tsData: TsMember = {
1526
- name,
1527
- girTypeName,
1528
- tsTypeName: this.girFactory.girTypeNameToTsTypeName(girTypeName, false),
1529
- doc: this.getTsDoc(girEnumMember),
1530
- }
1531
-
1532
- tsData.doc.tags.push(...this.getTsDocGirElementTags(tsData.tsTypeName, tsData.girTypeName))
1533
-
1534
- return tsData
1535
- }
1536
-
1537
- private getEnumerationTsData(girEnum: GirEnumElement | GirBitfieldElement, girTypeName: 'bitfield' | 'enum') {
1538
- if (!girElementIsIntrospectable(girEnum)) return undefined
1539
-
1540
- if (girEnum._tsData) {
1541
- // this.log.warn('[getEnumerationMemberTsData] _tsData already set!')
1542
- return girEnum._tsData
1543
- }
1544
-
1545
- // E.g. the NetworkManager-1.0 has enum names starting with 80211
1546
- const name = this.transformation.transformEnumName(girEnum)
1547
-
1548
- const tsData: TsEnum = {
1549
- name,
1550
- girTypeName,
1551
- tsTypeName: this.girFactory.girTypeNameToTsTypeName(girTypeName, false),
1552
- doc: this.getTsDoc(girEnum),
1553
- }
1554
-
1555
- tsData.doc.tags.push(...this.getTsDocGirElementTags(tsData.tsTypeName, tsData.girTypeName))
1556
-
1557
- return tsData
1558
- }
1559
-
1560
- private getAliasTsData(girAlias: GirAliasElement, tsClass: TsClass | null) {
1561
- if (!girElementIsIntrospectable(girAlias)) return undefined
1562
-
1563
- if (girAlias._tsData) {
1564
- // this.log.warn('[getEnumerationMemberTsData] _tsData already set!')
1565
- return girAlias._tsData
1566
- }
1567
-
1568
- const { type: typeName } = this.getTsType(girAlias, tsClass)
1569
- const name = girAlias.$.name
1570
- const tsData: TsAlias = {
1571
- name,
1572
- type: typeName,
1573
- girTypeName: 'alias',
1574
- tsTypeName: this.girFactory.girTypeNameToTsTypeName('alias', false),
1575
- }
1576
- return tsData
1577
- }
1578
-
1579
- private getConstantTsData(girConst: GirConstantElement, tsClass: TsClass | null) {
1580
- if (!girElementIsIntrospectable(girConst)) return undefined
1581
-
1582
- if (girConst._tsData) {
1583
- // this.log.warn('[getConstantTsData] _tsData already set!')
1584
- return girConst._tsData
1585
- }
1586
-
1587
- let tsData: TsVar | undefined = this.getVariableTsData(
1588
- girConst,
1589
- 'constant',
1590
- 'constant',
1591
- tsClass,
1592
- false,
1593
- false,
1594
- false,
1595
- )
1596
- if (tsData?.name) {
1597
- if (!this.constNames[tsData.name]) {
1598
- this.constNames[tsData.name] = girConst
1599
- } else {
1600
- this.log.warn(WARN_CONSTANT_ALREADY_EXPORTED(tsData.name))
1601
- tsData = undefined
1602
- }
1603
- }
1604
- return tsData
1605
- }
1606
-
1607
- private getClassConstructPropsTsData(
1608
- girClass: GirClassElement | GirUnionElement | GirInterfaceElement | GirRecordElement,
1609
- constructPropNames: LocalNames,
1610
- ) {
1611
- const constructProps: GirPropertyElement[] = []
1612
- const girProperties = (girClass as GirClassElement | GirInterfaceElement).property
1613
- if (!girProperties?.length) {
1614
- return constructProps
1615
- }
1616
- for (const girProp of girProperties) {
1617
- if (!girElementIsIntrospectable(girProp) || !girProp.$.name) continue
1618
- // Do not modify the original girProp, create a new one by clone `girProp` to `girConstrProp`
1619
- const girConstrProp = clone(girProp)
1620
-
1621
- if (!girClass._tsData) continue
1622
-
1623
- if (!girConstrProp._tsData) {
1624
- girConstrProp._tsData = this.getPropertyTsData(
1625
- girConstrProp,
1626
- 'property',
1627
- 'constructor-property',
1628
- girClass._tsData,
1629
- true,
1630
- true,
1631
- true,
1632
- 0,
1633
- )
1634
- }
1635
-
1636
- if (!girConstrProp._tsData) {
1637
- continue
1638
- }
1639
-
1640
- const localName = this.checkOrSetLocalName(girConstrProp, constructPropNames, 'property')
1641
-
1642
- if (!localName?.added) {
1643
- continue
1644
- }
1645
-
1646
- if (girConstrProp._fullSymName)
1647
- this.symTable.set(this.allDependencies, girConstrProp._fullSymName, girConstrProp)
1648
- constructProps.push(girConstrProp)
1649
- }
1650
-
1651
- return constructProps
1652
- }
1653
-
1654
- /**
1655
- * Some class/static methods are defined in a separate record which is not
1656
- * exported, but the methods are available as members of the JS constructor.
1657
- * In gjs one can use an instance of the object, a JS constructor or a GType
1658
- * as the method's instance-parameter.
1659
- * @see https://discourse.gnome.org/t/using-class-methods-like-gtk-widget-class-get-css-name-from-gjs/4001
1660
- * @param girClass
1661
- */
1662
- private getClassRecordMethods(
1663
- girClass: GirClassElement | GirUnionElement | GirInterfaceElement | GirRecordElement,
1664
- ): GirMethodElement[] {
1665
- const girMethods: GirMethodElement[] = []
1666
-
1667
- if (!girClass.$.name) return girMethods
1668
- const fName = girClass.$.name + 'Class'
1669
- let rec = this.ns.record?.find((r) => r.$.name == fName)
1670
- if (!rec || !this.isGtypeStructFor(girClass, rec)) {
1671
- rec = this.ns.record?.find((r) => this.isGtypeStructFor(girClass, r))
1672
- fName == rec?.$.name
1673
- }
1674
- if (!rec) return girMethods
1675
-
1676
- // Record methods
1677
- const methods = rec.method || []
1678
-
1679
- for (const girMethod of methods) {
1680
- if (!girElementIsIntrospectable(girMethod) || !girClass._tsData) continue
1681
-
1682
- if (!girMethod._tsData)
1683
- girMethod._tsData = this.getFunctionTsData(girMethod, 'static-function', girClass._tsData, {
1684
- isStatic: true,
1685
- isArrowType: false,
1686
- isGlobal: false,
1687
- isVirtual: false,
1688
- returnType: null,
1689
- generics: [],
1690
- })
1691
-
1692
- if (!girMethod._tsData) continue
1693
-
1694
- if (girMethod._tsData) {
1695
- if (girMethod._fullSymName) this.symTable.set(this.allDependencies, girMethod._fullSymName, girMethod)
1696
- girMethods.push(girMethod)
1697
- }
1698
- }
1699
- return girMethods
1700
- }
1701
-
1702
- /**
1703
- * Instance methods
1704
- * @param girClass
1705
- * @param localNames
1706
- */
1707
- private getClassMethodsTsData(
1708
- girClass: GirClassElement | GirUnionElement | GirInterfaceElement | GirRecordElement,
1709
- localNames: LocalNames,
1710
- ) {
1711
- const girMethods: GirMethodElement[] = []
1712
- if (girClass.method) {
1713
- for (const girMethod of girClass.method) {
1714
- if (!girElementIsIntrospectable(girMethod) || !girClass._tsData) continue
1715
-
1716
- if (!girMethod._tsData)
1717
- girMethod._tsData = this.getFunctionTsData(girMethod, 'method', girClass._tsData, {
1718
- isStatic: false,
1719
- isArrowType: false,
1720
- isGlobal: false,
1721
- isVirtual: false,
1722
- returnType: null,
1723
- generics: [],
1724
- })
1725
-
1726
- if (!girMethod._tsData) continue
1727
-
1728
- const localName = this.checkOrSetLocalName(girMethod, localNames, 'method')
1729
- if (localName?.added && localName.method) {
1730
- if (girMethod._fullSymName)
1731
- this.symTable.set(this.allDependencies, girMethod._fullSymName, girMethod)
1732
- girMethods.push(localName.method)
1733
- }
1734
- }
1735
- }
1736
- return girMethods
1737
- }
1738
-
1739
- private getClassFieldsTsData(
1740
- girClass: GirClassElement | GirUnionElement | GirInterfaceElement | GirRecordElement,
1741
- localNames: LocalNames,
1742
- ) {
1743
- const girFields: GirFieldElement[] = []
1744
- if (!girClass._tsData) {
1745
- this.log.warn(NO_TSDATA('setClassFieldsTsData'))
1746
- return girFields
1747
- }
1748
-
1749
- if (girClass.field) {
1750
- for (const girField of girClass.field) {
1751
- if (!girElementIsIntrospectable(girField)) continue
1752
- if (!girField._tsData)
1753
- girField._tsData = this.getVariableTsData(
1754
- girField,
1755
- 'field',
1756
- 'property',
1757
- girClass._tsData,
1758
- false,
1759
- false,
1760
- false,
1761
- )
1762
-
1763
- if (!girField._tsData) {
1764
- continue
1765
- }
1766
-
1767
- const localName = this.checkOrSetLocalName(girField, localNames, 'field')
1768
- if (localName?.added && localName.field) {
1769
- if (girField._fullSymName) this.symTable.set(this.allDependencies, girField._fullSymName, girField)
1770
- girFields.push(localName.field)
1771
- }
1772
- }
1773
- }
1774
-
1775
- return girFields
1776
- }
1777
-
1778
- private getGObjectProperties(girClass: GirClassElement | GirUnionElement | GirInterfaceElement | GirRecordElement) {
1779
- const girProperties: GirPropertyElement[] = []
1780
- if (girClass._fullSymName && !STATIC_NAME_ALREADY_EXISTS.includes(girClass._fullSymName)) {
1781
- // Records, classes and interfaces all have a static name
1782
- const type = this.girFactory.newTsType({ type: 'string' })
1783
- const staticNameProp = this.girFactory.newGirProperty({
1784
- isStatic: true,
1785
- name: 'name',
1786
- type: [type],
1787
- girTypeName: 'property',
1788
- })
1789
- girProperties.push(staticNameProp)
1790
- }
1791
-
1792
- if (girClass._tsData?.isDerivedFromGObject && girClass._module) {
1793
- if (this.config.environment === 'gjs') {
1794
- const type = this.girFactory.newTsType({
1795
- // TODO: Type not as string
1796
- type: 'GObject.GType',
1797
- generics: this.girFactory.newGenerics([
1798
- {
1799
- value: girClass._tsData.name,
1800
- },
1801
- ]),
1802
- })
1803
- const staticGTypeProp = this.girFactory.newGirProperty({
1804
- isStatic: true,
1805
- name: '$gtype',
1806
- type: [type],
1807
- girTypeName: 'property',
1808
- })
1809
- girProperties.push(staticGTypeProp)
1810
- } else if (this.config.environment === 'node') {
1811
- const staticGTypeProp = this.girFactory.newGirProperty({
1812
- isStatic: false,
1813
- name: '__gtype__',
1814
- type: [{ type: 'number' }],
1815
- girTypeName: 'property',
1816
- })
1817
- girProperties.push(staticGTypeProp)
1818
- }
1819
- }
1820
-
1821
- return girProperties
1822
- }
1823
-
1824
- private getClassPropertiesTsData(
1825
- girClass: GirClassElement | GirUnionElement | GirInterfaceElement | GirRecordElement,
1826
- localNames: LocalNames,
1827
- ) {
1828
- const girProperties: GirPropertyElement[] = []
1829
- const properties = (girClass as GirClassElement | GirInterfaceElement).property
1830
- if (properties) {
1831
- for (const girProperty of properties) {
1832
- if (!girElementIsIntrospectable(girProperty) || !girClass._tsData) continue
1833
-
1834
- girProperty._tsData = this.getPropertyTsData(girProperty, 'property', 'property', girClass._tsData)
1835
- if (!girProperty._tsData) continue
1836
-
1837
- const localName = this.checkOrSetLocalName(girProperty, localNames, 'property')
1838
- if (localName?.added && localName.property) {
1839
- if (girProperty._fullSymName)
1840
- this.symTable.set(this.allDependencies, girProperty._fullSymName, girProperty)
1841
- girProperties.push(localName.property)
1842
- }
1843
- }
1844
- }
1845
- return girProperties
1846
- }
1847
-
1848
- private getClassNonStaticPropertyNames(
1849
- girClass: GirClassElement | GirUnionElement | GirInterfaceElement | GirRecordElement,
1850
- ) {
1851
- const propertyNames: string[] = []
1852
-
1853
- if (!girClass._tsData) {
1854
- return propertyNames
1855
- }
1856
-
1857
- const girProperties = girClass._tsData.properties
1858
-
1859
- if (girProperties.length > 0) {
1860
- for (const girProperty of girProperties) {
1861
- if (!girElementIsIntrospectable(girProperty)) continue
1862
- if (
1863
- girProperty.$.name &&
1864
- !propertyNames.includes(girProperty.$.name) &&
1865
- !girProperty._tsData?.isStatic
1866
- ) {
1867
- propertyNames.push(girProperty.$.name)
1868
- }
1869
- }
1870
- }
1871
-
1872
- // Extended property names
1873
- for (const fullSymName of Object.keys(girClass._tsData.inherit)) {
1874
- const girProperties = girClass._tsData.inherit[fullSymName]?.class.properties
1875
- if (girProperties.length > 0) {
1876
- for (const girProperty of girProperties) {
1877
- if (!girElementIsIntrospectable(girProperty)) continue
1878
- if (
1879
- girProperty.$.name &&
1880
- !propertyNames.includes(girProperty.$.name) &&
1881
- !girProperty._tsData?.isStatic
1882
- ) {
1883
- propertyNames.push(girProperty.$.name)
1884
- }
1885
- }
1886
- }
1887
- }
1888
-
1889
- // Implemented property names
1890
- for (const fullSymName of Object.keys(girClass._tsData.implements)) {
1891
- const girProperties = girClass._tsData.implements[fullSymName]?.interface.properties
1892
- if (girProperties.length > 0) {
1893
- for (const girProperty of girProperties) {
1894
- if (!girElementIsIntrospectable(girProperty)) continue
1895
- if (
1896
- girProperty._tsData &&
1897
- girProperty.$.name &&
1898
- !propertyNames.includes(girProperty.$.name) &&
1899
- !girProperty._tsData?.isStatic
1900
- ) {
1901
- propertyNames.push(girProperty.$.name)
1902
- }
1903
- }
1904
- }
1905
- }
1906
-
1907
- return propertyNames
1908
- }
1909
-
1910
- private getClassConstructorsTsData(
1911
- girClass: GirClassElement | GirUnionElement | GirInterfaceElement | GirRecordElement,
1912
- ) {
1913
- if (!girClass._tsData) {
1914
- throw new Error(NO_TSDATA('getClassConstructorsTsData'))
1915
- }
1916
- const girConstructors: GirConstructorElement[] = []
1917
-
1918
- // JS constructor(s)
1919
- if (girClass._tsData?.isDerivedFromGObject) {
1920
- const constructorInParam: InjectionParameter = {
1921
- name: 'config',
1922
- type: [
1923
- {
1924
- optional: true,
1925
- type: girClass._tsData.constructPropInterfaceName,
1926
- },
1927
- ],
1928
- }
1929
- const realConstructor = this.girFactory.newGirFunction(
1930
- {
1931
- name: 'constructor',
1932
- isStatic: true,
1933
- inParams: [constructorInParam],
1934
- girTypeName: 'constructor',
1935
- },
1936
- girClass._tsData,
1937
- )
1938
- const initConstructor = this.girFactory.newGirFunction(
1939
- {
1940
- name: '_init',
1941
- inParams: [constructorInParam],
1942
- girTypeName: 'method',
1943
- },
1944
- girClass._tsData,
1945
- )
1946
- girConstructors.push(realConstructor, initConstructor)
1947
- }
1948
-
1949
- if (Array.isArray(girClass.constructor)) {
1950
- for (const girConstructor of girClass.constructor) {
1951
- if (!girElementIsIntrospectable(girConstructor)) continue
1952
-
1953
- girConstructor._tsData = this.getConstructorFunctionTsData(girClass._tsData, girConstructor)
1954
-
1955
- if (!girConstructor._tsData?.name) continue
1956
-
1957
- // Also add `new` pseudo constructors
1958
- const ADD_NEW_PSEUDO_CONSTRUCTOR = true
1959
-
1960
- // Inject an additional real constructor if static new(...) exists
1961
- if (girConstructor._tsData.name === 'new') {
1962
- const realConstructor = clone(girConstructor)
1963
- realConstructor._tsData = clone(realConstructor._tsData)
1964
-
1965
- if (realConstructor._tsData) {
1966
- realConstructor._tsData.overloads = []
1967
- realConstructor.$.name = 'constructor'
1968
- realConstructor._tsData.name = 'constructor'
1969
- girConstructors.push(realConstructor)
1970
- }
1971
-
1972
- if (ADD_NEW_PSEUDO_CONSTRUCTOR) {
1973
- girConstructors.push(girConstructor)
1974
- }
1975
- } else {
1976
- girConstructors.push(girConstructor)
1977
- }
1978
- }
1979
- }
1980
-
1981
- return girConstructors
1982
- }
1983
-
1984
- private getClassVirtualMethodsTsData(
1985
- girClass: GirClassElement | GirInterfaceElement | GirUnionElement | GirRecordElement,
1986
- ) {
1987
- const methods: GirVirtualMethodElement[] =
1988
- (girClass as GirClassElement | GirInterfaceElement)['virtual-method'] || []
1989
- const girMethods: GirVirtualMethodElement[] = []
1990
-
1991
- for (const girVMethod of methods) {
1992
- if (!girElementIsIntrospectable(girVMethod) || !girClass._tsData) continue
1993
-
1994
- girVMethod._tsData = this.getFunctionTsData(girVMethod, 'virtual', girClass._tsData, {
1995
- isStatic: false,
1996
- isArrowType: false,
1997
- isGlobal: false,
1998
- isVirtual: true,
1999
- returnType: null,
2000
- generics: [],
2001
- })
2002
- if (!girVMethod._tsData) continue
2003
-
2004
- if (girVMethod?._tsData?.name) {
2005
- girMethods.push(girVMethod)
2006
- }
2007
- }
2008
-
2009
- return girMethods
2010
- }
2011
-
2012
- /**
2013
- *
2014
- * @param girClass This is the class / interface the `parentClass` implements signals from
2015
- * @returns
2016
- */
2017
- private getClassSignalsTsData(
2018
- girClass: GirClassElement | GirUnionElement | GirInterfaceElement | GirRecordElement,
2019
- ) {
2020
- const girSignals: GirSignalElement[] = []
2021
-
2022
- const signals: GirSignalElement[] =
2023
- (girClass as GirClassElement | GirInterfaceElement).signal ||
2024
- (girClass as GirClassElement | GirInterfaceElement)['glib:signal'] ||
2025
- []
2026
- if (signals) {
2027
- for (const girSignal of signals) {
2028
- girSignal._tsData = this.setSignalTsData(girSignal, girClass)
2029
- if (!girSignal._tsData) continue
2030
- if (girSignal._fullSymName) this.symTable.set(this.allDependencies, girSignal._fullSymName, girSignal)
2031
-
2032
- girSignals.push(girSignal)
2033
- }
2034
- }
2035
- return girSignals
2036
- }
2037
-
2038
- getClassParentObject(
2039
- parentName: string,
2040
- namespace: string,
2041
- type: 'parent' | 'prerequisite' | 'implements',
2042
- ): ClassParent {
2043
- let qualifiedParentName: string
2044
- let parentModName: string
2045
-
2046
- // WORKAROUND: Fix wrong parent names
2047
- if (
2048
- (this.packageName === 'GstAudio-0.10' || this.packageName === 'ClutterGst-1.0') &&
2049
- (parentName === 'GstBase.BaseTransform' ||
2050
- parentName === 'GstBase.BaseSink' ||
2051
- parentName === 'GstBase.PushSrc')
2052
- ) {
2053
- const rename = parentName.replace('GstBase.', 'Gst.')
2054
- this.log.warn(`[getClassParentObject] Rename parent class "${parentName}" -> "${rename}"`)
2055
- parentName = rename
2056
- }
2057
-
2058
- if (parentName === 'GraniteServicesSettingsSerializable') {
2059
- parentName = 'ServicesSettingsSerializable'
2060
- this.log.warn(
2061
- `[getClassParentObject] Rename parent class "GraniteServicesSettingsSerializable" -> "ServicesSettingsSerializable"`,
2062
- )
2063
- }
2064
-
2065
- if (parentName.indexOf('.') < 0) {
2066
- qualifiedParentName = namespace + '.' + parentName
2067
- parentModName = namespace
2068
- } else {
2069
- qualifiedParentName = parentName
2070
- const split = parentName.split('.')
2071
- parentName = split[split.length - 1]
2072
- parentModName = split.slice(0, split.length - 1).join('.')
2073
- }
2074
- const localParentName = parentModName == namespace ? parentName : qualifiedParentName
2075
-
2076
- const dependencyExists = !!this.symTable.get(this.allDependencies, qualifiedParentName)
2077
-
2078
- const cls = this.getClassParent({
2079
- qualifiedParentName,
2080
- parentName,
2081
- })
2082
-
2083
- return {
2084
- qualifiedParentName,
2085
- localParentName,
2086
- type,
2087
- parentName,
2088
- cls,
2089
- dependencyExists,
2090
- // TODO: are there other types that can be inherited or implemented?
2091
- girTypeName: type === 'parent' ? 'class' : 'interface',
2092
- }
2093
- }
2094
-
2095
- private getClassParents(girClass: GirClassElement | GirUnionElement | GirInterfaceElement | GirRecordElement) {
2096
- const parents: ClassParent[] = []
2097
-
2098
- if (!girClass._module?.namespace) {
2099
- throw new Error('Namespace not found!')
2100
- }
2101
-
2102
- if (!girClass._tsData) {
2103
- throw new Error(NO_TSDATA('getClassParents'))
2104
- }
2105
-
2106
- const prerequisites = (girClass as GirInterfaceElement)?.prerequisite
2107
- const implmts = (girClass as GirInterfaceElement)?.implements
2108
-
2109
- if (implmts) {
2110
- for (const implement of implmts) {
2111
- const parentName = implement.$?.name
2112
- if (!parentName) continue
2113
- const parent = this.getClassParentObject(parentName, girClass._module.namespace, 'implements')
2114
- if (parent.dependencyExists) {
2115
- parents.push(parent)
2116
- }
2117
- }
2118
- }
2119
-
2120
- if (prerequisites) {
2121
- for (const prerequisite of prerequisites) {
2122
- const parentName = prerequisite.$?.name
2123
- if (!parentName) continue
2124
- const parent = this.getClassParentObject(parentName, girClass._module.namespace, 'prerequisite')
2125
- if (parent.dependencyExists) {
2126
- parents.push(parent)
2127
- }
2128
- }
2129
- }
2130
-
2131
- if ((girClass as GirClassElement).$.parent) {
2132
- const parentName = (girClass as GirClassElement).$.parent
2133
- if (parentName) {
2134
- const parent = this.getClassParentObject(parentName, girClass._module.namespace, 'parent')
2135
- if (parent.dependencyExists) {
2136
- parents.push(parent)
2137
- }
2138
- }
2139
- }
2140
-
2141
- // Please reply: Do all interfaces always inherit from GObject.Object?
2142
- // If this is a interface and GObject.Object is not in the parents array, add GObject.Object to the parents
2143
- if (girClass._tsData.girTypeName === 'interface' && girClass._fullSymName !== 'GObject.Object') {
2144
- if (!parents.find((parent) => parent.qualifiedParentName === 'GObject.Object')) {
2145
- // TODO make sure this class exists in symTable
2146
- const gObjectObjectCls =
2147
- this.symTable.getByHand<GirClassElement>('GObject-2.0.GObject.Object') || undefined
2148
- const parent: ClassParent = {
2149
- qualifiedParentName: 'GObject.Object',
2150
- localParentName: girClass._module.namespace === 'GObject' ? 'Object' : 'GObject.Object',
2151
- type: 'parent',
2152
- parentName: 'Object',
2153
- cls: gObjectObjectCls,
2154
- dependencyExists: !!gObjectObjectCls,
2155
- girTypeName: 'class',
2156
- }
2157
- if (parent.dependencyExists) {
2158
- parents.push(parent)
2159
- }
2160
- }
2161
- }
2162
-
2163
- return parents
2164
- }
2165
-
2166
- private setClassBaseTsData(
2167
- girClass: GirClassElement | GirUnionElement | GirInterfaceElement | GirRecordElement,
2168
- girTypeName: TypeGirClass,
2169
- ) {
2170
- if (!girClass?.$?.name) return undefined
2171
-
2172
- const girModule: GirModule = girClass._module ? girClass._module : this
2173
- let className = this.transformation.transformClassName(girClass.$.name)
2174
- /**
2175
- * E.g. 'Gtk'
2176
- */
2177
- const namespace = girModule.namespace
2178
- /**
2179
- * E.g. '3.0'
2180
- */
2181
- const version = girModule.version
2182
-
2183
- let qualifiedName: string
2184
- if (!className.includes('.')) {
2185
- qualifiedName = namespace + '.' + className
2186
- } else {
2187
- qualifiedName = className
2188
- const split = className.split('.')
2189
- className = split[split.length - 1]
2190
- }
2191
-
2192
- girClass._tsData = {
2193
- name: className,
2194
- qualifiedName,
2195
- parents: [],
2196
- namespace,
2197
- version,
2198
- isAbstract: this.isAbstractClass(girClass),
2199
- localNames: {},
2200
- constructPropNames: {},
2201
- inheritConstructPropInterfaceNames: [],
2202
- constructPropInterfaceName: `${namespace}.${className}.ConstructorProperties`,
2203
- fields: [],
2204
- properties: [],
2205
- conflictProperties: [],
2206
- constructProps: [],
2207
- propertySignalMethods: [],
2208
- methods: [],
2209
- conflictMethods: [],
2210
- virtualMethods: [],
2211
- constructors: [],
2212
- staticFunctions: [],
2213
- signals: [],
2214
- generics: [],
2215
- inherit: {},
2216
- implements: {},
2217
- girTypeName,
2218
- tsTypeName: this.girFactory.girTypeNameToTsTypeName(girTypeName, false),
2219
- doc: this.getTsDoc(girClass),
2220
- }
2221
-
2222
- girClass._tsData.doc.tags.push(
2223
- ...this.getTsDocGirElementTags(girClass._tsData.tsTypeName, girClass._tsData.girTypeName),
2224
- )
2225
-
2226
- girClass._tsData.parents = this.getClassParents(girClass)
2227
-
2228
- if (girClass._tsData.parents.length) {
2229
- for (const parent of girClass._tsData.parents) {
2230
- girClass._tsData.inheritConstructPropInterfaceNames.push(
2231
- `${parent.qualifiedParentName}.ConstructorProperties`,
2232
- )
2233
- }
2234
- }
2235
-
2236
- girClass._tsData.isDerivedFromGObject = this.isDerivedFromGObject(girClass)
2237
-
2238
- return girClass._tsData
2239
- }
2240
-
2241
- private setClassTsData(
2242
- girClass: GirClassElement | GirUnionElement | GirInterfaceElement | GirRecordElement,
2243
- girTypeName: TypeGirClass,
2244
- ): TsClass | undefined {
2245
- if (!girClass?.$?.name) return undefined
2246
-
2247
- if (girClass._tsData) {
2248
- return girClass._tsData
2249
- }
2250
-
2251
- girClass._tsData = this.setClassBaseTsData(girClass, girTypeName)
2252
- if (!girClass._tsData) {
2253
- return undefined
2254
- }
2255
-
2256
- // BASE
2257
-
2258
- if (girClass._tsData.isDerivedFromGObject) {
2259
- girClass._tsData.constructProps.push(
2260
- ...this.getClassConstructPropsTsData(girClass, girClass._tsData.constructPropNames),
2261
- )
2262
- }
2263
-
2264
- girClass._tsData.constructors.push(...this.getClassConstructorsTsData(girClass))
2265
- girClass._tsData.staticFunctions.push(...this.getClassStaticFunctionsTsData(girClass, girClass._tsData))
2266
-
2267
- girClass._tsData.fields.push(...this.getClassFieldsTsData(girClass, girClass._tsData.localNames))
2268
-
2269
- girClass._tsData.properties.push(...this.getClassPropertiesTsData(girClass, girClass._tsData.localNames))
2270
- girClass._tsData.methods.push(...this.getClassMethodsTsData(girClass, girClass._tsData.localNames))
2271
- girClass._tsData.virtualMethods.push(...this.getClassVirtualMethodsTsData(girClass))
2272
- girClass._tsData.signals.push(...this.getClassSignalsTsData(girClass))
2273
-
2274
- girClass._tsData.properties.push(...this.getGObjectProperties(girClass))
2275
-
2276
- // Copy fields, properties, methods, virtual methods and signals from inheritance tree
2277
- this.traverseInheritanceTree(girClass, girClass._tsData.girTypeName, (extendsCls, depth) => {
2278
- if (!girClass._tsData || !extendsCls._tsData || !extendsCls._fullSymName || !extendsCls._module) {
2279
- return
2280
- }
2281
-
2282
- if (girClass._fullSymName === extendsCls._fullSymName) {
2283
- return
2284
- }
2285
-
2286
- const key = extendsCls._module.packageName + '.' + extendsCls._fullSymName
2287
- if (girClass._tsData.inherit[key]) return
2288
-
2289
- girClass._tsData.inherit[key] = {
2290
- depth,
2291
- class: extendsCls._tsData,
2292
- }
2293
- })
2294
-
2295
- // Copy properties, methods and signals from implemented interface
2296
- this.forEachInterface(girClass, girClass._tsData.girTypeName, (iface, depth) => {
2297
- if (!girClass._tsData || !iface._tsData || !iface._fullSymName || !iface._module) {
2298
- return
2299
- }
2300
-
2301
- if (girClass._fullSymName === iface._fullSymName) {
2302
- return
2303
- }
2304
-
2305
- const key = iface._module.packageName + '.' + iface._fullSymName
2306
- if (girClass._tsData.implements[key]) return
2307
-
2308
- girClass._tsData.implements[key] = {
2309
- depth,
2310
- interface: iface._tsData,
2311
- }
2312
- })
2313
-
2314
- this.inject.toClass(girClass)
2315
-
2316
- girClass._tsData.propertySignalMethods.push(
2317
- ...this.getClassPropertySignalsMethods(girClass),
2318
- ...this.getGeneralSignalsMethods(girClass._tsData),
2319
- )
2320
-
2321
- if (this.config.fixConflicts) {
2322
- this.conflictResolver.repairClass(girClass)
2323
- }
2324
-
2325
- return girClass._tsData
2326
- }
2327
-
2328
- private isDerivedFromGObject(
2329
- girClass: GirClassElement | GirUnionElement | GirInterfaceElement | GirRecordElement,
2330
- ): boolean {
2331
- if (typeof girClass._tsData?.isDerivedFromGObject === 'boolean') return girClass._tsData.isDerivedFromGObject
2332
- let ret = false
2333
-
2334
- const onClassOrInterface = (
2335
- cls: GirClassElement | GirUnionElement | GirInterfaceElement | GirRecordElement,
2336
- ) => {
2337
- if (cls._tsData?.isDerivedFromGObject === true || cls._fullSymName === 'GObject.Object') {
2338
- ret = true
2339
- }
2340
- }
2341
- if (!girClass._tsData) throw new Error(NO_TSDATA('isDerivedFromGObject'))
2342
- this.traverseInheritanceTree(girClass, girClass._tsData.tsTypeName, onClassOrInterface)
2343
- this.forEachInterface(girClass, girClass._tsData.tsTypeName, onClassOrInterface)
2344
- return ret
2345
- }
2346
-
2347
- private getClassParent(parent: Pick<ClassParent, 'qualifiedParentName' | 'parentName'>) {
2348
- let parentPtr: GirClassElement | GirUnionElement | GirInterfaceElement | GirRecordElement | undefined =
2349
- undefined
2350
- if (this.symTable.get(this.allDependencies, parent.qualifiedParentName)) {
2351
- parentPtr =
2352
- (this.symTable.get(this.allDependencies, parent.qualifiedParentName) as GirClassElement) || undefined
2353
- }
2354
-
2355
- if (!parentPtr && parent.parentName == 'Object') {
2356
- parentPtr = (this.symTable.getByHand('GObject-2.0.GObject.Object') as GirClassElement) || undefined
2357
- }
2358
-
2359
- return parentPtr
2360
- }
2361
-
2362
- private traverseInheritanceTree(
2363
- girClass: GirClassElement | GirUnionElement | GirInterfaceElement | GirRecordElement,
2364
- gitTypeName: TypeGirClass,
2365
- callback: (
2366
- girClass: GirClassElement | GirUnionElement | GirInterfaceElement | GirRecordElement,
2367
- depth: number,
2368
- ) => void,
2369
- depth = 0,
2370
- recursive = true,
2371
- ): void {
2372
- if (!girClass.$.name) return
2373
- if (!girClass._tsData) girClass._tsData = this.setClassTsData(girClass, gitTypeName)
2374
- if (!girClass._tsData) return
2375
-
2376
- callback(girClass, depth)
2377
-
2378
- const parents = girClass._tsData.parents
2379
- if (recursive && parents.length) {
2380
- ++depth
2381
-
2382
- if (depth >= MAX_CLASS_PARENT_DEPTH) {
2383
- this.log.error('[traverseInheritanceTree] Maximum recursion depth reached')
2384
- return
2385
- }
2386
-
2387
- for (const parent of parents) {
2388
- if (!parent.parentName || parent.type !== 'parent') {
2389
- continue
2390
- }
2391
-
2392
- if (parent.cls) {
2393
- if (parent.cls === girClass) {
2394
- this.log.warn('[traverseInheritanceTree] A class cannot inherit itself')
2395
- continue
2396
- }
2397
-
2398
- this.traverseInheritanceTree(parent.cls, parent.girTypeName, callback, depth, recursive)
2399
- }
2400
- }
2401
- }
2402
- }
2403
-
2404
- private forEachInterface(
2405
- girIface: GirClassElement | GirUnionElement | GirInterfaceElement | GirRecordElement,
2406
- girTypeName: TypeGirClass,
2407
- callback: (
2408
- cls: GirClassElement | GirUnionElement | GirInterfaceElement | GirRecordElement,
2409
- depth: number,
2410
- ) => void,
2411
- recursive = true,
2412
- depth = 0,
2413
- ): void {
2414
- if (!girIface.$.name) return
2415
- if (!girIface._tsData) girIface._tsData = this.setClassTsData(girIface, girTypeName)
2416
- if (!girIface._tsData) {
2417
- throw new Error(NO_TSDATA('forEachInterface'))
2418
- }
2419
-
2420
- const parents = girIface._tsData.parents
2421
- if (parents.length) {
2422
- ++depth
2423
- for (const parent of parents) {
2424
- if (!parent.parentName || parent.type === 'parent') {
2425
- continue
2426
- }
2427
-
2428
- if (parent.cls) {
2429
- callback(parent.cls as GirInterfaceElement, depth)
2430
- // iface's prerequisite is also an interface, or it's
2431
- // a class and we also want to recurse classes
2432
-
2433
- if (recursive)
2434
- this.forEachInterface(
2435
- parent.cls as GirInterfaceElement,
2436
- parent.girTypeName,
2437
- callback,
2438
- recursive,
2439
- depth,
2440
- )
2441
- }
2442
- }
2443
- }
2444
- }
2445
-
2446
- /**
2447
- *
2448
- * @param girElement
2449
- * @param localNames Can be (constructor) properties, fields or methods
2450
- * @param type
2451
- */
2452
- private checkOrSetLocalName(
2453
- girElement:
2454
- | GirMethodElement
2455
- | GirPropertyElement
2456
- | GirFieldElement
2457
- | GirConstructorElement
2458
- | GirFunctionElement,
2459
- localNames: LocalNames,
2460
- type: LocalNameType,
2461
- ): LocalNameCheck | null {
2462
- let isOverloadable = false
2463
-
2464
- if (!girElement._tsData) {
2465
- return null
2466
- }
2467
-
2468
- const name = girElement._tsData?.name
2469
-
2470
- if (!name) {
2471
- return null
2472
- }
2473
-
2474
- // Methods are overloadable by typescript
2475
- // TODO Add support for properties
2476
- if (type === 'method') {
2477
- isOverloadable = true
2478
- }
2479
-
2480
- // Only names of the same type are overloadable
2481
- if (localNames[name]?.type && localNames[name].type !== type) {
2482
- // In GIO there are some methods and properties with the same name
2483
- // E.g. on `WebKit2.WebView.isLoading` and `WebKit2.WebView.isLoading()`
2484
- // See Gjs doc https://gjs-docs.gnome.org/webkit240~4.0_api/webkit2.webview#property-is_loading
2485
- // TODO prefer functions over properties (Overwrite the properties with the functions if they have the same name)
2486
-
2487
- return null
2488
- }
2489
-
2490
- // If name is found in localNames this variable was already defined
2491
- if (localNames?.[name]?.[type]?._tsData) {
2492
- // Ignore duplicates with the same type
2493
- // TODO should we use `this.functionSignaturesMatch` here?
2494
-
2495
- if (type === 'method') {
2496
- const tsMethod1 = (girElement as GirMethodElement)._tsData
2497
- const tsMethod2 = (localNames[name][type] as GirMethodElement)._tsData
2498
- if (!tsMethod1 || !tsMethod2) {
2499
- return null
2500
- }
2501
- // if (ConflictResolver.functionConflict(tsMethod1, tsMethod2)) {
2502
- // return null
2503
- // }
2504
- } else {
2505
- // TODO better handling of property and field
2506
- if (isEqual(localNames[name][type]?._tsData, girElement._tsData)) {
2507
- return null
2508
- }
2509
- }
2510
-
2511
- // Ignore if current method is not overloadable
2512
- if (!isOverloadable) {
2513
- return null
2514
- }
2515
- }
2516
-
2517
- localNames[name] = localNames[name] || {}
2518
- const localName: LocalName = {
2519
- ...localNames[name],
2520
- [type]: girElement,
2521
- type,
2522
- }
2523
-
2524
- localNames[name] = localName
2525
- return { ...localName, added: true }
2526
- }
2527
-
2528
- private isGtypeStructFor(
2529
- e: GirClassElement | GirUnionElement | GirInterfaceElement | GirRecordElement,
2530
- rec: GirRecordElement,
2531
- ) {
2532
- const isFor = rec.$['glib:is-gtype-struct-for']
2533
- return isFor && isFor == e.$.name
2534
- }
2535
-
2536
- /**
2537
- * E.g GObject.ObjectClass is a abstract class and required by UPowerGlib-1.0, UDisks-2.0 and others
2538
- * @param girClass
2539
- * @returns `true` if this is this a abstract class.
2540
- */
2541
- private isAbstractClass(girClass: GirClassElement | GirUnionElement | GirInterfaceElement | GirRecordElement) {
2542
- return girClass.$?.['glib:is-gtype-struct-for'] ? true : false
2543
- }
2544
-
2545
- /**
2546
- *
2547
- * @param girClass
2548
- * @returns
2549
- */
2550
- private getOtherStaticFunctions(
2551
- girClass: GirClassElement | GirUnionElement | GirInterfaceElement | GirRecordElement,
2552
- ): GirFunctionElement[] {
2553
- const girFunctions: GirFunctionElement[] = []
2554
-
2555
- if (!girClass._tsData) return girFunctions
2556
-
2557
- if (girClass.function?.length) {
2558
- for (const girFunction of girClass.function) {
2559
- girFunction._tsData = this.getFunctionTsData(girFunction, 'static-function', girClass._tsData, {
2560
- isStatic: true,
2561
- isArrowType: false,
2562
- isGlobal: false,
2563
- isVirtual: false,
2564
- returnType: null,
2565
- generics: [],
2566
- })
2567
-
2568
- if (!girFunction._tsData?.name) continue
2569
- if (girFunction._tsData.name.startsWith('new')) continue
2570
-
2571
- girFunctions.push(girFunction)
2572
- }
2573
- }
2574
- return girFunctions
2575
- }
2576
-
2577
- private getStaticNewFunctions(
2578
- girClass: GirClassElement | GirUnionElement | GirInterfaceElement | GirRecordElement,
2579
- parentClass: TsClass,
2580
- ): Array<GirFunctionElement | GirConstructorElement> {
2581
- const girFunctions: Array<GirFunctionElement | GirConstructorElement> = []
2582
- if (girClass.function?.length) {
2583
- for (const girFunction of girClass.function) {
2584
- girFunction._tsData = this.getConstructorFunctionTsData(parentClass, girFunction)
2585
- if (!girFunction._tsData?.name.startsWith('new')) continue
2586
- girFunctions.push(girFunction)
2587
- }
2588
- }
2589
- return girFunctions
2590
- }
2591
-
2592
- /**
2593
- * Static methods, <constructor> and <function>
2594
- * @param girClass
2595
- * @param constructorTypeName Used to overwrite the constructor return type
2596
- * @param useReference This value should be `false` for inherited and implemented classes / interfaces.
2597
- * Otherwise other modules would overwrite the return value of the constructor methods
2598
- */
2599
- private getClassStaticFunctionsTsData(
2600
- girClass: GirClassElement | GirUnionElement | GirInterfaceElement | GirRecordElement,
2601
- parentClass: TsClass,
2602
- ) {
2603
- const girStaticFuncs: Array<GirFunctionElement | GirConstructorElement | GirMethodElement> = []
2604
-
2605
- girStaticFuncs.push(...this.getStaticNewFunctions(girClass, parentClass))
2606
- girStaticFuncs.push(...this.getOtherStaticFunctions(girClass))
2607
- girStaticFuncs.push(...this.getClassRecordMethods(girClass))
2608
-
2609
- return girStaticFuncs
2610
- }
2611
-
2612
- private setModuleTsData() {
2613
- if (this.ns.enumeration) {
2614
- for (const girEnum of this.ns.enumeration) {
2615
- if (girEnum.member) {
2616
- for (const girEnumMember of girEnum.member) {
2617
- girEnumMember._tsData = this.getEnumerationMemberTsData(girEnumMember, 'enum-member')
2618
- if (!girEnumMember._tsData) continue
2619
- }
2620
- }
2621
- girEnum._tsData = this.getEnumerationTsData(girEnum, 'enum')
2622
- this.fixEnumerationDuplicateIdentifier(girEnum)
2623
- if (!girEnum._tsData) continue
2624
- }
2625
- }
2626
-
2627
- if (this.ns.bitfield)
2628
- for (const girBitfield of this.ns.bitfield) {
2629
- if (girBitfield.member)
2630
- for (const girEnumMember of girBitfield.member) {
2631
- girEnumMember._tsData = this.getEnumerationMemberTsData(girEnumMember, 'bitfield-member')
2632
- }
2633
- girBitfield._tsData = this.getEnumerationTsData(girBitfield, 'bitfield')
2634
- if (!girBitfield._tsData) continue
2635
- this.fixEnumerationDuplicateIdentifier(girBitfield)
2636
- }
2637
-
2638
- if (this.ns.constant)
2639
- for (const girConst of this.ns.constant) {
2640
- girConst._tsData = this.getConstantTsData(girConst, null)
2641
- if (!girConst._tsData) continue
2642
- }
2643
-
2644
- if (this.ns.function) {
2645
- for (const girFunc of this.ns.function) {
2646
- girFunc._tsData = this.getFunctionTsData(girFunc, 'function', null, {
2647
- isStatic: false,
2648
- isArrowType: false,
2649
- isGlobal: true,
2650
- isVirtual: false,
2651
- returnType: null,
2652
- generics: [],
2653
- })
2654
- if (!girFunc._tsData) continue
2655
- }
2656
- }
2657
-
2658
- if (this.ns.callback)
2659
- for (const girCallback of this.ns.callback) {
2660
- girCallback._tsData = this.setCallbackTsData(girCallback, null)
2661
- }
2662
-
2663
- if (this.ns.interface)
2664
- for (const girIface of this.ns.interface) {
2665
- girIface._tsData = this.setClassTsData(girIface, 'interface')
2666
- }
2667
-
2668
- if (this.ns.class)
2669
- for (const girClass of this.ns.class) {
2670
- girClass._tsData = this.setClassTsData(girClass, 'class')
2671
- if (!girClass._tsData) continue
2672
- }
2673
-
2674
- if (this.ns.record)
2675
- for (const girRecord of this.ns.record) {
2676
- girRecord._tsData = this.setClassTsData(girRecord, 'record')
2677
- if (!girRecord._tsData) continue
2678
- }
2679
-
2680
- if (this.ns.union)
2681
- for (const girUnion of this.ns.union) {
2682
- girUnion._tsData = this.setClassTsData(girUnion, 'union')
2683
- if (!girUnion._tsData) continue
2684
- }
2685
-
2686
- if (this.ns.alias) {
2687
- for (const girAlias of this.ns.alias) {
2688
- // GType is not a number in GJS
2689
- if (this.packageName !== 'GObject-2.0' || girAlias.$.name !== 'Type')
2690
- girAlias._tsData = this.getAliasTsData(girAlias, null)
2691
- if (!girAlias._tsData) continue
2692
- }
2693
- }
2694
- }
2695
-
2696
- /**
2697
- * TODO: find better name for this method
2698
- * @param fullTypeName
2699
- * @returns
2700
- */
2701
- private fullTypeLookupWithNamespace(fullTypeName: string) {
2702
- let resValue = ''
2703
- let namespace = ''
2704
-
2705
- // Check overwrites first
2706
- if (!resValue && fullTypeName && FULL_TYPE_MAP(this.config.environment, fullTypeName)) {
2707
- resValue = FULL_TYPE_MAP(this.config.environment, fullTypeName) || ''
2708
- }
2709
-
2710
- // Only use the fullTypeName as the type if it is found in the symTable
2711
- if (!resValue && this.symTable.get(this.allDependencies, fullTypeName)) {
2712
- if (fullTypeName.startsWith(this.namespace + '.')) {
2713
- resValue = removeNamespace(fullTypeName, this.namespace)
2714
- resValue = this.transformation.transformTypeName(resValue)
2715
- // TODO: check if resValue is a class, enum or interface before transformClassName
2716
- resValue = this.transformation.transformClassName(resValue)
2717
- namespace = this.namespace
2718
- resValue = namespace + '.' + resValue
2719
- } else {
2720
- const resValues = fullTypeName.split('.')
2721
- resValues.map((name) => this.transformation.transformTypeName(name))
2722
- // TODO: check if resValues[resValues.length - 1] is a class, enum, interface before transformClassName
2723
- resValues[resValues.length - 1] = this.transformation.transformClassName(
2724
- resValues[resValues.length - 1],
2725
- )
2726
- resValue = resValues.join('.')
2727
- namespace = resValues[0]
2728
- }
2729
- }
2730
-
2731
- return {
2732
- value: resValue,
2733
- namespace,
2734
- }
2735
- }
2736
-
2737
- private loadInheritance(inheritanceTable: InheritanceTable): void {
2738
- // Class hierarchy
2739
- for (const girClass of this.ns.class ? this.ns.class : []) {
2740
- let parent: string | null = null
2741
- if (girClass.$ && girClass.$.parent) parent = girClass.$.parent
2742
- if (!parent) continue
2743
- if (!girClass._fullSymName) continue
2744
-
2745
- if (!parent.includes('.')) {
2746
- parent = addNamespace(parent, this.namespace)
2747
- }
2748
-
2749
- const className = girClass._fullSymName
2750
-
2751
- const arr: string[] = inheritanceTable[className] || []
2752
- arr.push(parent)
2753
- inheritanceTable[className] = arr
2754
- }
2755
-
2756
- // Class interface implementations
2757
- for (const girClass of this.ns.class ? this.ns.class : []) {
2758
- if (!girClass._fullSymName) continue
2759
-
2760
- const names: string[] = []
2761
-
2762
- if (girClass.implements) {
2763
- for (const girImplements of girClass.implements) {
2764
- if (girImplements.$.name) {
2765
- let name: string = girImplements.$.name
2766
- if (!name.includes('.')) {
2767
- name = girClass._fullSymName.substring(0, girClass._fullSymName.indexOf('.') + 1) + name
2768
- }
2769
- names.push(name)
2770
- }
2771
- }
2772
- }
2773
-
2774
- if (names.length > 0) {
2775
- const className = girClass._fullSymName
2776
- const arr: string[] = inheritanceTable[className] || []
2777
- inheritanceTable[className] = arr.concat(names)
2778
- }
2779
- }
2780
- }
2781
-
2782
- private loadTypes(): void {
2783
- if (this.ns.bitfield) this.annotateAndRegisterGirElement(this.ns.bitfield)
2784
- if (this.ns.callback) this.annotateAndRegisterGirElement(this.ns.callback)
2785
- if (this.ns.class) this.annotateAndRegisterGirElement(this.ns.class)
2786
- if (this.ns.constant) this.annotateAndRegisterGirElement(this.ns.constant)
2787
- if (this.ns.enumeration) this.annotateAndRegisterGirElement(this.ns.enumeration)
2788
- if (this.ns.function) this.annotateAndRegisterGirElement(this.ns.function)
2789
- if (this.ns.interface) this.annotateAndRegisterGirElement(this.ns.interface)
2790
- if (this.ns.record) this.annotateAndRegisterGirElement(this.ns.record)
2791
- if (this.ns.union) this.annotateAndRegisterGirElement(this.ns.union)
2792
- if (this.ns.alias) this.annotateAndRegisterGirElement(this.ns.alias)
2793
-
2794
- if (this.ns.callback) for (const girCallback of this.ns.callback) this.annotateFunctionArguments(girCallback)
2795
-
2796
- for (const girClass of this.ns.class || []) {
2797
- this.annotateClass(girClass, 'class')
2798
- }
2799
- for (const girClass of this.ns.record || []) {
2800
- this.annotateClass(girClass, 'record')
2801
- }
2802
- for (const girClass of this.ns.interface || []) {
2803
- this.annotateClass(girClass, 'interface')
2804
- }
2805
-
2806
- if (this.ns.function) this.annotateFunctions(this.ns.function)
2807
- if (this.ns.callback) this.annotateFunctions(this.ns.callback)
2808
-
2809
- if (this.ns.constant) this.annotateVariables(this.ns.constant)
2810
- }
2811
-
2812
- /**
2813
- * Before processing the typescript data, each module should be initialized first.
2814
- * This is done in the `GenerationHandler`.
2815
- */
2816
- public init(inheritanceTable: InheritanceTable) {
2817
- this.loadTypes()
2818
- this.loadInheritance(inheritanceTable)
2819
- }
2820
-
2821
- /**
2822
- * Start processing the typescript data
2823
- */
2824
- public start() {
2825
- this.setModuleTsData()
2826
- }
2827
- }