@ts-for-gir/lib 4.0.0-rc.1 → 4.0.0-rc.2
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 +5 -5
- package/src/gir.ts +1 -0
- package/src/utils/gir-parsing.ts +3 -1
- package/src/utils/types.ts +31 -4
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ts-for-gir/lib",
|
|
3
|
-
"version": "4.0.0-rc.
|
|
3
|
+
"version": "4.0.0-rc.2",
|
|
4
4
|
"description": "Typescript .d.ts generator from GIR for gjs",
|
|
5
5
|
"main": "src/index.ts",
|
|
6
6
|
"module": "src/index.ts",
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
"type definitions"
|
|
42
42
|
],
|
|
43
43
|
"devDependencies": {
|
|
44
|
-
"@ts-for-gir/tsconfig": "^4.0.0-rc.
|
|
44
|
+
"@ts-for-gir/tsconfig": "^4.0.0-rc.2",
|
|
45
45
|
"@types/ejs": "^3.1.5",
|
|
46
46
|
"@types/lodash": "^4.17.24",
|
|
47
47
|
"@types/node": "^24.12.2",
|
|
@@ -49,9 +49,9 @@
|
|
|
49
49
|
"typescript": "^6.0.2"
|
|
50
50
|
},
|
|
51
51
|
"dependencies": {
|
|
52
|
-
"@gi.ts/parser": "^4.0.0-rc.
|
|
53
|
-
"@ts-for-gir/reporter": "^4.0.0-rc.
|
|
54
|
-
"@ts-for-gir/templates": "^4.0.0-rc.
|
|
52
|
+
"@gi.ts/parser": "^4.0.0-rc.2",
|
|
53
|
+
"@ts-for-gir/reporter": "^4.0.0-rc.2",
|
|
54
|
+
"@ts-for-gir/templates": "^4.0.0-rc.2",
|
|
55
55
|
"colorette": "^2.0.20",
|
|
56
56
|
"ejs": "^5.0.1",
|
|
57
57
|
"glob": "^13.0.6",
|
package/src/gir.ts
CHANGED
|
@@ -861,6 +861,7 @@ export const Uint8ArrayType = new NativeType("Uint8Array");
|
|
|
861
861
|
export const BooleanType = new NativeType("boolean");
|
|
862
862
|
export const StringType = new NativeType("string");
|
|
863
863
|
export const NumberType = new NativeType("number");
|
|
864
|
+
export const BigintOrNumberType = new BinaryType(new NativeType("bigint"), NumberType);
|
|
864
865
|
export const NullType = new NativeType("null");
|
|
865
866
|
export const VoidType = new NativeType("void");
|
|
866
867
|
export const UnknownType = new NativeType("unknown");
|
package/src/utils/gir-parsing.ts
CHANGED
|
@@ -14,6 +14,7 @@ import { LazyReporter } from "@ts-for-gir/reporter";
|
|
|
14
14
|
import type { IntrospectedNamespace } from "../gir/namespace.ts";
|
|
15
15
|
import {
|
|
16
16
|
ArrayType,
|
|
17
|
+
BigintOrNumberType,
|
|
17
18
|
ClosureType,
|
|
18
19
|
GenerifiedTypeIdentifier,
|
|
19
20
|
NativeType,
|
|
@@ -238,7 +239,8 @@ export function getType(
|
|
|
238
239
|
parameter.$ &&
|
|
239
240
|
(parameter.$.direction === GirDirection.Inout || parameter.$.direction === GirDirection.Out) &&
|
|
240
241
|
(nullable || allowNone) &&
|
|
241
|
-
!(variableType instanceof NativeType)
|
|
242
|
+
!(variableType instanceof NativeType) &&
|
|
243
|
+
variableType !== BigintOrNumberType
|
|
242
244
|
) {
|
|
243
245
|
return new NullableType(variableType);
|
|
244
246
|
}
|
package/src/utils/types.ts
CHANGED
|
@@ -4,14 +4,19 @@ import type { IntrospectedNamespace } from "../gir/namespace.ts";
|
|
|
4
4
|
import {
|
|
5
5
|
AnyType,
|
|
6
6
|
ArrayType,
|
|
7
|
+
BigintOrNumberType,
|
|
7
8
|
BinaryType,
|
|
8
9
|
BooleanType,
|
|
9
10
|
NativeType,
|
|
10
11
|
NeverType,
|
|
12
|
+
NullableType,
|
|
11
13
|
NumberType,
|
|
12
14
|
ObjectType,
|
|
15
|
+
OrType,
|
|
16
|
+
PromiseType,
|
|
13
17
|
StringType,
|
|
14
18
|
ThisType,
|
|
19
|
+
TupleType,
|
|
15
20
|
type TypeExpression,
|
|
16
21
|
TypeIdentifier,
|
|
17
22
|
Uint8ArrayType,
|
|
@@ -167,18 +172,19 @@ export function resolvePrimitiveType(name: string): TypeExpression | null {
|
|
|
167
172
|
case "gfloat":
|
|
168
173
|
case "gchar":
|
|
169
174
|
case "guint":
|
|
170
|
-
case "glong":
|
|
171
|
-
case "gulong":
|
|
172
175
|
case "gint":
|
|
173
176
|
case "guint8":
|
|
177
|
+
case "gdouble":
|
|
178
|
+
return NumberType;
|
|
179
|
+
case "glong":
|
|
180
|
+
case "gulong":
|
|
174
181
|
case "guint64":
|
|
175
182
|
case "gint64":
|
|
176
|
-
case "gdouble":
|
|
177
183
|
case "gssize":
|
|
178
184
|
case "gsize":
|
|
179
185
|
case "time_t": // C standard library time type (seconds since Unix epoch)
|
|
180
186
|
case "ulong": // C standard library unsigned long type
|
|
181
|
-
return
|
|
187
|
+
return BigintOrNumberType;
|
|
182
188
|
case "gboolean":
|
|
183
189
|
return BooleanType;
|
|
184
190
|
case "gpointer": // This is typically used in callbacks to pass data, so we'll allow anything.
|
|
@@ -243,6 +249,27 @@ export function resolveDirectedType(type: TypeExpression, direction: GirDirectio
|
|
|
243
249
|
return type;
|
|
244
250
|
}
|
|
245
251
|
}
|
|
252
|
+
} else if (type === BigintOrNumberType && direction === GirDirection.Out) {
|
|
253
|
+
// 64-bit integers accept number or bigint, but only return number to JS
|
|
254
|
+
return NumberType;
|
|
255
|
+
} else if (type instanceof PromiseType) {
|
|
256
|
+
// Propagate direction into the Promise's inner type so e.g. async
|
|
257
|
+
// functions returning 64-bit ints resolve to `Promise<number>` rather
|
|
258
|
+
// than `Promise<bigint | number>`.
|
|
259
|
+
const resolvedInner = resolveDirectedType(type.type, direction);
|
|
260
|
+
if (resolvedInner) return new PromiseType(resolvedInner);
|
|
261
|
+
} else if (type instanceof BinaryType && !(type instanceof NullableType)) {
|
|
262
|
+
// Walk through binary unions like `Promise<T> | void` (the dual-call
|
|
263
|
+
// async overload) so the inner types still get direction propagation.
|
|
264
|
+
// NullableType is skipped to preserve its subclass behaviour.
|
|
265
|
+
const a = resolveDirectedType(type.a, direction) ?? type.a;
|
|
266
|
+
const b = resolveDirectedType(type.b, direction) ?? type.b;
|
|
267
|
+
if (a !== type.a || b !== type.b) return new BinaryType(a, b);
|
|
268
|
+
} else if (type instanceof OrType && !(type instanceof BinaryType || type instanceof TupleType)) {
|
|
269
|
+
// flatten "bigint | number" out of another OR-type
|
|
270
|
+
const types = type.types.map((t) => resolveDirectedType(t, direction) ?? t);
|
|
271
|
+
if (types.length === 1) return types[0];
|
|
272
|
+
return new OrType(types[0], ...types.slice(1));
|
|
246
273
|
}
|
|
247
274
|
|
|
248
275
|
return null;
|