@gtkx/gir 0.1.48 → 0.1.49

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": "@gtkx/gir",
3
- "version": "0.1.48",
3
+ "version": "0.1.49",
4
4
  "description": "GObject Introspection file parser for GTKX",
5
5
  "keywords": [
6
6
  "gtk",
package/src/parser.ts CHANGED
@@ -61,6 +61,9 @@ const extractDoc = (node: Record<string, unknown>): string | undefined => {
61
61
  return text?.trim();
62
62
  };
63
63
 
64
+ const ensureArray = (value: unknown): Record<string, unknown>[] =>
65
+ Array.isArray(value) ? (value as Record<string, unknown>[]) : [];
66
+
64
67
  /**
65
68
  * Parser for GObject Introspection (GIR) XML files.
66
69
  * Converts GIR XML into structured TypeScript interfaces.
@@ -143,19 +146,11 @@ export class GirParser {
143
146
  implements: this.parseImplements(
144
147
  cls.implements as Record<string, unknown>[] | Record<string, unknown> | undefined,
145
148
  ),
146
- methods: this.parseMethods(Array.isArray(cls.method) ? (cls.method as Record<string, unknown>[]) : []),
147
- constructors: this.parseConstructors(
148
- Array.isArray(cls.constructor) ? (cls.constructor as Record<string, unknown>[]) : [],
149
- ),
150
- functions: this.parseFunctions(
151
- Array.isArray(cls.function) ? (cls.function as Record<string, unknown>[]) : [],
152
- ),
153
- properties: this.parseProperties(
154
- Array.isArray(cls.property) ? (cls.property as Record<string, unknown>[]) : [],
155
- ),
156
- signals: this.parseSignals(
157
- Array.isArray(cls["glib:signal"]) ? (cls["glib:signal"] as Record<string, unknown>[]) : [],
158
- ),
149
+ methods: this.parseMethods(ensureArray(cls.method)),
150
+ constructors: this.parseConstructors(ensureArray(cls.constructor)),
151
+ functions: this.parseFunctions(ensureArray(cls.function)),
152
+ properties: this.parseProperties(ensureArray(cls.property)),
153
+ signals: this.parseSignals(ensureArray(cls["glib:signal"])),
159
154
  doc: extractDoc(cls),
160
155
  }));
161
156
  }
@@ -173,13 +168,9 @@ export class GirParser {
173
168
  return interfaces.map((iface) => ({
174
169
  name: String(iface["@_name"] ?? ""),
175
170
  cType: String(iface["@_c:type"] ?? iface["@_glib:type-name"] ?? ""),
176
- methods: this.parseMethods(Array.isArray(iface.method) ? (iface.method as Record<string, unknown>[]) : []),
177
- properties: this.parseProperties(
178
- Array.isArray(iface.property) ? (iface.property as Record<string, unknown>[]) : [],
179
- ),
180
- signals: this.parseSignals(
181
- Array.isArray(iface["glib:signal"]) ? (iface["glib:signal"] as Record<string, unknown>[]) : [],
182
- ),
171
+ methods: this.parseMethods(ensureArray(iface.method)),
172
+ properties: this.parseProperties(ensureArray(iface.property)),
173
+ signals: this.parseSignals(ensureArray(iface["glib:signal"])),
183
174
  doc: extractDoc(iface),
184
175
  }));
185
176
  }
@@ -380,16 +371,10 @@ export class GirParser {
380
371
  disguised: record["@_disguised"] === "1",
381
372
  glibTypeName: record["@_glib:type-name"] ? String(record["@_glib:type-name"]) : undefined,
382
373
  glibGetType: record["@_glib:get-type"] ? String(record["@_glib:get-type"]) : undefined,
383
- fields: this.parseFields(Array.isArray(record.field) ? (record.field as Record<string, unknown>[]) : []),
384
- methods: this.parseMethods(
385
- Array.isArray(record.method) ? (record.method as Record<string, unknown>[]) : [],
386
- ),
387
- constructors: this.parseConstructors(
388
- Array.isArray(record.constructor) ? (record.constructor as Record<string, unknown>[]) : [],
389
- ),
390
- functions: this.parseFunctions(
391
- Array.isArray(record.function) ? (record.function as Record<string, unknown>[]) : [],
392
- ),
374
+ fields: this.parseFields(ensureArray(record.field)),
375
+ methods: this.parseMethods(ensureArray(record.method)),
376
+ constructors: this.parseConstructors(ensureArray(record.constructor)),
377
+ functions: this.parseFunctions(ensureArray(record.function)),
393
378
  doc: extractDoc(record),
394
379
  }));
395
380
  }
@@ -420,9 +405,7 @@ export class GirParser {
420
405
  return enumerations.map((enumeration) => ({
421
406
  name: String(enumeration["@_name"] ?? ""),
422
407
  cType: String(enumeration["@_c:type"] ?? ""),
423
- members: this.parseEnumerationMembers(
424
- Array.isArray(enumeration.member) ? (enumeration.member as Record<string, unknown>[]) : [],
425
- ),
408
+ members: this.parseEnumerationMembers(ensureArray(enumeration.member)),
426
409
  doc: extractDoc(enumeration),
427
410
  }));
428
411
  }
package/src/types.ts CHANGED
@@ -990,9 +990,34 @@ export class TypeMapper {
990
990
  */
991
991
  mapParameter(param: GirParameter): MappedType {
992
992
  if (param.direction === "out" || param.direction === "inout") {
993
+ // Temporarily disable callbacks while mapping the inner type,
994
+ // since Ref<unknown> doesn't need the type import
995
+ const savedRecordCallback = this.onRecordUsed;
996
+ const savedExternalCallback = this.onExternalTypeUsed;
997
+ const savedClassCallback = this.onSameNamespaceClassUsed;
998
+ this.onRecordUsed = undefined;
999
+ this.onExternalTypeUsed = undefined;
1000
+ this.onSameNamespaceClassUsed = undefined;
1001
+
993
1002
  const innerType = this.mapType(param.type);
1003
+
1004
+ // Restore callbacks
1005
+ this.onRecordUsed = savedRecordCallback;
1006
+ this.onExternalTypeUsed = savedExternalCallback;
1007
+ this.onSameNamespaceClassUsed = savedClassCallback;
1008
+
1009
+ // For boxed/gobject types, Ref wraps the raw ptr (unknown), not the wrapper class
1010
+ const isBoxedOrGObject = innerType.ffi.type === "boxed" || innerType.ffi.type === "gobject";
1011
+ const tsType = isBoxedOrGObject ? "unknown" : innerType.ts;
1012
+
1013
+ // Only trigger callbacks for non-boxed/gobject types that will actually appear in TS
1014
+ if (!isBoxedOrGObject) {
1015
+ // Re-map with callbacks enabled to register the type usage
1016
+ this.mapType(param.type);
1017
+ }
1018
+
994
1019
  return {
995
- ts: `Ref<${innerType.ts}>`,
1020
+ ts: `Ref<${tsType}>`,
996
1021
  ffi: {
997
1022
  type: "ref",
998
1023
  innerType: innerType.ffi,