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