@ts-for-gir/cli 4.0.0-rc.6 → 4.0.0-rc.7

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/bin/ts-for-gir CHANGED
@@ -7268,7 +7268,7 @@ import { dirname, join } from "node:path";
7268
7268
  import { fileURLToPath } from "node:url";
7269
7269
  function getPackageVersion() {
7270
7270
  if (true) {
7271
- return "4.0.0-rc.6";
7271
+ return "4.0.0-rc.7";
7272
7272
  }
7273
7273
  const currentModulePath = fileURLToPath(import.meta.url);
7274
7274
  const currentDir = dirname(currentModulePath);
@@ -8165,7 +8165,7 @@ import { fileURLToPath as fileURLToPath2 } from "node:url";
8165
8165
  var NEW_LINE_REG_EXP = /[\n\r]+/g;
8166
8166
  function getPackageVersion2() {
8167
8167
  if (true) {
8168
- return "4.0.0-rc.6";
8168
+ return "4.0.0-rc.7";
8169
8169
  }
8170
8170
  const currentModulePath = fileURLToPath2(import.meta.url);
8171
8171
  const currentDir = dirname2(currentModulePath);
@@ -14393,12 +14393,16 @@ var IntrospectedProperty = class _IntrospectedProperty extends IntrospectedBase
14393
14393
  writable = false;
14394
14394
  readable = true;
14395
14395
  constructOnly;
14396
+ /** GIR default-value attribute: the default value of the property as a string. */
14397
+ defaultValue;
14398
+ /** GIR getter attribute: name of the getter method for this property (used for nullable inference). */
14399
+ getter;
14396
14400
  get namespace() {
14397
14401
  return this.parent.namespace;
14398
14402
  }
14399
14403
  copy(options2) {
14400
14404
  const { name, writable, readable, type, constructOnly, parent } = this;
14401
- return new _IntrospectedProperty({
14405
+ const prop = new _IntrospectedProperty({
14402
14406
  name: options2?.name ?? name,
14403
14407
  writable,
14404
14408
  readable,
@@ -14406,6 +14410,9 @@ var IntrospectedProperty = class _IntrospectedProperty extends IntrospectedBase
14406
14410
  constructOnly,
14407
14411
  parent: options2?.parent ?? parent
14408
14412
  })._copyBaseProperties(this);
14413
+ prop.defaultValue = this.defaultValue;
14414
+ prop.getter = this.getter;
14415
+ return prop;
14409
14416
  }
14410
14417
  accept(visitor) {
14411
14418
  const node = this.copy({
@@ -14463,6 +14470,11 @@ var IntrospectedProperty = class _IntrospectedProperty extends IntrospectedBase
14463
14470
  property.doc = parseDoc(element);
14464
14471
  property.metadata = parseMetadata(element);
14465
14472
  }
14473
+ property.defaultValue = element.$["default-value"];
14474
+ property.getter = element.$.getter;
14475
+ if (element.$.nullable === "1" || element.$["allow-none"] === "1") {
14476
+ property.type = new NullableType(property.type);
14477
+ }
14466
14478
  return property;
14467
14479
  }
14468
14480
  };
@@ -14655,6 +14667,28 @@ var IntrospectedSignal = class _IntrospectedSignal extends IntrospectedClassMemb
14655
14667
 
14656
14668
  // ../lib/src/gir/introspected-classes.ts
14657
14669
  var log = new ConsoleReporter(true, "gir/introspected-classes", true);
14670
+ function hasExtendsShadowOf(cls, prerequisite, name) {
14671
+ let current = cls.resolveParents().extends();
14672
+ while (current) {
14673
+ const node = current.node;
14674
+ if (node !== prerequisite) {
14675
+ const hasOwn = [...node.props, ...node.fields, ...node.members].some((m) => m.name === name);
14676
+ if (hasOwn) return true;
14677
+ }
14678
+ current = current.extends();
14679
+ }
14680
+ return false;
14681
+ }
14682
+ function resolveNullableProperties(cls) {
14683
+ for (const prop of cls.props) {
14684
+ if (prop.type instanceof NullableType) continue;
14685
+ const getterName = prop.getter ?? `get_${prop.name}`;
14686
+ const getter = cls.members.find((m) => m.name === getterName && !(m instanceof IntrospectedStaticClassFunction));
14687
+ if (getter instanceof IntrospectedClassFunction && getter.return() instanceof NullableType) {
14688
+ prop.type = new NullableType(prop.type);
14689
+ }
14690
+ }
14691
+ }
14658
14692
  var IntrospectedClassFunction = class _IntrospectedClassFunction extends IntrospectedBase {
14659
14693
  parameters;
14660
14694
  return_type;
@@ -14665,6 +14699,8 @@ var IntrospectedClassFunction = class _IntrospectedClassFunction extends Introsp
14665
14699
  returnTypeDoc;
14666
14700
  /** If this function was generated from a signal, stores the signal name. */
14667
14701
  signalOrigin;
14702
+ /** GIR glib:finish-func attribute: name of the function that finishes this async operation. */
14703
+ finishFuncName;
14668
14704
  generics = [];
14669
14705
  constructor({
14670
14706
  name,
@@ -14711,6 +14747,7 @@ var IntrospectedClassFunction = class _IntrospectedClassFunction extends Introsp
14711
14747
  });
14712
14748
  fn.generics = [...this.generics];
14713
14749
  fn.returnTypeDoc = this.returnTypeDoc;
14750
+ fn.finishFuncName = this.finishFuncName;
14714
14751
  if (interfaceParent) {
14715
14752
  fn.interfaceParent = interfaceParent;
14716
14753
  }
@@ -14732,6 +14769,7 @@ var IntrospectedClassFunction = class _IntrospectedClassFunction extends Introsp
14732
14769
  static fromXML(element, parent, options2) {
14733
14770
  const fn = IntrospectedFunction.fromXML(element, parent.namespace, options2);
14734
14771
  const { raw_name: name, output_parameters, parameters, return_type, doc: doc2, isIntrospectable: isIntrospectable2 } = fn;
14772
+ const isShadowedBy = element.$["shadowed-by"] != null;
14735
14773
  const classFn = new _IntrospectedClassFunction({
14736
14774
  parent,
14737
14775
  name,
@@ -14739,10 +14777,11 @@ var IntrospectedClassFunction = class _IntrospectedClassFunction extends Introsp
14739
14777
  parameters,
14740
14778
  return_type,
14741
14779
  doc: doc2,
14742
- isIntrospectable: isIntrospectable2
14780
+ isIntrospectable: isIntrospectable2 && !isShadowedBy
14743
14781
  });
14744
14782
  classFn.returnTypeDoc = fn.returnTypeDoc;
14745
14783
  classFn.generics = [...fn.generics];
14784
+ classFn.finishFuncName = element.$["glib:finish-func"];
14746
14785
  return classFn;
14747
14786
  }
14748
14787
  anyify() {
@@ -14885,6 +14924,7 @@ var IntrospectedStaticClassFunction = class _IntrospectedStaticClassFunction ext
14885
14924
  static fromXML(m, parent, options2) {
14886
14925
  const fn = IntrospectedFunction.fromXML(m, parent.namespace, options2);
14887
14926
  const { raw_name: name, output_parameters, parameters, return_type, doc: doc2, isIntrospectable: isIntrospectable2 } = fn;
14927
+ const isShadowedBy = m.$["shadowed-by"] != null;
14888
14928
  return new _IntrospectedStaticClassFunction({
14889
14929
  parent,
14890
14930
  name,
@@ -14892,7 +14932,7 @@ var IntrospectedStaticClassFunction = class _IntrospectedStaticClassFunction ext
14892
14932
  parameters,
14893
14933
  return_type,
14894
14934
  doc: doc2,
14895
- isIntrospectable: isIntrospectable2
14935
+ isIntrospectable: isIntrospectable2 && !isShadowedBy
14896
14936
  });
14897
14937
  }
14898
14938
  };
@@ -15211,6 +15251,7 @@ var IntrospectedClass = class _IntrospectedClass extends IntrospectedBaseClass {
15211
15251
  if (extended?.node instanceof _IntrospectedClass) {
15212
15252
  for (const item of getItems(extended.node)) {
15213
15253
  if (items.has(item.name) || !validate3(item)) continue;
15254
+ if (!hasExtendsShadowOf(this, extended.node, item.name)) continue;
15214
15255
  items.set(item.name, item);
15215
15256
  }
15216
15257
  }
@@ -15348,6 +15389,7 @@ var IntrospectedClass = class _IntrospectedClass extends IntrospectedBaseClass {
15348
15389
  _IntrospectedClass.parseBasicProperties(element, clazz, ns, options2);
15349
15390
  _IntrospectedClass.parseResolveNames(element, clazz, ns, name);
15350
15391
  _IntrospectedClass.parseInheritanceAndMembers(element, clazz, ns, options2);
15392
+ resolveNullableProperties(clazz);
15351
15393
  return clazz;
15352
15394
  }
15353
15395
  static parseBasicProperties(element, clazz, ns, options2) {
@@ -15578,6 +15620,7 @@ var IntrospectedInterface = class _IntrospectedInterface extends IntrospectedBas
15578
15620
  _IntrospectedInterface.parseInterfaceBasicProperties(element, iface, namespace, options2);
15579
15621
  _IntrospectedInterface.parseInterfaceResolveNames(element, iface, namespace, name);
15580
15622
  _IntrospectedInterface.parseInterfaceMembers(element, iface, namespace, options2);
15623
+ resolveNullableProperties(iface);
15581
15624
  return iface;
15582
15625
  }
15583
15626
  static parseInterfaceBasicProperties(element, iface, namespace, options2) {
@@ -15948,9 +15991,7 @@ var IntrospectedFunction = class _IntrospectedFunction extends IntrospectedNames
15948
15991
  ({ allowOptions, params }, p) => {
15949
15992
  const { type, isOptional } = p;
15950
15993
  if (allowOptions) {
15951
- if (type instanceof NullableType) {
15952
- params.push(p.copy({ isOptional: true }));
15953
- } else if (!isOptional) {
15994
+ if (!isOptional) {
15954
15995
  params.push(p);
15955
15996
  return { allowOptions: false, params };
15956
15997
  } else {
@@ -17461,6 +17502,9 @@ function generatePromisifyOverloadedSignatures(node, async_parameters, sync_para
17461
17502
  }
17462
17503
  function findFinishMethodInClass(cls, node) {
17463
17504
  const members = node instanceof IntrospectedStaticClassFunction ? [...cls.constructors, ...cls.members.filter((m) => m instanceof IntrospectedStaticClassFunction)] : [...cls.members.filter((m) => !(m instanceof IntrospectedStaticClassFunction))];
17505
+ if (node.finishFuncName) {
17506
+ return members.find((m) => m.name === node.finishFuncName);
17507
+ }
17464
17508
  return members.find(
17465
17509
  (m) => m.name === `${node.name.replace(/_async$/, "")}_finish` || m.name === `${node.name}_finish`
17466
17510
  );
@@ -20172,6 +20216,14 @@ var fixMissingParent = (node) => {
20172
20216
  var removeComplexFields = (node) => {
20173
20217
  const { namespace } = node;
20174
20218
  node.fields = node.fields.filter((f) => {
20219
+ if (f.type instanceof ArrayType) {
20220
+ const elementType = f.type.deepUnwrap();
20221
+ if (elementType instanceof TypeIdentifier) {
20222
+ const classNode = resolveTypeIdentifier(namespace, elementType);
20223
+ return !classNode?.isPrivate;
20224
+ }
20225
+ return true;
20226
+ }
20175
20227
  const type = f.type.deepUnwrap();
20176
20228
  if (type instanceof NativeType) {
20177
20229
  return true;
@@ -20716,7 +20768,7 @@ function checkFunctionConflicts(ns, base, functionElement, conflict_ids, nextTyp
20716
20768
  return false;
20717
20769
  });
20718
20770
  });
20719
- const hasFieldConflicts = checkFieldPropertyConflicts(base, functionElement.name);
20771
+ const hasFieldConflicts = functionElement instanceof IntrospectedStaticClassFunction ? false : checkFieldPropertyConflicts(base, functionElement.name);
20720
20772
  const hasGObjectConflicts = checkGObjectConflicts(base, functionElement.name);
20721
20773
  const hasConflict = hasParentConflict || hasGObjectConflicts;
20722
20774
  return {
@@ -20950,6 +21002,38 @@ function mergeDescs(descs, comment, indentCount = 1) {
20950
21002
  return def;
20951
21003
  }
20952
21004
 
21005
+ // ../lib/src/utils/gir-defaults.ts
21006
+ function resolveCEnumConstant(cIdentifier, ns) {
21007
+ const own = ns.enum_constants.get(cIdentifier);
21008
+ if (own) return [ns.namespace, own[0], own[1]];
21009
+ for (const dep of ns.allDependencies) {
21010
+ const depModule = ns.getInstalledImport(dep.namespace);
21011
+ if (!depModule) continue;
21012
+ const entry = depModule.enum_constants.get(cIdentifier);
21013
+ if (entry) return [depModule.namespace, entry[0], entry[1]];
21014
+ }
21015
+ return null;
21016
+ }
21017
+ function convertSingleCValue(value, ns) {
21018
+ const trimmed = value.trim();
21019
+ if (trimmed === "NULL") return "null";
21020
+ if (trimmed === "TRUE") return "true";
21021
+ if (trimmed === "FALSE") return "false";
21022
+ if (/^-?\d+\.\d+$/.test(trimmed)) {
21023
+ const n = parseFloat(trimmed);
21024
+ if (!Number.isNaN(n)) return String(n);
21025
+ }
21026
+ const entry = resolveCEnumConstant(trimmed, ns);
21027
+ if (entry) return `${entry[0]}.${entry[1]}.${entry[2]}`;
21028
+ return trimmed;
21029
+ }
21030
+ function convertCDefaultValue(rawValue, ns) {
21031
+ if (rawValue.includes("|")) {
21032
+ return rawValue.split("|").map((part) => convertSingleCValue(part, ns)).join(" | ");
21033
+ }
21034
+ return convertSingleCValue(rawValue, ns);
21035
+ }
21036
+
20953
21037
  // ../lib/src/utils/path.ts
20954
21038
  import { dirname as dirname4, resolve as resolve3 } from "node:path";
20955
21039
  import { fileURLToPath as fileURLToPath3 } from "node:url";
@@ -23441,6 +23525,12 @@ export const ${node.name}: ${node.name}Namespace & {
23441
23525
  if (tsProp.constructOnly) propTags.push({ tagName: "construct-only", paramName: "", text: "" });
23442
23526
  else if (tsProp.readable && !tsProp.writable) propTags.push({ tagName: "read-only", paramName: "", text: "" });
23443
23527
  else if (tsProp.writable && !tsProp.readable) propTags.push({ tagName: "write-only", paramName: "", text: "" });
23528
+ if (tsProp.defaultValue !== void 0)
23529
+ propTags.push({
23530
+ tagName: "default",
23531
+ paramName: "",
23532
+ text: convertCDefaultValue(tsProp.defaultValue, this.namespace)
23533
+ });
23444
23534
  desc.push(...this.addGirDocComment(tsProp.doc, propTags, indentCount));
23445
23535
  const indent = generateIndent(indentCount);
23446
23536
  const name = generateMemberName(tsProp);
@@ -27576,7 +27666,7 @@ import { fileURLToPath as fileURLToPath5 } from "node:url";
27576
27666
  import { i18n, JSX as JSX8, ReflectionKind as ReflectionKind4 } from "typedoc";
27577
27667
  function getTsForGirVersion() {
27578
27668
  if (true) {
27579
- return "4.0.0-rc.6";
27669
+ return "4.0.0-rc.7";
27580
27670
  }
27581
27671
  const __dirname3 = dirname8(fileURLToPath5(import.meta.url));
27582
27672
  return JSON.parse(readFileSync7(join14(__dirname3, "..", "..", "package.json"), "utf8")).version;
@@ -11,7 +11,7 @@
11
11
  "clear": "rm -rf dist @types"
12
12
  },
13
13
  "devDependencies": {
14
- "@ts-for-gir/cli": "^4.0.0-rc.6",
14
+ "@ts-for-gir/cli": "^4.0.0-rc.7",
15
15
  "esbuild": "^0.28.0",
16
16
  "typescript": "^6.0.2"
17
17
  }
@@ -14,10 +14,10 @@
14
14
  "typescript": "^6.0.2"
15
15
  },
16
16
  "dependencies": {
17
- "@girs/adw-1": "^1.10.0-4.0.0-rc.5",
18
- "@girs/gio-2.0": "^2.88.0-4.0.0-rc.5",
19
- "@girs/gjs": "^4.0.0-rc.5",
20
- "@girs/glib-2.0": "^2.88.0-4.0.0-rc.5",
21
- "@girs/gtk-4.0": "^4.23.0-4.0.0-rc.5"
17
+ "@girs/adw-1": "^1.10.0-4.0.0-rc.6",
18
+ "@girs/gio-2.0": "^2.88.0-4.0.0-rc.6",
19
+ "@girs/gjs": "^4.0.0-rc.6",
20
+ "@girs/glib-2.0": "^2.88.0-4.0.0-rc.6",
21
+ "@girs/gtk-4.0": "^4.23.0-4.0.0-rc.6"
22
22
  }
23
23
  }
@@ -16,7 +16,7 @@
16
16
  "clear": "rm -rf @girs packages/*/dist"
17
17
  },
18
18
  "devDependencies": {
19
- "@ts-for-gir/cli": "^4.0.0-rc.6",
19
+ "@ts-for-gir/cli": "^4.0.0-rc.7",
20
20
  "typescript": "^6.0.2"
21
21
  }
22
22
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ts-for-gir/cli",
3
- "version": "4.0.0-rc.6",
3
+ "version": "4.0.0-rc.7",
4
4
  "description": "TypeScript type definition generator for GObject introspection GIR files",
5
5
  "main": "src/index.ts",
6
6
  "module": "src/index.ts",
@@ -55,14 +55,14 @@
55
55
  ".": "./src/index.ts"
56
56
  },
57
57
  "devDependencies": {
58
- "@gi.ts/parser": "^4.0.0-rc.6",
59
- "@ts-for-gir/generator-base": "^4.0.0-rc.6",
60
- "@ts-for-gir/generator-html-doc": "^4.0.0-rc.6",
61
- "@ts-for-gir/generator-json": "^4.0.0-rc.6",
62
- "@ts-for-gir/generator-typescript": "^4.0.0-rc.6",
63
- "@ts-for-gir/lib": "^4.0.0-rc.6",
64
- "@ts-for-gir/reporter": "^4.0.0-rc.6",
65
- "@ts-for-gir/tsconfig": "^4.0.0-rc.6",
58
+ "@gi.ts/parser": "^4.0.0-rc.7",
59
+ "@ts-for-gir/generator-base": "^4.0.0-rc.7",
60
+ "@ts-for-gir/generator-html-doc": "^4.0.0-rc.7",
61
+ "@ts-for-gir/generator-json": "^4.0.0-rc.7",
62
+ "@ts-for-gir/generator-typescript": "^4.0.0-rc.7",
63
+ "@ts-for-gir/lib": "^4.0.0-rc.7",
64
+ "@ts-for-gir/reporter": "^4.0.0-rc.7",
65
+ "@ts-for-gir/tsconfig": "^4.0.0-rc.7",
66
66
  "@types/ejs": "^3.1.5",
67
67
  "@types/inquirer": "^9.0.9",
68
68
  "@types/node": "^25.6.0",
@@ -72,7 +72,7 @@
72
72
  },
73
73
  "dependencies": {
74
74
  "@inquirer/prompts": "^8.4.2",
75
- "@ts-for-gir/templates": "^4.0.0-rc.6",
75
+ "@ts-for-gir/templates": "^4.0.0-rc.7",
76
76
  "colorette": "^2.0.20",
77
77
  "cosmiconfig": "^9.0.1",
78
78
  "ejs": "^5.0.2",