@ts-for-gir/lib 4.0.0-beta.25 → 4.0.0-beta.26
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/package.json +12 -26
- package/src/constants.ts +154 -0
- package/src/dependency-manager.ts +427 -0
- package/src/formatters/default.ts +7 -0
- package/src/formatters/formatter.ts +3 -0
- package/src/formatters/index.ts +3 -0
- package/src/formatters/json.ts +7 -0
- package/src/generators/generator.ts +65 -0
- package/src/generators/index.ts +2 -0
- package/src/generics/clutter.ts +71 -0
- package/src/generics/generify.ts +74 -0
- package/src/generics/gio.ts +91 -0
- package/src/generics/glib.ts +31 -0
- package/src/generics/gtk.ts +99 -0
- package/src/generics/meta.ts +41 -0
- package/src/generics/st.ts +197 -0
- package/src/generics/visitor.ts +484 -0
- package/src/gir/alias.ts +73 -0
- package/src/gir/callback.ts +79 -0
- package/src/gir/const.ts +73 -0
- package/src/gir/constructor.ts +91 -0
- package/src/gir/data.ts +12 -0
- package/src/gir/dependency-resolver.ts +81 -0
- package/src/gir/direct-allocation-constructor.ts +65 -0
- package/src/gir/enum-member.ts +51 -0
- package/src/gir/enum.ts +126 -0
- package/src/gir/error.ts +82 -0
- package/src/gir/function.ts +296 -0
- package/src/gir/generics.ts +66 -0
- package/src/gir/gir-complex-record.ts +7 -0
- package/src/gir/index.ts +25 -0
- package/src/gir/introspected-base.ts +104 -0
- package/src/gir/introspected-class-member.ts +15 -0
- package/src/gir/introspected-classes.ts +1517 -0
- package/src/gir/introspected-namespace-member.ts +24 -0
- package/src/gir/namespace.ts +76 -0
- package/src/gir/parameter.ts +199 -0
- package/src/gir/promisify.ts +209 -0
- package/src/gir/property.ts +203 -0
- package/src/gir/record.ts +477 -0
- package/src/gir/registry.ts +184 -0
- package/src/gir/signal.ts +246 -0
- package/src/gir-module.ts +703 -0
- package/src/gir.ts +892 -0
- package/src/index.ts +16 -0
- package/src/injections/gee08.ts +89 -0
- package/src/injections/gee1.ts +35 -0
- package/src/injections/gio.ts +707 -0
- package/src/injections/glib.ts +275 -0
- package/src/injections/gobject.ts +901 -0
- package/src/injections/gtk4.ts +23 -0
- package/src/injections/inject.ts +43 -0
- package/src/injections/shell.ts +45 -0
- package/src/injections/tracker1.ts +42 -0
- package/src/library-version.ts +50 -0
- package/src/logger.ts +104 -0
- package/src/messages.ts +57 -0
- package/src/templates/index.ts +1 -0
- package/src/templates/template-engine.ts +178 -0
- package/src/types/answer-version.ts +4 -0
- package/src/types/any-introspected-type.ts +3 -0
- package/src/types/class-function-types.ts +49 -0
- package/src/types/class-member.ts +5 -0
- package/src/types/class-parent.ts +14 -0
- package/src/types/class.ts +45 -0
- package/src/types/config-flags.ts +5 -0
- package/src/types/construct-name.ts +13 -0
- package/src/types/dependency-map.ts +4 -0
- package/{lib/types/dependency.d.ts → src/types/dependency.ts} +17 -15
- package/{lib/types/file-info.d.ts → src/types/file-info.ts} +3 -3
- package/src/types/format.ts +1 -0
- package/src/types/generator-constructor.ts +7 -0
- package/src/types/generics-config.ts +90 -0
- package/src/types/gir-any-element.ts +35 -0
- package/src/types/gir-module-interface.ts +22 -0
- package/src/types/gir-module-resolved.ts +32 -0
- package/src/types/gir-type-name.ts +20 -0
- package/src/types/index.ts +94 -0
- package/{lib/types/inheritance-table.d.ts → src/types/inheritance-table.ts} +1 -1
- package/src/types/introspected.ts +18 -0
- package/src/types/local-name-check.ts +5 -0
- package/src/types/local-name-type.ts +1 -0
- package/src/types/local-name.ts +8 -0
- package/src/types/local-names.ts +5 -0
- package/src/types/metadata.ts +6 -0
- package/src/types/ns-loader.ts +7 -0
- package/src/types/options-base.ts +8 -0
- package/{lib/types/options-generation.d.ts → src/types/options-generation.ts} +22 -13
- package/src/types/options-load.ts +6 -0
- package/src/types/options-transform.ts +5 -0
- package/src/types/output-format.ts +1 -0
- package/{lib/types/package-data-parsed.d.ts → src/types/package-data-parsed.ts} +13 -13
- package/{lib/types/package-data.d.ts → src/types/package-data.ts} +12 -11
- package/src/types/package-section-parsed.ts +9 -0
- package/src/types/parsed-gir.ts +5 -0
- package/src/types/parsed-package-data.ts +7 -0
- package/src/types/property-case.ts +1 -0
- package/src/types/resolve-type.ts +4 -0
- package/src/types/template-data.ts +8 -0
- package/src/types/template-options.ts +33 -0
- package/src/types/transformation-case.ts +9 -0
- package/src/types/transformations.ts +5 -0
- package/{lib/types/ts-doc-tag.d.ts → src/types/ts-doc-tag.ts} +5 -3
- package/{lib/types/ts-doc.d.ts → src/types/ts-doc.ts} +5 -3
- package/{lib/types/type-gir-alias.d.ts → src/types/type-gir-alias.ts} +1 -1
- package/{lib/types/type-gir-class.d.ts → src/types/type-gir-class.ts} +1 -1
- package/src/types/type-gir-element.ts +25 -0
- package/{lib/types/type-gir-enumeration-member.d.ts → src/types/type-gir-enumeration-member.ts} +1 -1
- package/{lib/types/type-ts-enumeration-member.d.ts → src/types/type-gir-enumeration.ts} +1 -1
- package/src/types/type-gir-function.ts +8 -0
- package/{lib/types/type-gir-interface.d.ts → src/types/type-gir-interface.ts} +1 -1
- package/{lib/types/type-gir-method.d.ts → src/types/type-gir-method.ts} +1 -1
- package/src/types/type-gir-parameter.ts +1 -0
- package/{lib/types/type-gir-property.d.ts → src/types/type-gir-property.ts} +1 -1
- package/src/types/type-gir-variable.ts +1 -0
- package/src/types/type-ts-element.ts +13 -0
- package/{lib/types/type-gir-enumeration.d.ts → src/types/type-ts-enumeration-member.ts} +1 -1
- package/{lib/types/type-ts-function.d.ts → src/types/type-ts-function.ts} +1 -1
- package/{lib/types/type-ts-property.d.ts → src/types/type-ts-property.ts} +1 -1
- package/src/types/user-config-load-result.ts +6 -0
- package/{lib/types/user-config.d.ts → src/types/user-config.ts} +25 -17
- package/src/util.ts +84 -0
- package/src/utils/conflicts/conflict-resolver.ts +122 -0
- package/src/utils/conflicts/function-conflict-detector.ts +139 -0
- package/src/utils/conflicts/index.ts +2 -0
- package/src/utils/conflicts.ts +490 -0
- package/{lib/utils/documentation.js → src/utils/documentation.ts} +25 -22
- package/src/utils/files.ts +71 -0
- package/src/utils/function-type-guards.ts +61 -0
- package/src/utils/generation.ts +69 -0
- package/src/utils/gir-parsing.ts +243 -0
- package/src/utils/girs.ts +113 -0
- package/src/utils/index.ts +14 -0
- package/src/utils/naming.ts +188 -0
- package/{lib/utils/numbers.d.ts → src/utils/numbers.ts} +3 -1
- package/{lib/utils/objects.js → src/utils/objects.ts} +15 -7
- package/src/utils/path.ts +7 -0
- package/src/utils/registry.ts +5 -0
- package/src/utils/strings.ts +134 -0
- package/src/utils/type-resolution.ts +116 -0
- package/src/utils/types.ts +247 -0
- package/src/validators/class.ts +324 -0
- package/src/validators/function-parameters.ts +52 -0
- package/src/validators/interface.ts +20 -0
- package/src/visitor.ts +58 -0
- package/lib/constants.d.ts +0 -25
- package/lib/constants.js +0 -93
- package/lib/constants.js.map +0 -1
- package/lib/dependency-manager.d.ts +0 -151
- package/lib/dependency-manager.js +0 -340
- package/lib/dependency-manager.js.map +0 -1
- package/lib/formatters/default.d.ts +0 -4
- package/lib/formatters/default.js +0 -7
- package/lib/formatters/default.js.map +0 -1
- package/lib/formatters/formatter.d.ts +0 -3
- package/lib/formatters/formatter.js +0 -3
- package/lib/formatters/formatter.js.map +0 -1
- package/lib/formatters/json.d.ts +0 -4
- package/lib/formatters/json.js +0 -7
- package/lib/formatters/json.js.map +0 -1
- package/lib/generators/dts/glib.d.ts +0 -2
- package/lib/generators/dts/glib.js +0 -514
- package/lib/generators/dts/glib.js.map +0 -1
- package/lib/generators/dts/gobject.d.ts +0 -2
- package/lib/generators/dts/gobject.js +0 -117
- package/lib/generators/dts/gobject.js.map +0 -1
- package/lib/generators/dts-inline.d.ts +0 -10
- package/lib/generators/dts-inline.js +0 -57
- package/lib/generators/dts-inline.js.map +0 -1
- package/lib/generators/dts-modules.d.ts +0 -10
- package/lib/generators/dts-modules.js +0 -98
- package/lib/generators/dts-modules.js.map +0 -1
- package/lib/generators/dts.d.ts +0 -45
- package/lib/generators/dts.js +0 -683
- package/lib/generators/dts.js.map +0 -1
- package/lib/generators/generator.d.ts +0 -45
- package/lib/generators/generator.js +0 -9
- package/lib/generators/generator.js.map +0 -1
- package/lib/generators/index.d.ts +0 -5
- package/lib/generators/index.js +0 -6
- package/lib/generators/index.js.map +0 -1
- package/lib/generators/json.d.ts +0 -257
- package/lib/generators/json.js +0 -866
- package/lib/generators/json.js.map +0 -1
- package/lib/generics/clutter.d.ts +0 -41
- package/lib/generics/clutter.js +0 -52
- package/lib/generics/clutter.js.map +0 -1
- package/lib/generics/generify.d.ts +0 -2
- package/lib/generics/generify.js +0 -47
- package/lib/generics/generify.js.map +0 -1
- package/lib/generics/gio.d.ts +0 -7
- package/lib/generics/gio.js +0 -51
- package/lib/generics/gio.js.map +0 -1
- package/lib/generics/glib.d.ts +0 -7
- package/lib/generics/glib.js +0 -18
- package/lib/generics/glib.js.map +0 -1
- package/lib/generics/gtk.d.ts +0 -7
- package/lib/generics/gtk.js +0 -56
- package/lib/generics/gtk.js.map +0 -1
- package/lib/generics/meta.d.ts +0 -36
- package/lib/generics/meta.js +0 -29
- package/lib/generics/meta.js.map +0 -1
- package/lib/generics/st.d.ts +0 -31
- package/lib/generics/st.js +0 -98
- package/lib/generics/st.js.map +0 -1
- package/lib/generics/visitor.d.ts +0 -20
- package/lib/generics/visitor.js +0 -255
- package/lib/generics/visitor.js.map +0 -1
- package/lib/gir/alias.d.ts +0 -24
- package/lib/gir/alias.js +0 -43
- package/lib/gir/alias.js.map +0 -1
- package/lib/gir/base.d.ts +0 -62
- package/lib/gir/base.js +0 -83
- package/lib/gir/base.js.map +0 -1
- package/lib/gir/class.d.ts +0 -228
- package/lib/gir/class.js +0 -1151
- package/lib/gir/class.js.map +0 -1
- package/lib/gir/const.d.ts +0 -25
- package/lib/gir/const.js +0 -43
- package/lib/gir/const.js.map +0 -1
- package/lib/gir/enum.d.ts +0 -45
- package/lib/gir/enum.js +0 -164
- package/lib/gir/enum.js.map +0 -1
- package/lib/gir/function.d.ts +0 -200
- package/lib/gir/function.js +0 -683
- package/lib/gir/function.js.map +0 -1
- package/lib/gir/generics.d.ts +0 -5
- package/lib/gir/generics.js +0 -57
- package/lib/gir/generics.js.map +0 -1
- package/lib/gir/index.d.ts +0 -14
- package/lib/gir/index.js +0 -15
- package/lib/gir/index.js.map +0 -1
- package/lib/gir/namespace.d.ts +0 -21
- package/lib/gir/namespace.js +0 -57
- package/lib/gir/namespace.js.map +0 -1
- package/lib/gir/nodes.d.ts +0 -11
- package/lib/gir/nodes.js +0 -12
- package/lib/gir/nodes.js.map +0 -1
- package/lib/gir/promisify.d.ts +0 -5
- package/lib/gir/promisify.js +0 -158
- package/lib/gir/promisify.js.map +0 -1
- package/lib/gir/property.d.ts +0 -60
- package/lib/gir/property.js +0 -128
- package/lib/gir/property.js.map +0 -1
- package/lib/gir/registry.d.ts +0 -51
- package/lib/gir/registry.js +0 -147
- package/lib/gir/registry.js.map +0 -1
- package/lib/gir/signal.d.ts +0 -36
- package/lib/gir/signal.js +0 -169
- package/lib/gir/signal.js.map +0 -1
- package/lib/gir/util.d.ts +0 -49
- package/lib/gir/util.js +0 -561
- package/lib/gir/util.js.map +0 -1
- package/lib/gir-module.d.ts +0 -104
- package/lib/gir-module.js +0 -584
- package/lib/gir-module.js.map +0 -1
- package/lib/gir.d.ts +0 -254
- package/lib/gir.js +0 -639
- package/lib/gir.js.map +0 -1
- package/lib/index.d.ts +0 -13
- package/lib/index.js +0 -16
- package/lib/index.js.map +0 -1
- package/lib/injections/gee08.d.ts +0 -7
- package/lib/injections/gee08.js +0 -68
- package/lib/injections/gee08.js.map +0 -1
- package/lib/injections/gee1.d.ts +0 -7
- package/lib/injections/gee1.js +0 -28
- package/lib/injections/gee1.js.map +0 -1
- package/lib/injections/gio.d.ts +0 -7
- package/lib/injections/gio.js +0 -563
- package/lib/injections/gio.js.map +0 -1
- package/lib/injections/glib.d.ts +0 -7
- package/lib/injections/glib.js +0 -210
- package/lib/injections/glib.js.map +0 -1
- package/lib/injections/gobject.d.ts +0 -7
- package/lib/injections/gobject.js +0 -594
- package/lib/injections/gobject.js.map +0 -1
- package/lib/injections/gtk4.d.ts +0 -7
- package/lib/injections/gtk4.js +0 -19
- package/lib/injections/gtk4.js.map +0 -1
- package/lib/injections/inject.d.ts +0 -4
- package/lib/injections/inject.js +0 -33
- package/lib/injections/inject.js.map +0 -1
- package/lib/injections/shell.d.ts +0 -20
- package/lib/injections/shell.js +0 -34
- package/lib/injections/shell.js.map +0 -1
- package/lib/injections/tracker1.d.ts +0 -7
- package/lib/injections/tracker1.js +0 -30
- package/lib/injections/tracker1.js.map +0 -1
- package/lib/library-version.d.ts +0 -10
- package/lib/library-version.js +0 -45
- package/lib/library-version.js.map +0 -1
- package/lib/logger.d.ts +0 -36
- package/lib/logger.js +0 -134
- package/lib/logger.js.map +0 -1
- package/lib/messages.d.ts +0 -23
- package/lib/messages.js +0 -39
- package/lib/messages.js.map +0 -1
- package/lib/registry.d.ts +0 -8
- package/lib/registry.js +0 -12
- package/lib/registry.js.map +0 -1
- package/lib/transformation.d.ts +0 -169
- package/lib/transformation.js +0 -393
- package/lib/transformation.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/class-parent.d.ts +0 -13
- 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/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.js +0 -2
- package/lib/types/dependency.js.map +0 -1
- package/lib/types/file-info.js +0 -2
- package/lib/types/file-info.js.map +0 -1
- package/lib/types/format.d.ts +0 -1
- package/lib/types/format.js +0 -2
- package/lib/types/format.js.map +0 -1
- package/lib/types/gir-alias-element.d.ts +0 -4
- 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-bitfield-element.d.ts +0 -6
- package/lib/types/gir-bitfield-element.js +0 -2
- package/lib/types/gir-bitfield-element.js.map +0 -1
- package/lib/types/gir-callable-param-element.d.ts +0 -4
- 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-params.d.ts +0 -7
- package/lib/types/gir-callable-params.js +0 -2
- package/lib/types/gir-callable-params.js.map +0 -1
- package/lib/types/gir-callable-return.d.ts +0 -5
- 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 -6
- 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 -17
- 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 -4
- 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 -6
- package/lib/types/gir-constructor-element.js +0 -2
- package/lib/types/gir-constructor-element.js.map +0 -1
- package/lib/types/gir-enum-element.d.ts +0 -6
- 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 -5
- 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 -6
- package/lib/types/gir-function-element.js +0 -2
- package/lib/types/gir-function-element.js.map +0 -1
- package/lib/types/gir-instance-parameter.d.ts +0 -7
- 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 -16
- 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 -5
- 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 -7
- 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 -15
- 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 -27
- package/lib/types/gir-namespace.js +0 -2
- package/lib/types/gir-namespace.js.map +0 -1
- package/lib/types/gir-property-element.d.ts +0 -4
- 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 -10
- 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 -5
- 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 -10
- package/lib/types/gir-signal.js +0 -2
- package/lib/types/gir-signal.js.map +0 -1
- package/lib/types/gir-type-name.d.ts +0 -2
- package/lib/types/gir-type-name.js +0 -2
- package/lib/types/gir-type-name.js.map +0 -1
- package/lib/types/gir-union-element.d.ts +0 -9
- 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-virtual-method.d.ts +0 -6
- 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 -79
- package/lib/types/index.js +0 -80
- package/lib/types/index.js.map +0 -1
- package/lib/types/inheritance-table.js +0 -2
- package/lib/types/inheritance-table.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/metadata.d.ts +0 -8
- package/lib/types/metadata.js +0 -2
- package/lib/types/metadata.js.map +0 -1
- package/lib/types/options-base.d.ts +0 -4
- package/lib/types/options-base.js +0 -2
- package/lib/types/options-base.js.map +0 -1
- package/lib/types/options-generation.js +0 -2
- package/lib/types/options-generation.js.map +0 -1
- package/lib/types/options-load.d.ts +0 -5
- package/lib/types/options-load.js +0 -2
- package/lib/types/options-load.js.map +0 -1
- package/lib/types/options-transform.d.ts +0 -4
- package/lib/types/options-transform.js +0 -2
- package/lib/types/options-transform.js.map +0 -1
- package/lib/types/output-format.d.ts +0 -1
- package/lib/types/output-format.js +0 -2
- package/lib/types/output-format.js.map +0 -1
- package/lib/types/package-data-parsed.js +0 -2
- package/lib/types/package-data-parsed.js.map +0 -1
- package/lib/types/package-data.js +0 -2
- package/lib/types/package-data.js.map +0 -1
- package/lib/types/package-section-parsed.d.ts +0 -8
- package/lib/types/package-section-parsed.js +0 -2
- package/lib/types/package-section-parsed.js.map +0 -1
- package/lib/types/parsed-gir.d.ts +0 -5
- package/lib/types/parsed-gir.js +0 -2
- package/lib/types/parsed-gir.js.map +0 -1
- package/lib/types/parsed-package-data.d.ts +0 -6
- package/lib/types/parsed-package-data.js +0 -2
- package/lib/types/parsed-package-data.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/property-case.d.ts +0 -1
- package/lib/types/property-case.js +0 -2
- package/lib/types/property-case.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/template-data.d.ts +0 -7
- package/lib/types/template-data.js +0 -2
- package/lib/types/template-data.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 -4
- package/lib/types/transformations.js +0 -2
- package/lib/types/transformations.js.map +0 -1
- package/lib/types/ts-doc-tag.js +0 -2
- package/lib/types/ts-doc-tag.js.map +0 -1
- package/lib/types/ts-doc.js +0 -2
- package/lib/types/ts-doc.js.map +0 -1
- 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.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.js +0 -2
- package/lib/types/type-gir-enumeration-member.js.map +0 -1
- 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.js +0 -2
- package/lib/types/type-gir-interface.js.map +0 -1
- 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.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.js +0 -2
- package/lib/types/type-ts-enumeration-member.js.map +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.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.js +0 -2
- package/lib/types/user-config.js.map +0 -1
- package/lib/util.d.ts +0 -20
- package/lib/util.js +0 -67
- package/lib/util.js.map +0 -1
- package/lib/utils/documentation.d.ts +0 -13
- package/lib/utils/documentation.js.map +0 -1
- package/lib/utils/files.d.ts +0 -21
- package/lib/utils/files.js +0 -62
- package/lib/utils/files.js.map +0 -1
- package/lib/utils/girs.d.ts +0 -45
- package/lib/utils/girs.js +0 -101
- package/lib/utils/girs.js.map +0 -1
- package/lib/utils/index.d.ts +0 -8
- package/lib/utils/index.js +0 -9
- package/lib/utils/index.js.map +0 -1
- package/lib/utils/naming.d.ts +0 -13
- package/lib/utils/naming.js +0 -40
- package/lib/utils/naming.js.map +0 -1
- package/lib/utils/numbers.js +0 -9
- package/lib/utils/numbers.js.map +0 -1
- package/lib/utils/objects.d.ts +0 -136
- package/lib/utils/objects.js.map +0 -1
- package/lib/utils/path.d.ts +0 -1
- package/lib/utils/path.js +0 -7
- package/lib/utils/path.js.map +0 -1
- package/lib/utils/strings.d.ts +0 -74
- package/lib/utils/strings.js +0 -121
- package/lib/utils/strings.js.map +0 -1
- package/lib/validators/class.d.ts +0 -7
- package/lib/validators/class.js +0 -217
- package/lib/validators/class.js.map +0 -1
- package/lib/validators/function-parameters.d.ts +0 -14
- package/lib/validators/function-parameters.js +0 -31
- package/lib/validators/function-parameters.js.map +0 -1
- package/lib/validators/interface.d.ts +0 -5
- package/lib/validators/interface.js +0 -16
- package/lib/validators/interface.js.map +0 -1
- package/lib/visitor.d.ts +0 -35
- package/lib/visitor.js +0 -29
- package/lib/visitor.js.map +0 -1
package/lib/generators/json.js
DELETED
|
@@ -1,866 +0,0 @@
|
|
|
1
|
-
import { Logger } from "../logger.js";
|
|
2
|
-
import { FormatGenerator } from "./generator.js";
|
|
3
|
-
import { IntrospectedBaseClass, IntrospectedRecord, IntrospectedInterface, IntrospectedClass } from "../gir/class.js";
|
|
4
|
-
import { IntrospectedConstant } from "../gir/const.js";
|
|
5
|
-
import { IntrospectedEnum, IntrospectedError } from "../gir/enum.js";
|
|
6
|
-
import { IntrospectedSignalType } from "../gir/signal.js";
|
|
7
|
-
import { IntrospectedFunction, IntrospectedConstructor, IntrospectedFunctionParameter, IntrospectedCallback } from "../gir/function.js";
|
|
8
|
-
import { IntrospectedClassFunction, IntrospectedStaticClassFunction, IntrospectedVirtualClassFunction } from "../gir/function.js";
|
|
9
|
-
import { sanitizeIdentifierName, isInvalid, resolveDirectedType } from "../gir/util.js";
|
|
10
|
-
import { NativeType, AnyType, VoidType, StringType, NumberType, ArrayType, TypeIdentifier, OrType, TupleType, NullableType, ClosureType, AnyFunctionType, TypeConflict } from "../gir.js";
|
|
11
|
-
import { GirDirection } from "@gi.ts/parser";
|
|
12
|
-
import { IntrospectedAlias } from "../gir/alias.js";
|
|
13
|
-
function generateType(type) {
|
|
14
|
-
if (type instanceof TypeIdentifier) {
|
|
15
|
-
return {
|
|
16
|
-
kind: "identifier" /* TypeKind.identifier */,
|
|
17
|
-
name: type.name,
|
|
18
|
-
namespace: type.namespace
|
|
19
|
-
};
|
|
20
|
-
}
|
|
21
|
-
else if (type instanceof NativeType) {
|
|
22
|
-
return {
|
|
23
|
-
kind: "native" /* TypeKind.native */,
|
|
24
|
-
type: type.expression()
|
|
25
|
-
};
|
|
26
|
-
}
|
|
27
|
-
else if (type instanceof ClosureType) {
|
|
28
|
-
return {
|
|
29
|
-
kind: "closure" /* TypeKind.closure */,
|
|
30
|
-
type: generateType(type.type),
|
|
31
|
-
user_data: type.user_data
|
|
32
|
-
};
|
|
33
|
-
}
|
|
34
|
-
else if (type instanceof ArrayType) {
|
|
35
|
-
return {
|
|
36
|
-
kind: "array" /* TypeKind.array */,
|
|
37
|
-
type: generateType(type.type),
|
|
38
|
-
depth: type.arrayDepth
|
|
39
|
-
};
|
|
40
|
-
}
|
|
41
|
-
else if (type instanceof NullableType) {
|
|
42
|
-
return {
|
|
43
|
-
kind: "null" /* TypeKind.nulled */,
|
|
44
|
-
type: generateType(type.type)
|
|
45
|
-
};
|
|
46
|
-
}
|
|
47
|
-
else if (type instanceof TypeConflict) {
|
|
48
|
-
// Type conflicts aren't considered in JSON outputs.
|
|
49
|
-
return generateType(type.type);
|
|
50
|
-
}
|
|
51
|
-
else if (type instanceof TupleType) {
|
|
52
|
-
return {
|
|
53
|
-
kind: "tuple" /* TypeKind.tuple */,
|
|
54
|
-
types: type.types.map(t => generateType(t))
|
|
55
|
-
};
|
|
56
|
-
}
|
|
57
|
-
else if (type instanceof OrType) {
|
|
58
|
-
return {
|
|
59
|
-
kind: "or" /* TypeKind.or */,
|
|
60
|
-
types: type.types.map(t => generateType(t))
|
|
61
|
-
};
|
|
62
|
-
}
|
|
63
|
-
else {
|
|
64
|
-
return {
|
|
65
|
-
kind: "native" /* TypeKind.native */,
|
|
66
|
-
type: "any"
|
|
67
|
-
};
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
function capitalize(str) {
|
|
71
|
-
if (str.length === 0) {
|
|
72
|
-
return "";
|
|
73
|
-
}
|
|
74
|
-
if (str.length === 1) {
|
|
75
|
-
return str[0].toUpperCase();
|
|
76
|
-
}
|
|
77
|
-
return str[0].toUpperCase() + str.substring(1).toLowerCase();
|
|
78
|
-
}
|
|
79
|
-
export class JsonGenerator extends FormatGenerator {
|
|
80
|
-
log;
|
|
81
|
-
constructor(namespace, options) {
|
|
82
|
-
super(namespace, options);
|
|
83
|
-
this.log = new Logger(options.verbose, JsonGenerator.name);
|
|
84
|
-
}
|
|
85
|
-
/**
|
|
86
|
-
* Intelligently reformats # and () references
|
|
87
|
-
* to handle c-prefixes and namespacing.
|
|
88
|
-
*
|
|
89
|
-
* @param doc
|
|
90
|
-
*/
|
|
91
|
-
generateDoc(doc) {
|
|
92
|
-
const { namespace } = this;
|
|
93
|
-
function resolveClass(ns, className) {
|
|
94
|
-
let classes = ns.getMembers(className);
|
|
95
|
-
let plural = false;
|
|
96
|
-
if (classes.length === 0 && className.endsWith("Class")) {
|
|
97
|
-
classes = ns.getMembers(className.slice(0, -5));
|
|
98
|
-
}
|
|
99
|
-
if (classes.length === 0 && className.endsWith("Iface")) {
|
|
100
|
-
classes = ns.getMembers(className.slice(0, -5));
|
|
101
|
-
}
|
|
102
|
-
if (classes.length === 0 && className.endsWith("Interface")) {
|
|
103
|
-
classes = ns.getMembers(className.slice(0, -9));
|
|
104
|
-
}
|
|
105
|
-
if (classes.length === 0 && className.endsWith("s")) {
|
|
106
|
-
plural = true;
|
|
107
|
-
classes = ns.getMembers(className.slice(0, -1));
|
|
108
|
-
}
|
|
109
|
-
return [classes[0] ?? null, plural];
|
|
110
|
-
}
|
|
111
|
-
function formatReference(identifier, member_name, punc) {
|
|
112
|
-
const parts = identifier
|
|
113
|
-
.split(/([A-Z])/)
|
|
114
|
-
.filter(p => p != "")
|
|
115
|
-
.reduce((prev, next) => {
|
|
116
|
-
if (next.toUpperCase() === next) {
|
|
117
|
-
prev.push(`${next}`);
|
|
118
|
-
}
|
|
119
|
-
else {
|
|
120
|
-
const lastCapital = prev.pop();
|
|
121
|
-
prev.push(`${lastCapital}${next}`);
|
|
122
|
-
}
|
|
123
|
-
return prev;
|
|
124
|
-
}, []);
|
|
125
|
-
const [base_part] = parts;
|
|
126
|
-
const [, , namespaces, className] = parts.slice(1).reduce(([underscore, camel, ns, selected], next) => {
|
|
127
|
-
const next_underscore = [underscore, next.toLowerCase()].join("_");
|
|
128
|
-
const namespaces = namespace.getImportsForCPrefix(next_underscore);
|
|
129
|
-
const nextCamel = camel + capitalize(next);
|
|
130
|
-
if (namespaces.length > 0) {
|
|
131
|
-
return [next_underscore, nextCamel, namespaces, capitalize(next)];
|
|
132
|
-
}
|
|
133
|
-
return [next_underscore, nextCamel, ns, selected + capitalize(next)];
|
|
134
|
-
}, [
|
|
135
|
-
base_part.toLowerCase(),
|
|
136
|
-
capitalize(base_part),
|
|
137
|
-
namespace.getImportsForCPrefix(base_part.toLowerCase()),
|
|
138
|
-
""
|
|
139
|
-
]);
|
|
140
|
-
let ns = namespaces.find(n => n.hasSymbol(className));
|
|
141
|
-
if (!ns) {
|
|
142
|
-
ns = namespaces.find(n => {
|
|
143
|
-
const [c] = resolveClass(n, className);
|
|
144
|
-
return c != null;
|
|
145
|
-
});
|
|
146
|
-
}
|
|
147
|
-
if (ns) {
|
|
148
|
-
const is_prop = punc === ":";
|
|
149
|
-
const modified_name = is_prop ? member_name.replace(/[\-]/g, "_") : member_name;
|
|
150
|
-
const [clazz, plural] = resolveClass(ns, className);
|
|
151
|
-
if (clazz instanceof IntrospectedBaseClass || clazz instanceof IntrospectedEnum) {
|
|
152
|
-
const r = `#${plural ? "{" : ""}${ns.namespace}.${clazz.name}${punc ? `${punc}${modified_name}` : ""}${plural ? "}s" : ""}`;
|
|
153
|
-
return r;
|
|
154
|
-
}
|
|
155
|
-
return `#${ns.namespace}${punc ? ` (${punc}${modified_name})` : ""}`;
|
|
156
|
-
}
|
|
157
|
-
else {
|
|
158
|
-
return null;
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
function formatFunctionReference(func, upper = false) {
|
|
162
|
-
// namespace_class_do_thing()
|
|
163
|
-
const parts = func.toLowerCase().split("_");
|
|
164
|
-
// ['namespace', 'class', 'do', 'thing']
|
|
165
|
-
const [base_part] = parts;
|
|
166
|
-
// ['namespace']
|
|
167
|
-
const namespaceBase = [
|
|
168
|
-
base_part.toLowerCase(),
|
|
169
|
-
capitalize(base_part),
|
|
170
|
-
namespace.getImportsForCPrefix(base_part.toLowerCase()),
|
|
171
|
-
0
|
|
172
|
-
];
|
|
173
|
-
// ['namespace', 'Namespace', { Namespace }, -1]
|
|
174
|
-
const [, , namespaces, i] = parts.slice(1).reduce(([prev, camel, currentNamespaces, selected], next, i) => {
|
|
175
|
-
const underscore = [prev, next.toLowerCase()].join("_");
|
|
176
|
-
const namespaces = namespace.getImportsForCPrefix(underscore);
|
|
177
|
-
const identifier = camel + capitalize(next);
|
|
178
|
-
// We've found namespace(s) which matches the c_prefix
|
|
179
|
-
if (namespaces.length > 0) {
|
|
180
|
-
return [underscore, identifier, namespaces, i];
|
|
181
|
-
}
|
|
182
|
-
return [underscore, identifier, currentNamespaces, selected];
|
|
183
|
-
}, namespaceBase);
|
|
184
|
-
// If no namespaces are found for the function's c_prefix, we return the original reference.
|
|
185
|
-
if (namespaces.length === 0) {
|
|
186
|
-
return null;
|
|
187
|
-
}
|
|
188
|
-
// ['class', 'do', 'thing']
|
|
189
|
-
const nameParts = parts.slice(i + 1);
|
|
190
|
-
// 'class_do_thing'
|
|
191
|
-
const functionName = nameParts.join("_");
|
|
192
|
-
const functionNamespace = namespaces.find(n => n.hasSymbol(functionName.toLowerCase()));
|
|
193
|
-
const constNamespace = namespaces.find(n => n.hasSymbol(functionName.toUpperCase()));
|
|
194
|
-
const enumNamespace = namespaces.find(n => n.enum_constants.has(func.toUpperCase()));
|
|
195
|
-
if (functionNamespace) {
|
|
196
|
-
const [member = null] = functionNamespace.getMembers(functionName.toLowerCase());
|
|
197
|
-
if (member instanceof IntrospectedFunction) {
|
|
198
|
-
return `${functionNamespace.namespace}.${member.name}`;
|
|
199
|
-
}
|
|
200
|
-
return null;
|
|
201
|
-
}
|
|
202
|
-
else if (constNamespace) {
|
|
203
|
-
const [member = null] = constNamespace.getMembers(functionName.toUpperCase());
|
|
204
|
-
if (member instanceof IntrospectedConstant) {
|
|
205
|
-
return `${constNamespace.namespace}.${member.name}`;
|
|
206
|
-
}
|
|
207
|
-
return null;
|
|
208
|
-
}
|
|
209
|
-
else if (enumNamespace) {
|
|
210
|
-
const constantInfo = enumNamespace.enum_constants.get(func.toUpperCase());
|
|
211
|
-
if (constantInfo) {
|
|
212
|
-
const [enumName, memberName] = constantInfo;
|
|
213
|
-
const [klass = null] = enumNamespace.getMembers(enumName);
|
|
214
|
-
if (klass instanceof IntrospectedEnum) {
|
|
215
|
-
return `${enumNamespace.namespace}.${klass.name}.${memberName.toUpperCase()}`;
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
return null;
|
|
219
|
-
}
|
|
220
|
-
else {
|
|
221
|
-
// ['class', 'do', 'thing']
|
|
222
|
-
const { selectedClassName, resolvedNamespace, selectedIndex } = parts.slice(i + 1).reduce(({ className, selectedClassName, resolvedNamespace, selectedIndex }, next, i) => {
|
|
223
|
-
// Class
|
|
224
|
-
const identifier = `${className}${capitalize(next)}`;
|
|
225
|
-
const withSymbol = namespaces.find(n => n.hasSymbol(identifier));
|
|
226
|
-
if (withSymbol) {
|
|
227
|
-
// { className: Class, resolvedNamespace: {Namespace}, selectedIndex: 0 }
|
|
228
|
-
return {
|
|
229
|
-
className: identifier,
|
|
230
|
-
selectedClassName: identifier,
|
|
231
|
-
resolvedNamespace: withSymbol,
|
|
232
|
-
selectedIndex: i
|
|
233
|
-
};
|
|
234
|
-
}
|
|
235
|
-
return { className: identifier, selectedClassName, resolvedNamespace, selectedIndex };
|
|
236
|
-
}, {
|
|
237
|
-
className: "",
|
|
238
|
-
selectedClassName: "",
|
|
239
|
-
resolvedNamespace: null,
|
|
240
|
-
selectedIndex: -1
|
|
241
|
-
});
|
|
242
|
-
if (resolvedNamespace && selectedIndex >= 0) {
|
|
243
|
-
const nextIndex = i + selectedIndex + 1 /* (slice omits first index) */ + 1; /* (the next index) */
|
|
244
|
-
const functionName = parts.slice(nextIndex).join("_");
|
|
245
|
-
const [klass] = resolveClass(resolvedNamespace, selectedClassName);
|
|
246
|
-
if (klass instanceof IntrospectedBaseClass || klass instanceof IntrospectedEnum) {
|
|
247
|
-
return `${resolvedNamespace.namespace}.${klass.name}.${upper ? functionName.toUpperCase() : functionName}`;
|
|
248
|
-
}
|
|
249
|
-
return `${resolvedNamespace.namespace}.${selectedClassName}.${upper ? functionName.toUpperCase() : functionName}`;
|
|
250
|
-
}
|
|
251
|
-
}
|
|
252
|
-
return null;
|
|
253
|
-
}
|
|
254
|
-
return `${doc}`
|
|
255
|
-
.replace(/[#]{0,1}([A-Z][A-z]+)\.([a-z_]+)\(\)/g, (original, identifier, member_name) => {
|
|
256
|
-
const resolved = formatReference(identifier, member_name, ".");
|
|
257
|
-
return resolved != null ? `${resolved}()` : original;
|
|
258
|
-
})
|
|
259
|
-
.replace(/#([A-Z][A-z]*)(([:]{1,2})([a-z\-]+)){0,1}/g, (original, identifier, _, punc, member_name) => {
|
|
260
|
-
const resolved = formatReference(identifier, member_name, punc);
|
|
261
|
-
return resolved != null ? resolved : original;
|
|
262
|
-
})
|
|
263
|
-
.replace(/([A-Z][A-z]*)(([:]{1,2})([a-z\-]+))/g, (original, identifier, _, punc, member_name) => {
|
|
264
|
-
const resolved = formatReference(identifier, member_name, punc);
|
|
265
|
-
return resolved != null ? resolved : original;
|
|
266
|
-
})
|
|
267
|
-
.replace(/(\s)([a-z_]+)\(\)/g, (original, w, func) => {
|
|
268
|
-
const resolved = formatFunctionReference(func);
|
|
269
|
-
return resolved != null ? `${w}${resolved}()` : original;
|
|
270
|
-
})
|
|
271
|
-
.replace(/%([A-Z_]+)/g, (original, identifier) => {
|
|
272
|
-
const resolved = formatFunctionReference(identifier.toLowerCase(), true);
|
|
273
|
-
return resolved != null ? `%${resolved}` : original;
|
|
274
|
-
})
|
|
275
|
-
.replace(/#([A-Z_]+)/g, (original, identifier) => {
|
|
276
|
-
const resolved = formatFunctionReference(identifier.toLowerCase(), true);
|
|
277
|
-
return resolved != null ? `#${resolved}` : original;
|
|
278
|
-
});
|
|
279
|
-
}
|
|
280
|
-
generateMetadata(metadata) {
|
|
281
|
-
return { ...metadata };
|
|
282
|
-
}
|
|
283
|
-
generateParameters(parameters) {
|
|
284
|
-
const { namespace, options } = this;
|
|
285
|
-
return parameters.map(p => ({
|
|
286
|
-
kind: "parameter" /* NodeKind.parameter */,
|
|
287
|
-
direction: p.direction,
|
|
288
|
-
optional: p.isOptional,
|
|
289
|
-
varargs: p.isVarArgs,
|
|
290
|
-
name: p.name,
|
|
291
|
-
resoleNames: p.resolve_names,
|
|
292
|
-
type: generateType(p.type.resolve(namespace, options)),
|
|
293
|
-
...this._generateDocAndMetadata(p)
|
|
294
|
-
}));
|
|
295
|
-
}
|
|
296
|
-
generateCallbackType(node) {
|
|
297
|
-
return [{}, {}];
|
|
298
|
-
}
|
|
299
|
-
generateCallback(node) {
|
|
300
|
-
const { namespace, options } = this;
|
|
301
|
-
const parameters = this.generateParameters(node.parameters);
|
|
302
|
-
return {
|
|
303
|
-
kind: "callback" /* NodeKind.callback */,
|
|
304
|
-
name: node.name,
|
|
305
|
-
type: this.generateCallbackType(node),
|
|
306
|
-
parameters,
|
|
307
|
-
returnType: generateType(node.return().resolve(namespace, options)),
|
|
308
|
-
...this._generateDocAndMetadata(node)
|
|
309
|
-
};
|
|
310
|
-
}
|
|
311
|
-
generateClassCallback(node) {
|
|
312
|
-
const { namespace, options } = this;
|
|
313
|
-
const parameters = this.generateParameters(node.parameters);
|
|
314
|
-
return {
|
|
315
|
-
kind: "callback" /* NodeKind.callback */,
|
|
316
|
-
name: node.name,
|
|
317
|
-
type: this.generateCallbackType(node),
|
|
318
|
-
parameters,
|
|
319
|
-
returnType: generateType(node.return().resolve(namespace, options)),
|
|
320
|
-
...this._generateDocAndMetadata(node)
|
|
321
|
-
};
|
|
322
|
-
}
|
|
323
|
-
generateReturn(return_type, output_parameters) {
|
|
324
|
-
const { namespace, options } = this;
|
|
325
|
-
const type = return_type.resolve(namespace, options);
|
|
326
|
-
if (output_parameters.length > 0) {
|
|
327
|
-
const exclude_first = type.equals(VoidType);
|
|
328
|
-
const returns = [
|
|
329
|
-
...(exclude_first ? [] : [type]),
|
|
330
|
-
...output_parameters.map(op => op.type.resolve(namespace, options))
|
|
331
|
-
];
|
|
332
|
-
return returns.map(r => generateType(r));
|
|
333
|
-
}
|
|
334
|
-
return generateType(type);
|
|
335
|
-
}
|
|
336
|
-
generateEnum(node) {
|
|
337
|
-
return {
|
|
338
|
-
kind: "enum" /* NodeKind.enum */,
|
|
339
|
-
name: node.name,
|
|
340
|
-
members: Array.from(node.members.values()).map(member => member.asString(this)),
|
|
341
|
-
...this._generateDocAndMetadata(node)
|
|
342
|
-
};
|
|
343
|
-
}
|
|
344
|
-
generateError(node) {
|
|
345
|
-
const { namespace } = this;
|
|
346
|
-
const clazz = node.asClass();
|
|
347
|
-
clazz.members = [];
|
|
348
|
-
clazz.members.push(...Array.from(node.functions.values()));
|
|
349
|
-
const GLib = namespace.assertInstalledImport("GLib");
|
|
350
|
-
const GLibError = GLib.assertClass("Error");
|
|
351
|
-
clazz.superType = GLibError.getType();
|
|
352
|
-
// Manually construct a GLib.Error constructor.
|
|
353
|
-
clazz.mainConstructor = new IntrospectedConstructor({
|
|
354
|
-
name: "new",
|
|
355
|
-
parent: clazz,
|
|
356
|
-
parameters: [
|
|
357
|
-
new IntrospectedFunctionParameter({
|
|
358
|
-
name: "options",
|
|
359
|
-
type: NativeType.of("{ message: string, code: number}"),
|
|
360
|
-
direction: GirDirection.In
|
|
361
|
-
})
|
|
362
|
-
],
|
|
363
|
-
return_type: clazz.getType()
|
|
364
|
-
});
|
|
365
|
-
return {
|
|
366
|
-
...clazz.asString(this),
|
|
367
|
-
kind: "error" /* NodeKind.error */
|
|
368
|
-
};
|
|
369
|
-
}
|
|
370
|
-
_generateDocAndMetadata(node) {
|
|
371
|
-
const { options } = this;
|
|
372
|
-
if (!options.noComments) {
|
|
373
|
-
return {
|
|
374
|
-
private: node.isPrivate,
|
|
375
|
-
doc: this.generateDoc(node.doc ?? "") ?? null,
|
|
376
|
-
metadata: this.generateMetadata(node.metadata ?? {}) ?? null
|
|
377
|
-
};
|
|
378
|
-
}
|
|
379
|
-
return {
|
|
380
|
-
private: false,
|
|
381
|
-
doc: null,
|
|
382
|
-
metadata: null
|
|
383
|
-
};
|
|
384
|
-
}
|
|
385
|
-
generateConst(node) {
|
|
386
|
-
const { namespace, options } = this;
|
|
387
|
-
return {
|
|
388
|
-
kind: "constant" /* NodeKind.constant */,
|
|
389
|
-
name: node.name,
|
|
390
|
-
type: generateType(node.type.resolve(namespace, options)),
|
|
391
|
-
...this._generateDocAndMetadata(node)
|
|
392
|
-
};
|
|
393
|
-
}
|
|
394
|
-
implements(node) {
|
|
395
|
-
const { namespace, options } = this;
|
|
396
|
-
if (node.interfaces.length > 0) {
|
|
397
|
-
return node.interfaces
|
|
398
|
-
.map(i => i.resolveIdentifier(namespace, options))
|
|
399
|
-
.filter((i) => i != null);
|
|
400
|
-
}
|
|
401
|
-
return [];
|
|
402
|
-
}
|
|
403
|
-
extends(node) {
|
|
404
|
-
const { namespace: ns, options } = this;
|
|
405
|
-
if (node.superType) {
|
|
406
|
-
return node.superType.resolveIdentifier(ns, options);
|
|
407
|
-
}
|
|
408
|
-
return null;
|
|
409
|
-
}
|
|
410
|
-
generateInterface(node) {
|
|
411
|
-
const { namespace } = this;
|
|
412
|
-
// If an interface does not list a prerequisite type, we fill it with GObject.Object
|
|
413
|
-
if (node.superType == null) {
|
|
414
|
-
const gobject = namespace.assertInstalledImport("GObject");
|
|
415
|
-
// TODO Optimize GObject.Object
|
|
416
|
-
if (!gobject) {
|
|
417
|
-
throw new Error("GObject not generated, all interfaces extend from GObject.Object!");
|
|
418
|
-
}
|
|
419
|
-
const GObject = gobject.getClass("Object");
|
|
420
|
-
if (!GObject) {
|
|
421
|
-
throw new Error(`GObject.Object could not be found while generating ${node.namespace.namespace}.${node.name}`);
|
|
422
|
-
}
|
|
423
|
-
node.superType = GObject.getType();
|
|
424
|
-
}
|
|
425
|
-
const { name } = node;
|
|
426
|
-
const Extends = this.extends(node);
|
|
427
|
-
const Properties = node.props.map(v => v && v.asString(this));
|
|
428
|
-
const Methods = node.members
|
|
429
|
-
.filter(m => !(m instanceof IntrospectedStaticClassFunction) && !(m instanceof IntrospectedVirtualClassFunction))
|
|
430
|
-
.map(v => v && v.asString(this));
|
|
431
|
-
const StaticMethods = node.members
|
|
432
|
-
.filter((m) => m instanceof IntrospectedStaticClassFunction)
|
|
433
|
-
.map(v => v && v.asString(this));
|
|
434
|
-
const VirtualMethods = node.members
|
|
435
|
-
.filter((m) => m instanceof IntrospectedVirtualClassFunction)
|
|
436
|
-
.map(v => v && v.asString(this));
|
|
437
|
-
return {
|
|
438
|
-
kind: "interface" /* NodeKind.interface */,
|
|
439
|
-
name,
|
|
440
|
-
type: generateType(node.getType()),
|
|
441
|
-
extends: Extends ? generateType(Extends) : null,
|
|
442
|
-
props: Properties,
|
|
443
|
-
methods: Methods,
|
|
444
|
-
staticMethods: StaticMethods,
|
|
445
|
-
virtualMethods: VirtualMethods,
|
|
446
|
-
...this._generateDocAndMetadata(node)
|
|
447
|
-
};
|
|
448
|
-
}
|
|
449
|
-
generateRecord(node) {
|
|
450
|
-
const { name } = node;
|
|
451
|
-
const Extends = this.extends(node);
|
|
452
|
-
const Properties = node.props.map(v => v && v.asString(this));
|
|
453
|
-
const Fields = node.fields.map(v => v && v.asString(this));
|
|
454
|
-
const Constructors = node.constructors.map(v => v && this.generateConstructorFunction(v));
|
|
455
|
-
const Methods = node.members
|
|
456
|
-
.filter(m => !(m instanceof IntrospectedStaticClassFunction) && !(m instanceof IntrospectedVirtualClassFunction))
|
|
457
|
-
.map(v => v && v.asString(this));
|
|
458
|
-
const StaticMethods = node.members
|
|
459
|
-
.filter((m) => m instanceof IntrospectedStaticClassFunction)
|
|
460
|
-
.map(v => v && v.asString(this));
|
|
461
|
-
const VirtualMethods = node.members
|
|
462
|
-
.filter((m) => m instanceof IntrospectedVirtualClassFunction)
|
|
463
|
-
.map(v => v && v.asString(this));
|
|
464
|
-
const Callbacks = node.callbacks.map(c => c && c.asString(this));
|
|
465
|
-
return {
|
|
466
|
-
kind: "record" /* NodeKind.record */,
|
|
467
|
-
name,
|
|
468
|
-
type: generateType(node.getType()),
|
|
469
|
-
mainConstructor: node.mainConstructor?.asString(this) ?? null,
|
|
470
|
-
extends: Extends ? generateType(Extends) : null,
|
|
471
|
-
implements: [],
|
|
472
|
-
props: Properties,
|
|
473
|
-
fields: Fields,
|
|
474
|
-
constructors: Constructors,
|
|
475
|
-
methods: Methods,
|
|
476
|
-
staticMethods: StaticMethods,
|
|
477
|
-
virtualMethods: VirtualMethods,
|
|
478
|
-
callbacks: Callbacks,
|
|
479
|
-
...this._generateDocAndMetadata(node)
|
|
480
|
-
};
|
|
481
|
-
}
|
|
482
|
-
generateClass(node) {
|
|
483
|
-
const Extends = this.extends(node);
|
|
484
|
-
const Implements = this.implements(node);
|
|
485
|
-
let MainConstructor = null;
|
|
486
|
-
const ConstructorProps = node.props.map(v => this.generateProperty(v, true));
|
|
487
|
-
if (node.mainConstructor) {
|
|
488
|
-
MainConstructor = this.generateConstructor(node.mainConstructor);
|
|
489
|
-
}
|
|
490
|
-
else {
|
|
491
|
-
MainConstructor = {
|
|
492
|
-
kind: "properties_constructor" /* NodeKind.propertiesConstructor */,
|
|
493
|
-
name: "new",
|
|
494
|
-
private: false,
|
|
495
|
-
properties: ConstructorProps.map(p => ({
|
|
496
|
-
kind: "parameter" /* NodeKind.parameter */,
|
|
497
|
-
private: p.private,
|
|
498
|
-
varargs: false,
|
|
499
|
-
name: p.name,
|
|
500
|
-
type: p.type,
|
|
501
|
-
doc: p.doc,
|
|
502
|
-
metadata: p.metadata,
|
|
503
|
-
optional: true
|
|
504
|
-
})),
|
|
505
|
-
doc: null,
|
|
506
|
-
metadata: null
|
|
507
|
-
};
|
|
508
|
-
}
|
|
509
|
-
const Properties = node.props.map(v => v.asString(this));
|
|
510
|
-
const Fields = node.fields.map(v => v.asString(this));
|
|
511
|
-
const Constructors = node.constructors.map(v => this.generateConstructorFunction(v));
|
|
512
|
-
const Methods = node.members
|
|
513
|
-
.filter(m => !(m instanceof IntrospectedStaticClassFunction) && !(m instanceof IntrospectedVirtualClassFunction))
|
|
514
|
-
.map(v => v && v.asString(this));
|
|
515
|
-
const StaticMethods = node.members
|
|
516
|
-
.filter((m) => m instanceof IntrospectedStaticClassFunction)
|
|
517
|
-
.map(v => v && v.asString(this));
|
|
518
|
-
const VirtualMethods = node.members
|
|
519
|
-
.filter((m) => m instanceof IntrospectedVirtualClassFunction)
|
|
520
|
-
.map(v => v && v.asString(this));
|
|
521
|
-
// TODO Move these to a cleaner place.
|
|
522
|
-
const Connect = new IntrospectedClassFunction({
|
|
523
|
-
name: "connect",
|
|
524
|
-
parent: node,
|
|
525
|
-
parameters: [
|
|
526
|
-
new IntrospectedFunctionParameter({
|
|
527
|
-
name: "id",
|
|
528
|
-
type: StringType,
|
|
529
|
-
direction: GirDirection.In
|
|
530
|
-
}),
|
|
531
|
-
new IntrospectedFunctionParameter({
|
|
532
|
-
name: "callback",
|
|
533
|
-
type: AnyFunctionType,
|
|
534
|
-
direction: GirDirection.In
|
|
535
|
-
})
|
|
536
|
-
],
|
|
537
|
-
return_type: NumberType
|
|
538
|
-
});
|
|
539
|
-
const ConnectAfter = new IntrospectedClassFunction({
|
|
540
|
-
name: "connect_after",
|
|
541
|
-
parent: node,
|
|
542
|
-
parameters: [
|
|
543
|
-
new IntrospectedFunctionParameter({
|
|
544
|
-
name: "id",
|
|
545
|
-
type: StringType,
|
|
546
|
-
direction: GirDirection.In
|
|
547
|
-
}),
|
|
548
|
-
new IntrospectedFunctionParameter({
|
|
549
|
-
name: "callback",
|
|
550
|
-
type: AnyFunctionType,
|
|
551
|
-
direction: GirDirection.In
|
|
552
|
-
})
|
|
553
|
-
],
|
|
554
|
-
return_type: NumberType
|
|
555
|
-
});
|
|
556
|
-
const Emit = new IntrospectedClassFunction({
|
|
557
|
-
name: "emit",
|
|
558
|
-
parent: node,
|
|
559
|
-
parameters: [
|
|
560
|
-
new IntrospectedFunctionParameter({
|
|
561
|
-
name: "id",
|
|
562
|
-
type: StringType,
|
|
563
|
-
direction: GirDirection.In
|
|
564
|
-
}),
|
|
565
|
-
new IntrospectedFunctionParameter({
|
|
566
|
-
name: "args",
|
|
567
|
-
isVarArgs: true,
|
|
568
|
-
type: new ArrayType(AnyType),
|
|
569
|
-
direction: GirDirection.In
|
|
570
|
-
})
|
|
571
|
-
],
|
|
572
|
-
return_type: VoidType
|
|
573
|
-
});
|
|
574
|
-
const default_signals = [];
|
|
575
|
-
let hasConnect, hasConnectAfter, hasEmit;
|
|
576
|
-
if (node.signals.length > 0) {
|
|
577
|
-
hasConnect = node.members.some(m => m.name === "connect");
|
|
578
|
-
hasConnectAfter = node.members.some(m => m.name === "connect_after");
|
|
579
|
-
hasEmit = node.members.some(m => m.name === "emit");
|
|
580
|
-
if (!hasConnect) {
|
|
581
|
-
default_signals.push(Connect);
|
|
582
|
-
}
|
|
583
|
-
if (!hasConnectAfter) {
|
|
584
|
-
default_signals.push(ConnectAfter);
|
|
585
|
-
}
|
|
586
|
-
if (!hasEmit) {
|
|
587
|
-
default_signals.push(Emit);
|
|
588
|
-
}
|
|
589
|
-
hasConnect = !default_signals.some(s => s.name === "connect");
|
|
590
|
-
hasConnectAfter = !default_signals.some(s => s.name === "connect_after");
|
|
591
|
-
hasEmit = !default_signals.some(s => s.name === "emit");
|
|
592
|
-
}
|
|
593
|
-
const SignalsList = [
|
|
594
|
-
...default_signals.map(s => s.asString(this)),
|
|
595
|
-
...node.signals
|
|
596
|
-
.map(s => {
|
|
597
|
-
const methods = [];
|
|
598
|
-
if (!hasConnect)
|
|
599
|
-
methods.push(s.asString(this, IntrospectedSignalType.CONNECT));
|
|
600
|
-
if (!hasConnectAfter)
|
|
601
|
-
methods.push(s.asString(this, IntrospectedSignalType.CONNECT_AFTER));
|
|
602
|
-
if (!hasEmit)
|
|
603
|
-
methods.push(s.asString(this, IntrospectedSignalType.EMIT));
|
|
604
|
-
return methods;
|
|
605
|
-
})
|
|
606
|
-
.flat()
|
|
607
|
-
];
|
|
608
|
-
const Signals = SignalsList;
|
|
609
|
-
return {
|
|
610
|
-
kind: "class" /* NodeKind.class */,
|
|
611
|
-
abstract: node.isAbstract,
|
|
612
|
-
type: generateType(node.getType()),
|
|
613
|
-
name: node.name,
|
|
614
|
-
mainConstructor: MainConstructor,
|
|
615
|
-
signals: Signals,
|
|
616
|
-
extends: Extends ? generateType(Extends) : null,
|
|
617
|
-
implements: Implements.map(i => generateType(i)),
|
|
618
|
-
props: Properties,
|
|
619
|
-
fields: Fields,
|
|
620
|
-
constructors: Constructors,
|
|
621
|
-
methods: Methods,
|
|
622
|
-
staticMethods: StaticMethods,
|
|
623
|
-
virtualMethods: VirtualMethods,
|
|
624
|
-
...this._generateDocAndMetadata(node)
|
|
625
|
-
};
|
|
626
|
-
}
|
|
627
|
-
generateField(node) {
|
|
628
|
-
const { namespace, options } = this;
|
|
629
|
-
const { name, computed } = node;
|
|
630
|
-
const invalid = isInvalid(name);
|
|
631
|
-
const Static = node.isStatic;
|
|
632
|
-
const ReadOnly = node.writable;
|
|
633
|
-
return {
|
|
634
|
-
kind: "field" /* NodeKind.field */,
|
|
635
|
-
readonly: ReadOnly,
|
|
636
|
-
static: Static,
|
|
637
|
-
computed,
|
|
638
|
-
type: generateType(node.type.resolve(namespace, options)),
|
|
639
|
-
name: invalid ? `"${name}"` : name,
|
|
640
|
-
...this._generateDocAndMetadata(node)
|
|
641
|
-
};
|
|
642
|
-
}
|
|
643
|
-
generateProperty(node, construct = false) {
|
|
644
|
-
const { namespace, options } = this;
|
|
645
|
-
const invalid = isInvalid(node.name);
|
|
646
|
-
const ReadOnly = node.writable || construct;
|
|
647
|
-
const Name = invalid ? `"${node.name}"` : node.name;
|
|
648
|
-
const Type = generateType(node.type.resolve(namespace, options));
|
|
649
|
-
return {
|
|
650
|
-
kind: "prop" /* NodeKind.prop */,
|
|
651
|
-
readonly: ReadOnly,
|
|
652
|
-
constructOnly: node.constructOnly,
|
|
653
|
-
readable: node.readable,
|
|
654
|
-
writable: node.writable,
|
|
655
|
-
static: false,
|
|
656
|
-
type: Type,
|
|
657
|
-
name: Name,
|
|
658
|
-
...this._generateDocAndMetadata(node)
|
|
659
|
-
};
|
|
660
|
-
}
|
|
661
|
-
generateSignal(node, type = IntrospectedSignalType.CONNECT) {
|
|
662
|
-
switch (type) {
|
|
663
|
-
case IntrospectedSignalType.CONNECT:
|
|
664
|
-
return node.asConnect(false).asString(this);
|
|
665
|
-
case IntrospectedSignalType.CONNECT_AFTER:
|
|
666
|
-
return node.asConnect(true).asString(this);
|
|
667
|
-
case IntrospectedSignalType.EMIT:
|
|
668
|
-
return node.asEmit().asString(this);
|
|
669
|
-
}
|
|
670
|
-
}
|
|
671
|
-
generateEnumMember(node) {
|
|
672
|
-
const invalid = isInvalid(node.name);
|
|
673
|
-
let enumMember;
|
|
674
|
-
if (node.value != null &&
|
|
675
|
-
!Number.isNaN(Number.parseInt(node.value, 10)) &&
|
|
676
|
-
Number.isNaN(Number.parseInt(node.name, 10)) &&
|
|
677
|
-
node.name !== "NaN") {
|
|
678
|
-
enumMember = { name: invalid ? `"${node.name}"` : `${node.name}`, value: `${node.value}` };
|
|
679
|
-
}
|
|
680
|
-
else {
|
|
681
|
-
enumMember = { name: invalid ? `"${node.name}"` : `${node.name}`, value: null };
|
|
682
|
-
}
|
|
683
|
-
return {
|
|
684
|
-
kind: "enum_member" /* NodeKind.enumMember */,
|
|
685
|
-
...enumMember,
|
|
686
|
-
...this._generateDocAndMetadata(node)
|
|
687
|
-
};
|
|
688
|
-
}
|
|
689
|
-
generateParameter(node) {
|
|
690
|
-
const { namespace, options } = this;
|
|
691
|
-
const type = generateType(resolveDirectedType(node.type, node.direction)?.resolve(namespace, options) ??
|
|
692
|
-
node.type.resolve(namespace, options));
|
|
693
|
-
return {
|
|
694
|
-
kind: "parameter" /* NodeKind.parameter */,
|
|
695
|
-
name: node.name,
|
|
696
|
-
type,
|
|
697
|
-
varargs: node.isVarArgs,
|
|
698
|
-
optional: node.isOptional,
|
|
699
|
-
...this._generateDocAndMetadata(node)
|
|
700
|
-
};
|
|
701
|
-
}
|
|
702
|
-
generateFunction(node) {
|
|
703
|
-
const { namespace } = this;
|
|
704
|
-
// Register our identifier with the sanitized identifiers.
|
|
705
|
-
// We avoid doing this in fromXML because other class-level function classes
|
|
706
|
-
// depends on that code.
|
|
707
|
-
sanitizeIdentifierName(namespace.namespace, node.raw_name);
|
|
708
|
-
const Parameters = this.generateParameters(node.parameters);
|
|
709
|
-
const ReturnType = this.generateReturn(node.return(), node.output_parameters);
|
|
710
|
-
return {
|
|
711
|
-
kind: "function" /* NodeKind.function */,
|
|
712
|
-
name: node.name,
|
|
713
|
-
parameters: Parameters,
|
|
714
|
-
returnType: ReturnType,
|
|
715
|
-
...this._generateDocAndMetadata(node)
|
|
716
|
-
};
|
|
717
|
-
}
|
|
718
|
-
generateConstructorFunction(node) {
|
|
719
|
-
const { namespace, options } = this;
|
|
720
|
-
const Parameters = this.generateParameters(node.parameters);
|
|
721
|
-
return {
|
|
722
|
-
kind: "class_function" /* NodeKind.classFunction */,
|
|
723
|
-
static: true,
|
|
724
|
-
name: node.name,
|
|
725
|
-
parameters: Parameters,
|
|
726
|
-
returnType: generateType(node.return().resolve(namespace, options)),
|
|
727
|
-
...this._generateDocAndMetadata(node)
|
|
728
|
-
};
|
|
729
|
-
}
|
|
730
|
-
generateConstructor(node) {
|
|
731
|
-
return {
|
|
732
|
-
name: node.name,
|
|
733
|
-
kind: "constructor" /* NodeKind.constructor */,
|
|
734
|
-
parameters: this.generateParameters(node.parameters),
|
|
735
|
-
...this._generateDocAndMetadata(node)
|
|
736
|
-
};
|
|
737
|
-
}
|
|
738
|
-
generateDirectAllocationConstructor(node) {
|
|
739
|
-
return {
|
|
740
|
-
name: node.name,
|
|
741
|
-
kind: "constructor" /* NodeKind.constructor */,
|
|
742
|
-
parameters: this.generateParameters(node.parameters),
|
|
743
|
-
...this._generateDocAndMetadata(node)
|
|
744
|
-
};
|
|
745
|
-
}
|
|
746
|
-
generateClassFunction(node) {
|
|
747
|
-
const parameters = node.parameters.map(p => this.generateParameter(p));
|
|
748
|
-
const output_parameters = node.output_parameters;
|
|
749
|
-
const return_type = node.return();
|
|
750
|
-
const ReturnType = this.generateReturn(return_type, output_parameters);
|
|
751
|
-
return {
|
|
752
|
-
kind: "class_function" /* NodeKind.classFunction */,
|
|
753
|
-
name: node.name,
|
|
754
|
-
parameters,
|
|
755
|
-
returnType: ReturnType,
|
|
756
|
-
...this._generateDocAndMetadata(node)
|
|
757
|
-
};
|
|
758
|
-
}
|
|
759
|
-
generateStaticClassFunction(node) {
|
|
760
|
-
const parameters = node.parameters.map(p => this.generateParameter(p));
|
|
761
|
-
const output_parameters = node.output_parameters;
|
|
762
|
-
const return_type = node.return();
|
|
763
|
-
const ReturnType = this.generateReturn(return_type, output_parameters);
|
|
764
|
-
return {
|
|
765
|
-
kind: "static_class_function" /* NodeKind.staticClassFunction */,
|
|
766
|
-
name: node.name,
|
|
767
|
-
parameters,
|
|
768
|
-
returnType: ReturnType,
|
|
769
|
-
...this._generateDocAndMetadata(node)
|
|
770
|
-
};
|
|
771
|
-
}
|
|
772
|
-
generateAlias(node) {
|
|
773
|
-
const { namespace, options } = this;
|
|
774
|
-
const type = node.type.resolve(namespace, options);
|
|
775
|
-
const { name } = node;
|
|
776
|
-
return {
|
|
777
|
-
kind: "alias" /* NodeKind.alias */,
|
|
778
|
-
name,
|
|
779
|
-
type: generateType(type.resolve(namespace, options)),
|
|
780
|
-
...this._generateDocAndMetadata(node)
|
|
781
|
-
};
|
|
782
|
-
}
|
|
783
|
-
generateVirtualClassFunction(node) {
|
|
784
|
-
return {
|
|
785
|
-
...this.generateClassFunction(node),
|
|
786
|
-
kind: "virtual_class_function" /* NodeKind.virtualClassFunction */
|
|
787
|
-
};
|
|
788
|
-
}
|
|
789
|
-
generateNamespace(node) {
|
|
790
|
-
function shouldGenerate(node) {
|
|
791
|
-
return node.emit;
|
|
792
|
-
}
|
|
793
|
-
const { namespace, version } = node.dependency;
|
|
794
|
-
const members = Array.from(node.members.values())
|
|
795
|
-
.flatMap(m => m)
|
|
796
|
-
.filter(shouldGenerate);
|
|
797
|
-
const classes = members
|
|
798
|
-
.filter((m) => m instanceof IntrospectedClass)
|
|
799
|
-
.map(m => m.asString(this));
|
|
800
|
-
const interfaces = members
|
|
801
|
-
.filter((m) => m instanceof IntrospectedInterface)
|
|
802
|
-
.map(m => m.asString(this));
|
|
803
|
-
const records = members
|
|
804
|
-
.filter((m) => m instanceof IntrospectedRecord)
|
|
805
|
-
.map(m => m.asString(this));
|
|
806
|
-
const constants = members
|
|
807
|
-
.filter((m) => m instanceof IntrospectedConstant)
|
|
808
|
-
.map(m => m.asString(this));
|
|
809
|
-
const callbacks = members
|
|
810
|
-
.filter((m) => m instanceof IntrospectedCallback)
|
|
811
|
-
.map(m => m.asString(this));
|
|
812
|
-
// Functions can have overrides.
|
|
813
|
-
const functions = [
|
|
814
|
-
...members
|
|
815
|
-
.filter((m) => !(m instanceof IntrospectedCallback) && m instanceof IntrospectedFunction)
|
|
816
|
-
.reduce((prev, next) => {
|
|
817
|
-
if (!prev.has(next.name))
|
|
818
|
-
prev.set(next.name, next.asString(this));
|
|
819
|
-
return prev;
|
|
820
|
-
}, new Map())
|
|
821
|
-
.values()
|
|
822
|
-
];
|
|
823
|
-
const errors = members
|
|
824
|
-
.filter((m) => m instanceof IntrospectedError)
|
|
825
|
-
.map(m => m.asString(this));
|
|
826
|
-
const enums = members
|
|
827
|
-
.filter((m) => !(m instanceof IntrospectedError) && m instanceof IntrospectedEnum)
|
|
828
|
-
.map(m => m.asString(this));
|
|
829
|
-
const alias = members
|
|
830
|
-
.filter((m) => m instanceof IntrospectedAlias)
|
|
831
|
-
.map(m => m.asString(this));
|
|
832
|
-
// Resolve imports after we stringify everything else, sometimes we have to ad-hoc add an import.
|
|
833
|
-
const imports = [];
|
|
834
|
-
return Promise.resolve({
|
|
835
|
-
kind: "namespace" /* NodeKind.namespace */,
|
|
836
|
-
name: namespace,
|
|
837
|
-
version,
|
|
838
|
-
imports: Object.fromEntries(imports),
|
|
839
|
-
classes,
|
|
840
|
-
interfaces,
|
|
841
|
-
records,
|
|
842
|
-
constants,
|
|
843
|
-
functions,
|
|
844
|
-
callbacks,
|
|
845
|
-
errors,
|
|
846
|
-
enums,
|
|
847
|
-
alias
|
|
848
|
-
});
|
|
849
|
-
}
|
|
850
|
-
async stringifyNamespace(node) {
|
|
851
|
-
const { namespace } = this;
|
|
852
|
-
this.log.debug(`Resolving the types of ${namespace.namespace}...`);
|
|
853
|
-
try {
|
|
854
|
-
const output = await this.generateNamespace(node);
|
|
855
|
-
this.log.debug(`Printing ${namespace.namespace}...`);
|
|
856
|
-
if (!output)
|
|
857
|
-
return null;
|
|
858
|
-
return JSON.stringify(output, null, 4);
|
|
859
|
-
}
|
|
860
|
-
catch (err) {
|
|
861
|
-
this.log.error(`Failed to generate namespace: "${node.namespace}"`, err);
|
|
862
|
-
return null;
|
|
863
|
-
}
|
|
864
|
-
}
|
|
865
|
-
}
|
|
866
|
-
//# sourceMappingURL=json.js.map
|