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