@ts-for-gir/lib 4.0.0-beta.26 → 4.0.0-beta.27

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ts-for-gir/lib",
3
- "version": "4.0.0-beta.26",
3
+ "version": "4.0.0-beta.27",
4
4
  "description": "Typescript .d.ts generator from GIR for gjs",
5
5
  "main": "src/index.ts",
6
6
  "module": "src/index.ts",
@@ -18,7 +18,7 @@
18
18
  "type": "git",
19
19
  "url": "git+https://github.com/gjsify/ts-for-gir.git"
20
20
  },
21
- "author": "Pascal Garber <pascal@artandcode.studio>",
21
+ "author": "Pascal Garber <pascal@mailfreun.de>",
22
22
  "files": [
23
23
  "src"
24
24
  ],
@@ -48,9 +48,9 @@
48
48
  "typescript": "^5.9.2"
49
49
  },
50
50
  "dependencies": {
51
- "@gi.ts/parser": "^4.0.0-beta.26",
52
- "@ts-for-gir/reporter": "^4.0.0-beta.26",
53
- "@ts-for-gir/templates": "^4.0.0-beta.26",
51
+ "@gi.ts/parser": "^4.0.0-beta.27",
52
+ "@ts-for-gir/reporter": "^4.0.0-beta.27",
53
+ "@ts-for-gir/templates": "^4.0.0-beta.27",
54
54
  "colorette": "^2.0.20",
55
55
  "ejs": "^3.1.10",
56
56
  "glob": "^11.0.3",
@@ -28,7 +28,7 @@ const GenericNames = [
28
28
 
29
29
  export function* getGenericNames(start: string = "A") {
30
30
  let names = GenericNames.map((s) => `${s}`);
31
- const startIteration = Number.parseInt(start.slice(1) || "0");
31
+ const startIteration = Number.parseInt(start.slice(1) || "0", 10);
32
32
 
33
33
  let i = startIteration;
34
34
 
package/src/gir-module.ts CHANGED
@@ -569,13 +569,15 @@ export class GirModule implements IGirModule {
569
569
  throw new Error(`Missing namespace in ${packageName}`);
570
570
  }
571
571
 
572
- const importConflicts = (el: IntrospectedConstant | IntrospectedBaseClass | IntrospectedFunction) => {
572
+ const importConflicts = (
573
+ el: IntrospectedConstant | IntrospectedBaseClass | IntrospectedFunction | IntrospectedEnum | IntrospectedError,
574
+ ) => {
573
575
  return !this.hasImport(el.name);
574
576
  };
575
577
 
576
578
  if (ns.enumeration) {
577
579
  // Get the requested enums
578
- ns.enumeration
580
+ const enumerations = ns.enumeration
579
581
  ?.map((enumeration) => {
580
582
  if (enumeration.$["glib:error-domain"]) {
581
583
  return IntrospectedError.fromXML(enumeration as GirEnumElement, this, options);
@@ -583,55 +585,72 @@ export class GirModule implements IGirModule {
583
585
  return IntrospectedEnum.fromXML(enumeration as GirEnumElement, this, options);
584
586
  }
585
587
  })
586
- .forEach((c) => this.members.set(c.name, c));
588
+ .filter(importConflicts);
589
+
590
+ for (const c of enumerations) {
591
+ this.members.set(c.name, c);
592
+ }
587
593
  }
588
594
 
589
595
  // Constants
590
596
  if (ns.constant) {
591
- ns.constant
597
+ const constants = ns.constant
592
598
  ?.filter(isIntrospectable)
593
599
  .map((constant) => IntrospectedConstant.fromXML(constant, this, options))
594
- .filter(importConflicts)
595
- .forEach((c) => this.members.set(c.name, c));
600
+ .filter(importConflicts);
601
+
602
+ for (const c of constants) {
603
+ this.members.set(c.name, c);
604
+ }
596
605
  }
597
606
 
598
607
  // Get the requested functions
599
608
  if (ns.function) {
600
- ns.function
609
+ const functions = ns.function
601
610
  ?.filter(isIntrospectable)
602
611
  .map((func) => IntrospectedFunction.fromXML(func, this, options))
603
- .filter(importConflicts)
604
- .forEach((c) => this.members.set(c.name, c));
612
+ .filter(importConflicts);
613
+
614
+ for (const c of functions) {
615
+ this.members.set(c.name, c);
616
+ }
605
617
  }
606
618
 
607
619
  if (ns.callback) {
608
- ns.callback
620
+ const callbacks = ns.callback
609
621
  ?.filter(isIntrospectable)
610
622
  .map((callback) => IntrospectedCallback.fromXML(callback, this, options))
611
- .filter(importConflicts)
612
- .forEach((c) => this.members.set(c.name, c));
623
+ .filter(importConflicts);
624
+
625
+ for (const c of callbacks) {
626
+ this.members.set(c.name, c);
627
+ }
613
628
  }
614
629
 
615
630
  if (ns["glib:boxed"]) {
616
- ns["glib:boxed"]
617
- ?.filter(isIntrospectable)
618
- .map(
619
- (boxed) =>
620
- new IntrospectedAlias({
621
- name: boxed.$["glib:name"],
622
- namespace: this,
623
- type: new NullableType(ObjectType),
624
- }),
625
- )
626
- .forEach((c) => this.members.set(c.name, c));
631
+ const boxed = ns["glib:boxed"]?.filter(isIntrospectable).map(
632
+ (boxed) =>
633
+ new IntrospectedAlias({
634
+ name: boxed.$["glib:name"],
635
+ namespace: this,
636
+ type: new NullableType(ObjectType),
637
+ }),
638
+ );
639
+
640
+ for (const c of boxed) {
641
+ this.members.set(c.name, c);
642
+ }
627
643
  }
628
644
 
629
645
  // Bitfield is a type of enum
630
646
  if (ns.bitfield) {
631
- ns.bitfield
647
+ const bitfields = ns.bitfield
632
648
  ?.filter(isIntrospectable)
633
- .map((field) => IntrospectedEnum.fromXML(field as GirBitfieldElement, this, options, true))
634
- .forEach((c) => this.members.set(c.name, c));
649
+ .map((field) => IntrospectedEnum.fromXML(field as GirBitfieldElement, this, options, true));
650
+
651
+ for (const c of bitfields) {
652
+ this.members.set(c.name, c);
653
+ }
635
654
  }
636
655
 
637
656
  // The `enum_constants` map maps the C identifiers (GTK_BUTTON_TYPE_Y)
@@ -646,40 +665,52 @@ export class GirModule implements IGirModule {
646
665
 
647
666
  // Get the requested classes
648
667
  if (ns.class) {
649
- ns.class
668
+ const classes = ns.class
650
669
  ?.filter(isIntrospectable)
651
670
  .map((klass) => IntrospectedClass.fromXML(klass, this, options))
652
- .filter(importConflicts)
653
- .forEach((c) => this.members.set(c.name, c));
671
+ .filter(importConflicts);
672
+
673
+ for (const c of classes) {
674
+ this.members.set(c.name, c);
675
+ }
654
676
  }
655
677
 
656
678
  if (ns.record) {
657
- ns.record
679
+ const records = ns.record
658
680
  ?.filter(isIntrospectable)
659
681
  .map((record) => IntrospectedRecord.fromXML(record, this, options))
660
- .filter(importConflicts)
661
- .forEach((c) => this.members.set(c.name, c));
682
+ .filter(importConflicts);
683
+
684
+ for (const c of records) {
685
+ this.members.set(c.name, c);
686
+ }
662
687
  }
663
688
 
664
689
  if (ns.union) {
665
- ns.union
690
+ const unions = ns.union
666
691
  ?.filter(isIntrospectable)
667
692
  .map((union) => IntrospectedRecord.fromXML(union, this, options))
668
- .filter(importConflicts)
669
- .forEach((c) => this.members.set(c.name, c));
693
+ .filter(importConflicts);
694
+
695
+ for (const c of unions) {
696
+ this.members.set(c.name, c);
697
+ }
670
698
  }
671
699
 
672
700
  if (ns.interface) {
673
- ns.interface
701
+ const interfaces = ns.interface
674
702
  ?.map((inter) => IntrospectedInterface.fromXML(inter as GirInterfaceElement, this, options))
675
- .filter(importConflicts)
676
- .forEach((c) => this.members.set(c.name, c));
703
+ .filter(importConflicts);
704
+
705
+ for (const c of interfaces) {
706
+ this.members.set(c.name, c);
707
+ }
677
708
  }
678
709
 
679
710
  if (ns.alias) {
680
711
  type NamedType = GirType & { $: { name: string } };
681
712
 
682
- ns.alias
713
+ const aliases = ns.alias
683
714
  ?.filter(isIntrospectable)
684
715
  // Avoid attempting to alias non-introspectable symbols.
685
716
  .map((b) => {
@@ -696,8 +727,11 @@ export class GirModule implements IGirModule {
696
727
  return b;
697
728
  })
698
729
  .map((alias) => IntrospectedAlias.fromXML(alias, this, options))
699
- .filter((alias): alias is IntrospectedAlias => alias != null)
700
- .forEach((c) => this.members.set(c.name, c));
730
+ .filter((alias): alias is IntrospectedAlias => alias != null);
731
+
732
+ for (const c of aliases) {
733
+ this.members.set(c.name, c);
734
+ }
701
735
  }
702
736
  }
703
737
  }
@@ -614,7 +614,7 @@ Note that GObject.Object.get_property is really intended for language bindings,
614
614
  });
615
615
 
616
616
  // Find the index and replace
617
- const bindPropertyFullIndex = GObject.members.findIndex((m) => m === bindPropertyFullWithClosures);
617
+ const bindPropertyFullIndex = GObject.members.indexOf(bindPropertyFullWithClosures);
618
618
  GObject.members[bindPropertyFullIndex] = bindPropertyFullWithClosures.copy({
619
619
  parameters: correctedParameters,
620
620
  });
package/src/utils/girs.ts CHANGED
@@ -71,7 +71,7 @@ export const isCommentLine = (line: string) => {
71
71
  */
72
72
  export const girBool = (boolStr: string | undefined, defaultVal = false): boolean => {
73
73
  if (boolStr) {
74
- if (parseInt(boolStr) === 0) return false;
74
+ if (parseInt(boolStr, 10) === 0) return false;
75
75
  return true;
76
76
  }
77
77
  return defaultVal;