nitrogen 0.33.7 → 0.33.8
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/lib/syntax/createType.js +14 -4
- package/lib/syntax/helpers.js +2 -1
- package/lib/syntax/isCoreType.d.ts +2 -0
- package/lib/syntax/isCoreType.js +20 -0
- package/lib/syntax/kotlin/KotlinBoxedPrimitive.js +4 -1
- package/lib/syntax/kotlin/KotlinCxxBridgedType.js +69 -13
- package/lib/syntax/swift/SwiftVariant.js +2 -1
- package/lib/syntax/types/ArrayType.js +4 -1
- package/lib/syntax/types/BigIntType.d.ts +2 -0
- package/lib/syntax/types/BigIntType.js +27 -9
- package/lib/syntax/types/Int64Type.d.ts +11 -0
- package/lib/syntax/types/Int64Type.js +30 -0
- package/lib/syntax/types/Type.d.ts +1 -1
- package/lib/syntax/types/UInt64Type.d.ts +11 -0
- package/lib/syntax/types/UInt64Type.js +30 -0
- package/package.json +2 -2
- package/src/syntax/createType.ts +16 -3
- package/src/syntax/helpers.ts +2 -1
- package/src/syntax/isCoreType.ts +21 -0
- package/src/syntax/kotlin/KotlinBoxedPrimitive.ts +4 -1
- package/src/syntax/kotlin/KotlinCxxBridgedType.ts +68 -13
- package/src/syntax/swift/SwiftVariant.ts +2 -1
- package/src/syntax/types/ArrayType.ts +4 -1
- package/src/syntax/types/{BigIntType.ts → Int64Type.ts} +3 -3
- package/src/syntax/types/Type.ts +2 -1
- package/src/syntax/types/UInt64Type.ts +38 -0
package/lib/syntax/createType.js
CHANGED
|
@@ -2,7 +2,7 @@ import { ts, Type as TSMorphType } from 'ts-morph';
|
|
|
2
2
|
import { BooleanType } from './types/BooleanType.js';
|
|
3
3
|
import { NumberType } from './types/NumberType.js';
|
|
4
4
|
import { StringType } from './types/StringType.js';
|
|
5
|
-
import {
|
|
5
|
+
import { Int64Type } from './types/Int64Type.js';
|
|
6
6
|
import { VoidType } from './types/VoidType.js';
|
|
7
7
|
import { ArrayType } from './types/ArrayType.js';
|
|
8
8
|
import { FunctionType } from './types/FunctionType.js';
|
|
@@ -25,10 +25,11 @@ import { getBaseTypes, getHybridObjectNitroModuleConfig } from '../utils.js';
|
|
|
25
25
|
import { DateType } from './types/DateType.js';
|
|
26
26
|
import { NitroConfig } from '../config/NitroConfig.js';
|
|
27
27
|
import { CustomType } from './types/CustomType.js';
|
|
28
|
-
import { isSyncFunction, isArrayBuffer, isCustomType, isDate, isError, isMap, isPromise, isRecord, } from './isCoreType.js';
|
|
28
|
+
import { isSyncFunction, isArrayBuffer, isCustomType, isDate, isError, isMap, isPromise, isRecord, isInt64, isUInt64, } from './isCoreType.js';
|
|
29
29
|
import { getCustomTypeConfig } from './getCustomTypeConfig.js';
|
|
30
30
|
import { compareLooselyness } from './helpers.js';
|
|
31
31
|
import { NullType } from './types/NullType.js';
|
|
32
|
+
import { UInt64Type } from './types/UInt64Type.js';
|
|
32
33
|
function getHybridObjectName(type) {
|
|
33
34
|
const symbol = isHybridView(type) ? type.getAliasSymbol() : type.getSymbol();
|
|
34
35
|
if (symbol == null) {
|
|
@@ -145,8 +146,11 @@ export function createType(language, type, isOptional) {
|
|
|
145
146
|
else if (type.isString()) {
|
|
146
147
|
return new StringType();
|
|
147
148
|
}
|
|
148
|
-
else if (
|
|
149
|
-
return new
|
|
149
|
+
else if (isInt64(type)) {
|
|
150
|
+
return new Int64Type();
|
|
151
|
+
}
|
|
152
|
+
else if (isUInt64(type)) {
|
|
153
|
+
return new UInt64Type();
|
|
150
154
|
}
|
|
151
155
|
else if (type.isVoid()) {
|
|
152
156
|
return new VoidType();
|
|
@@ -309,6 +313,12 @@ export function createType(language, type, isOptional) {
|
|
|
309
313
|
else if (type.isAny()) {
|
|
310
314
|
throw new Error(`The TypeScript type "${type.getText()}" resolved to any - any is not supported in Nitro.`);
|
|
311
315
|
}
|
|
316
|
+
else if (type.isBigInt()) {
|
|
317
|
+
throw new Error(`Using a bigint without specifying signedness is deprecated! Use \`Int64\` or \`UInt64\` instead.`);
|
|
318
|
+
}
|
|
319
|
+
else if (type.isLiteral()) {
|
|
320
|
+
throw new Error(`The literal "${type.getLiteralValue()}" cannot be used as a type!`);
|
|
321
|
+
}
|
|
312
322
|
else {
|
|
313
323
|
if (type.getSymbol() == null) {
|
|
314
324
|
// There is no declaration for it!
|
package/lib/syntax/helpers.js
CHANGED
|
@@ -7,3 +7,5 @@ export declare function isMap(type: TSMorphType): boolean;
|
|
|
7
7
|
export declare function isError(type: TSMorphType): boolean;
|
|
8
8
|
export declare function isCustomType(type: TSMorphType): boolean;
|
|
9
9
|
export declare function isSyncFunction(type: TSMorphType): boolean;
|
|
10
|
+
export declare function isInt64(type: TSMorphType): boolean;
|
|
11
|
+
export declare function isUInt64(type: TSMorphType): boolean;
|
package/lib/syntax/isCoreType.js
CHANGED
|
@@ -45,3 +45,23 @@ export function isSyncFunction(type) {
|
|
|
45
45
|
const syncTag = type.getProperty('__syncTag');
|
|
46
46
|
return syncTag != null;
|
|
47
47
|
}
|
|
48
|
+
export function isInt64(type) {
|
|
49
|
+
// Int64 is an intersection: `bigint & {...}`
|
|
50
|
+
const isBigInt = type.getIntersectionTypes().some((i) => i.isBigInt());
|
|
51
|
+
if (!isBigInt) {
|
|
52
|
+
// not a bigint
|
|
53
|
+
return false;
|
|
54
|
+
}
|
|
55
|
+
const signedTag = type.getProperty('__signedTag');
|
|
56
|
+
return signedTag != null;
|
|
57
|
+
}
|
|
58
|
+
export function isUInt64(type) {
|
|
59
|
+
// UInt64 is an intersection: `bigint & {...}`
|
|
60
|
+
const isBigInt = type.getIntersectionTypes().some((i) => i.isBigInt());
|
|
61
|
+
if (!isBigInt) {
|
|
62
|
+
// not a bigint
|
|
63
|
+
return false;
|
|
64
|
+
}
|
|
65
|
+
const unsignedTag = type.getProperty('__unsignedTag');
|
|
66
|
+
return unsignedTag != null;
|
|
67
|
+
}
|
|
@@ -9,7 +9,10 @@ export function getKotlinBoxedPrimitiveType(type) {
|
|
|
9
9
|
return 'jni::JDouble';
|
|
10
10
|
case 'boolean':
|
|
11
11
|
return 'jni::JBoolean';
|
|
12
|
-
case '
|
|
12
|
+
case 'int64':
|
|
13
|
+
return 'jni::JLong';
|
|
14
|
+
case 'uint64':
|
|
15
|
+
// this sucks, but ULong is actually Long in JNI. We have to reinterpret it.
|
|
13
16
|
return 'jni::JLong';
|
|
14
17
|
default:
|
|
15
18
|
throw new Error(`Type ${type.kind} is not a primitive!`);
|
|
@@ -47,6 +47,9 @@ export class KotlinCxxBridgedType {
|
|
|
47
47
|
const keyType = new KotlinCxxBridgedType(record.keyType);
|
|
48
48
|
const valueType = new KotlinCxxBridgedType(record.valueType);
|
|
49
49
|
return keyType.needsSpecialHandling || valueType.needsSpecialHandling;
|
|
50
|
+
case 'uint64':
|
|
51
|
+
// ULong == Long, we need to cast
|
|
52
|
+
return true;
|
|
50
53
|
default:
|
|
51
54
|
break;
|
|
52
55
|
}
|
|
@@ -216,9 +219,12 @@ export class KotlinCxxBridgedType {
|
|
|
216
219
|
case 'void':
|
|
217
220
|
case 'number':
|
|
218
221
|
case 'boolean':
|
|
219
|
-
case '
|
|
222
|
+
case 'int64':
|
|
220
223
|
// primitives are not references
|
|
221
224
|
return this.getTypeCode('c++');
|
|
225
|
+
case 'uint64':
|
|
226
|
+
// ULong is unfortunately not representable in JNI. It's long + cast
|
|
227
|
+
return 'jlong';
|
|
222
228
|
default:
|
|
223
229
|
return `jni::${referenceType}_ref<${this.getTypeCode('c++')}>`;
|
|
224
230
|
}
|
|
@@ -226,8 +232,8 @@ export class KotlinCxxBridgedType {
|
|
|
226
232
|
getTypeCode(language, isBoxed = false) {
|
|
227
233
|
switch (this.type.kind) {
|
|
228
234
|
case 'number':
|
|
229
|
-
case 'bigint':
|
|
230
235
|
case 'boolean':
|
|
236
|
+
case 'int64':
|
|
231
237
|
if (isBoxed) {
|
|
232
238
|
return getKotlinBoxedPrimitiveType(this.type);
|
|
233
239
|
}
|
|
@@ -238,6 +244,21 @@ export class KotlinCxxBridgedType {
|
|
|
238
244
|
}
|
|
239
245
|
return this.type.getCode(language);
|
|
240
246
|
}
|
|
247
|
+
case 'uint64':
|
|
248
|
+
// ULong is unfortunately not representable in JNI. It's long + cast
|
|
249
|
+
switch (language) {
|
|
250
|
+
case 'c++':
|
|
251
|
+
if (isBoxed) {
|
|
252
|
+
return 'jni::JLong';
|
|
253
|
+
}
|
|
254
|
+
else {
|
|
255
|
+
return 'jlong';
|
|
256
|
+
}
|
|
257
|
+
case 'kotlin':
|
|
258
|
+
return 'Long';
|
|
259
|
+
default:
|
|
260
|
+
return this.type.getCode(language);
|
|
261
|
+
}
|
|
241
262
|
case 'array':
|
|
242
263
|
const array = getTypeAs(this.type, ArrayType);
|
|
243
264
|
const bridgedItem = new KotlinCxxBridgedType(array.itemType);
|
|
@@ -248,7 +269,10 @@ export class KotlinCxxBridgedType {
|
|
|
248
269
|
return 'jni::JArrayDouble';
|
|
249
270
|
case 'boolean':
|
|
250
271
|
return 'jni::JArrayBoolean';
|
|
251
|
-
case '
|
|
272
|
+
case 'int64':
|
|
273
|
+
return 'jni::JArrayLong';
|
|
274
|
+
case 'uint64':
|
|
275
|
+
// ULong is Long, we have to reinterpret cast it
|
|
252
276
|
return 'jni::JArrayLong';
|
|
253
277
|
default:
|
|
254
278
|
return `jni::JArrayClass<${bridgedItem.getTypeCode(language)}>`;
|
|
@@ -259,7 +283,10 @@ export class KotlinCxxBridgedType {
|
|
|
259
283
|
return 'DoubleArray';
|
|
260
284
|
case 'boolean':
|
|
261
285
|
return 'BooleanArray';
|
|
262
|
-
case '
|
|
286
|
+
case 'int64':
|
|
287
|
+
return 'LongArray';
|
|
288
|
+
case 'uint64':
|
|
289
|
+
// ULong is Long, we have to reinterpret cast it
|
|
263
290
|
return 'LongArray';
|
|
264
291
|
default:
|
|
265
292
|
return `Array<${bridgedItem.getTypeCode(language)}>`;
|
|
@@ -377,7 +404,8 @@ export class KotlinCxxBridgedType {
|
|
|
377
404
|
// primitives need to be boxed to make them nullable
|
|
378
405
|
case 'number':
|
|
379
406
|
case 'boolean':
|
|
380
|
-
case '
|
|
407
|
+
case 'int64':
|
|
408
|
+
case 'uint64':
|
|
381
409
|
const boxed = getKotlinBoxedPrimitiveType(optional.wrappingType);
|
|
382
410
|
return boxed;
|
|
383
411
|
default:
|
|
@@ -431,7 +459,8 @@ export class KotlinCxxBridgedType {
|
|
|
431
459
|
switch (this.type.kind) {
|
|
432
460
|
case 'number':
|
|
433
461
|
case 'boolean':
|
|
434
|
-
case '
|
|
462
|
+
case 'int64':
|
|
463
|
+
case 'uint64':
|
|
435
464
|
switch (language) {
|
|
436
465
|
case 'c++':
|
|
437
466
|
if (isBoxed) {
|
|
@@ -442,6 +471,14 @@ export class KotlinCxxBridgedType {
|
|
|
442
471
|
else {
|
|
443
472
|
return parameterName;
|
|
444
473
|
}
|
|
474
|
+
case 'kotlin':
|
|
475
|
+
switch (this.type.kind) {
|
|
476
|
+
case 'uint64':
|
|
477
|
+
// Long -> ULong
|
|
478
|
+
return `${parameterName}.toULong()`;
|
|
479
|
+
default:
|
|
480
|
+
return parameterName;
|
|
481
|
+
}
|
|
445
482
|
default:
|
|
446
483
|
return parameterName;
|
|
447
484
|
}
|
|
@@ -584,7 +621,8 @@ export class KotlinCxxBridgedType {
|
|
|
584
621
|
switch (array.itemType.kind) {
|
|
585
622
|
case 'number':
|
|
586
623
|
case 'boolean':
|
|
587
|
-
case '
|
|
624
|
+
case 'int64':
|
|
625
|
+
case 'uint64': {
|
|
588
626
|
// primitive arrays can be constructed more efficiently with region/batch access.
|
|
589
627
|
// no need to iterate through the entire array.
|
|
590
628
|
return `
|
|
@@ -685,9 +723,10 @@ export class KotlinCxxBridgedType {
|
|
|
685
723
|
}
|
|
686
724
|
parseFromKotlinToCpp(parameterName, language, isBoxed = false) {
|
|
687
725
|
switch (this.type.kind) {
|
|
688
|
-
case 'number':
|
|
689
726
|
case 'boolean':
|
|
690
|
-
case '
|
|
727
|
+
case 'number':
|
|
728
|
+
case 'int64':
|
|
729
|
+
case 'uint64':
|
|
691
730
|
switch (language) {
|
|
692
731
|
case 'c++':
|
|
693
732
|
let code;
|
|
@@ -699,11 +738,27 @@ export class KotlinCxxBridgedType {
|
|
|
699
738
|
// it's just the primitive type directly
|
|
700
739
|
code = parameterName;
|
|
701
740
|
}
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
741
|
+
switch (this.type.kind) {
|
|
742
|
+
case 'boolean':
|
|
743
|
+
// jboolean =/= bool (it's a char in Java)
|
|
744
|
+
code = `static_cast<bool>(${code})`;
|
|
745
|
+
break;
|
|
746
|
+
case 'uint64':
|
|
747
|
+
// jlong =/= uint64 (it's signed in Java)
|
|
748
|
+
code = `static_cast<uint64_t>(${code})`;
|
|
749
|
+
break;
|
|
750
|
+
default:
|
|
751
|
+
break;
|
|
705
752
|
}
|
|
706
753
|
return code;
|
|
754
|
+
case 'kotlin':
|
|
755
|
+
switch (this.type.kind) {
|
|
756
|
+
case 'uint64':
|
|
757
|
+
// ULong -> Long
|
|
758
|
+
return `${parameterName}.toLong()`;
|
|
759
|
+
default:
|
|
760
|
+
return parameterName;
|
|
761
|
+
}
|
|
707
762
|
default:
|
|
708
763
|
return parameterName;
|
|
709
764
|
}
|
|
@@ -849,7 +904,8 @@ export class KotlinCxxBridgedType {
|
|
|
849
904
|
switch (array.itemType.kind) {
|
|
850
905
|
case 'number':
|
|
851
906
|
case 'boolean':
|
|
852
|
-
case '
|
|
907
|
+
case 'int64':
|
|
908
|
+
case 'uint64': {
|
|
853
909
|
// primitive arrays can use region/batch access,
|
|
854
910
|
// which we can use to construct the vector directly instead of looping through it.
|
|
855
911
|
return `
|
|
@@ -4,7 +4,8 @@ import { getTypeAs } from '../types/getTypeAs.js';
|
|
|
4
4
|
import { OptionalType } from '../types/OptionalType.js';
|
|
5
5
|
function isPrimitive(type) {
|
|
6
6
|
switch (type.kind) {
|
|
7
|
-
case '
|
|
7
|
+
case 'int64':
|
|
8
|
+
case 'uint64':
|
|
8
9
|
case 'boolean':
|
|
9
10
|
case 'number':
|
|
10
11
|
case 'string':
|
|
@@ -27,7 +27,10 @@ export class ArrayType {
|
|
|
27
27
|
return 'DoubleArray';
|
|
28
28
|
case 'boolean':
|
|
29
29
|
return 'BooleanArray';
|
|
30
|
-
case '
|
|
30
|
+
case 'int64':
|
|
31
|
+
return 'LongArray';
|
|
32
|
+
case 'uint64':
|
|
33
|
+
// ULong is just interpret as LongArray in Java.
|
|
31
34
|
return 'LongArray';
|
|
32
35
|
default:
|
|
33
36
|
return `Array<${itemCode}>`;
|
|
@@ -2,6 +2,8 @@ import type { Language } from '../../getPlatformSpecs.js';
|
|
|
2
2
|
import type { SourceFile, SourceImport } from '../SourceFile.js';
|
|
3
3
|
import type { Type, TypeKind } from './Type.js';
|
|
4
4
|
export declare class BigIntType implements Type {
|
|
5
|
+
private signed;
|
|
6
|
+
constructor(signed: boolean);
|
|
5
7
|
get canBePassedByReference(): boolean;
|
|
6
8
|
get kind(): TypeKind;
|
|
7
9
|
get isEquatable(): boolean;
|
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
export class BigIntType {
|
|
2
|
+
signed;
|
|
3
|
+
constructor(signed) {
|
|
4
|
+
this.signed = signed;
|
|
5
|
+
}
|
|
2
6
|
get canBePassedByReference() {
|
|
3
7
|
// It's a primitive.
|
|
4
8
|
return false;
|
|
@@ -10,15 +14,29 @@ export class BigIntType {
|
|
|
10
14
|
return true;
|
|
11
15
|
}
|
|
12
16
|
getCode(language) {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
17
|
+
if (this.signed) {
|
|
18
|
+
switch (language) {
|
|
19
|
+
case 'c++':
|
|
20
|
+
return 'int64_t';
|
|
21
|
+
case 'swift':
|
|
22
|
+
return 'Int64';
|
|
23
|
+
case 'kotlin':
|
|
24
|
+
return 'Long';
|
|
25
|
+
default:
|
|
26
|
+
throw new Error(`Language ${language} is not yet supported for BigIntType!`);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
switch (language) {
|
|
31
|
+
case 'c++':
|
|
32
|
+
return 'uint64_t';
|
|
33
|
+
case 'swift':
|
|
34
|
+
return 'UInt64';
|
|
35
|
+
case 'kotlin':
|
|
36
|
+
return 'ULong';
|
|
37
|
+
default:
|
|
38
|
+
throw new Error(`Language ${language} is not yet supported for BigIntType!`);
|
|
39
|
+
}
|
|
22
40
|
}
|
|
23
41
|
}
|
|
24
42
|
getExtraFiles() {
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Language } from '../../getPlatformSpecs.js';
|
|
2
|
+
import type { SourceFile, SourceImport } from '../SourceFile.js';
|
|
3
|
+
import type { Type, TypeKind } from './Type.js';
|
|
4
|
+
export declare class Int64Type implements Type {
|
|
5
|
+
get canBePassedByReference(): boolean;
|
|
6
|
+
get kind(): TypeKind;
|
|
7
|
+
get isEquatable(): boolean;
|
|
8
|
+
getCode(language: Language): string;
|
|
9
|
+
getExtraFiles(): SourceFile[];
|
|
10
|
+
getRequiredImports(): SourceImport[];
|
|
11
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
export class Int64Type {
|
|
2
|
+
get canBePassedByReference() {
|
|
3
|
+
// It's a primitive.
|
|
4
|
+
return false;
|
|
5
|
+
}
|
|
6
|
+
get kind() {
|
|
7
|
+
return 'int64';
|
|
8
|
+
}
|
|
9
|
+
get isEquatable() {
|
|
10
|
+
return true;
|
|
11
|
+
}
|
|
12
|
+
getCode(language) {
|
|
13
|
+
switch (language) {
|
|
14
|
+
case 'c++':
|
|
15
|
+
return 'int64_t';
|
|
16
|
+
case 'swift':
|
|
17
|
+
return 'Int64';
|
|
18
|
+
case 'kotlin':
|
|
19
|
+
return 'Long';
|
|
20
|
+
default:
|
|
21
|
+
throw new Error(`Language ${language} is not yet supported for Int64Type!`);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
getExtraFiles() {
|
|
25
|
+
return [];
|
|
26
|
+
}
|
|
27
|
+
getRequiredImports() {
|
|
28
|
+
return [];
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Language } from '../../getPlatformSpecs.js';
|
|
2
2
|
import type { SourceFile, SourceImport } from '../SourceFile.js';
|
|
3
|
-
export type TypeKind = 'array-buffer' | 'array' | '
|
|
3
|
+
export type TypeKind = 'array-buffer' | 'array' | 'int64' | 'uint64' | 'boolean' | 'custom-type' | 'enum' | 'error' | 'function' | 'hybrid-object' | 'hybrid-object-base' | 'map' | 'null' | 'number' | 'optional' | 'promise' | 'record' | 'string' | 'struct' | 'tuple' | 'variant' | 'result-wrapper' | 'date' | 'void';
|
|
4
4
|
export interface GetCodeOptions {
|
|
5
5
|
/**
|
|
6
6
|
* Specifies whether the name (e.g. a C++ class name)
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Language } from '../../getPlatformSpecs.js';
|
|
2
|
+
import type { SourceFile, SourceImport } from '../SourceFile.js';
|
|
3
|
+
import type { Type, TypeKind } from './Type.js';
|
|
4
|
+
export declare class UInt64Type implements Type {
|
|
5
|
+
get canBePassedByReference(): boolean;
|
|
6
|
+
get kind(): TypeKind;
|
|
7
|
+
get isEquatable(): boolean;
|
|
8
|
+
getCode(language: Language): string;
|
|
9
|
+
getExtraFiles(): SourceFile[];
|
|
10
|
+
getRequiredImports(): SourceImport[];
|
|
11
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
export class UInt64Type {
|
|
2
|
+
get canBePassedByReference() {
|
|
3
|
+
// It's a primitive.
|
|
4
|
+
return false;
|
|
5
|
+
}
|
|
6
|
+
get kind() {
|
|
7
|
+
return 'uint64';
|
|
8
|
+
}
|
|
9
|
+
get isEquatable() {
|
|
10
|
+
return true;
|
|
11
|
+
}
|
|
12
|
+
getCode(language) {
|
|
13
|
+
switch (language) {
|
|
14
|
+
case 'c++':
|
|
15
|
+
return 'uint64_t';
|
|
16
|
+
case 'swift':
|
|
17
|
+
return 'UInt64';
|
|
18
|
+
case 'kotlin':
|
|
19
|
+
return 'ULong';
|
|
20
|
+
default:
|
|
21
|
+
throw new Error(`Language ${language} is not yet supported for UInt64Type!`);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
getExtraFiles() {
|
|
25
|
+
return [];
|
|
26
|
+
}
|
|
27
|
+
getRequiredImports() {
|
|
28
|
+
return [];
|
|
29
|
+
}
|
|
30
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nitrogen",
|
|
3
|
-
"version": "0.33.
|
|
3
|
+
"version": "0.33.8",
|
|
4
4
|
"description": "The code-generator for react-native-nitro-modules.",
|
|
5
5
|
"main": "lib/index",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
37
|
"chalk": "^5.3.0",
|
|
38
|
-
"react-native-nitro-modules": "^0.33.
|
|
38
|
+
"react-native-nitro-modules": "^0.33.8",
|
|
39
39
|
"ts-morph": "^27.0.0",
|
|
40
40
|
"yargs": "^18.0.0",
|
|
41
41
|
"zod": "^4.0.5"
|
package/src/syntax/createType.ts
CHANGED
|
@@ -3,7 +3,7 @@ import type { Type } from './types/Type.js'
|
|
|
3
3
|
import { BooleanType } from './types/BooleanType.js'
|
|
4
4
|
import { NumberType } from './types/NumberType.js'
|
|
5
5
|
import { StringType } from './types/StringType.js'
|
|
6
|
-
import {
|
|
6
|
+
import { Int64Type } from './types/Int64Type.js'
|
|
7
7
|
import { VoidType } from './types/VoidType.js'
|
|
8
8
|
import { ArrayType } from './types/ArrayType.js'
|
|
9
9
|
import { FunctionType } from './types/FunctionType.js'
|
|
@@ -40,10 +40,13 @@ import {
|
|
|
40
40
|
isMap,
|
|
41
41
|
isPromise,
|
|
42
42
|
isRecord,
|
|
43
|
+
isInt64,
|
|
44
|
+
isUInt64,
|
|
43
45
|
} from './isCoreType.js'
|
|
44
46
|
import { getCustomTypeConfig } from './getCustomTypeConfig.js'
|
|
45
47
|
import { compareLooselyness } from './helpers.js'
|
|
46
48
|
import { NullType } from './types/NullType.js'
|
|
49
|
+
import { UInt64Type } from './types/UInt64Type.js'
|
|
47
50
|
|
|
48
51
|
function getHybridObjectName(type: TSMorphType): string {
|
|
49
52
|
const symbol = isHybridView(type) ? type.getAliasSymbol() : type.getSymbol()
|
|
@@ -205,8 +208,10 @@ export function createType(
|
|
|
205
208
|
return new NumberType()
|
|
206
209
|
} else if (type.isString()) {
|
|
207
210
|
return new StringType()
|
|
208
|
-
} else if (
|
|
209
|
-
return new
|
|
211
|
+
} else if (isInt64(type)) {
|
|
212
|
+
return new Int64Type()
|
|
213
|
+
} else if (isUInt64(type)) {
|
|
214
|
+
return new UInt64Type()
|
|
210
215
|
} else if (type.isVoid()) {
|
|
211
216
|
return new VoidType()
|
|
212
217
|
} else if (type.isArray()) {
|
|
@@ -367,6 +372,14 @@ export function createType(
|
|
|
367
372
|
throw new Error(
|
|
368
373
|
`The TypeScript type "${type.getText()}" resolved to any - any is not supported in Nitro.`
|
|
369
374
|
)
|
|
375
|
+
} else if (type.isBigInt()) {
|
|
376
|
+
throw new Error(
|
|
377
|
+
`Using a bigint without specifying signedness is deprecated! Use \`Int64\` or \`UInt64\` instead.`
|
|
378
|
+
)
|
|
379
|
+
} else if (type.isLiteral()) {
|
|
380
|
+
throw new Error(
|
|
381
|
+
`The literal "${type.getLiteralValue()}" cannot be used as a type!`
|
|
382
|
+
)
|
|
370
383
|
} else {
|
|
371
384
|
if (type.getSymbol() == null) {
|
|
372
385
|
// There is no declaration for it!
|
package/src/syntax/helpers.ts
CHANGED
package/src/syntax/isCoreType.ts
CHANGED
|
@@ -58,3 +58,24 @@ export function isSyncFunction(type: TSMorphType): boolean {
|
|
|
58
58
|
const syncTag = type.getProperty('__syncTag')
|
|
59
59
|
return syncTag != null
|
|
60
60
|
}
|
|
61
|
+
|
|
62
|
+
export function isInt64(type: TSMorphType): boolean {
|
|
63
|
+
// Int64 is an intersection: `bigint & {...}`
|
|
64
|
+
const isBigInt = type.getIntersectionTypes().some((i) => i.isBigInt())
|
|
65
|
+
if (!isBigInt) {
|
|
66
|
+
// not a bigint
|
|
67
|
+
return false
|
|
68
|
+
}
|
|
69
|
+
const signedTag = type.getProperty('__signedTag')
|
|
70
|
+
return signedTag != null
|
|
71
|
+
}
|
|
72
|
+
export function isUInt64(type: TSMorphType): boolean {
|
|
73
|
+
// UInt64 is an intersection: `bigint & {...}`
|
|
74
|
+
const isBigInt = type.getIntersectionTypes().some((i) => i.isBigInt())
|
|
75
|
+
if (!isBigInt) {
|
|
76
|
+
// not a bigint
|
|
77
|
+
return false
|
|
78
|
+
}
|
|
79
|
+
const unsignedTag = type.getProperty('__unsignedTag')
|
|
80
|
+
return unsignedTag != null
|
|
81
|
+
}
|
|
@@ -11,7 +11,10 @@ export function getKotlinBoxedPrimitiveType(type: Type): string {
|
|
|
11
11
|
return 'jni::JDouble'
|
|
12
12
|
case 'boolean':
|
|
13
13
|
return 'jni::JBoolean'
|
|
14
|
-
case '
|
|
14
|
+
case 'int64':
|
|
15
|
+
return 'jni::JLong'
|
|
16
|
+
case 'uint64':
|
|
17
|
+
// this sucks, but ULong is actually Long in JNI. We have to reinterpret it.
|
|
15
18
|
return 'jni::JLong'
|
|
16
19
|
default:
|
|
17
20
|
throw new Error(`Type ${type.kind} is not a primitive!`)
|
|
@@ -56,6 +56,9 @@ export class KotlinCxxBridgedType implements BridgedType<'kotlin', 'c++'> {
|
|
|
56
56
|
const keyType = new KotlinCxxBridgedType(record.keyType)
|
|
57
57
|
const valueType = new KotlinCxxBridgedType(record.valueType)
|
|
58
58
|
return keyType.needsSpecialHandling || valueType.needsSpecialHandling
|
|
59
|
+
case 'uint64':
|
|
60
|
+
// ULong == Long, we need to cast
|
|
61
|
+
return true
|
|
59
62
|
default:
|
|
60
63
|
break
|
|
61
64
|
}
|
|
@@ -233,9 +236,12 @@ export class KotlinCxxBridgedType implements BridgedType<'kotlin', 'c++'> {
|
|
|
233
236
|
case 'void':
|
|
234
237
|
case 'number':
|
|
235
238
|
case 'boolean':
|
|
236
|
-
case '
|
|
239
|
+
case 'int64':
|
|
237
240
|
// primitives are not references
|
|
238
241
|
return this.getTypeCode('c++')
|
|
242
|
+
case 'uint64':
|
|
243
|
+
// ULong is unfortunately not representable in JNI. It's long + cast
|
|
244
|
+
return 'jlong'
|
|
239
245
|
default:
|
|
240
246
|
return `jni::${referenceType}_ref<${this.getTypeCode('c++')}>`
|
|
241
247
|
}
|
|
@@ -244,8 +250,8 @@ export class KotlinCxxBridgedType implements BridgedType<'kotlin', 'c++'> {
|
|
|
244
250
|
getTypeCode(language: 'kotlin' | 'c++', isBoxed = false): string {
|
|
245
251
|
switch (this.type.kind) {
|
|
246
252
|
case 'number':
|
|
247
|
-
case 'bigint':
|
|
248
253
|
case 'boolean':
|
|
254
|
+
case 'int64':
|
|
249
255
|
if (isBoxed) {
|
|
250
256
|
return getKotlinBoxedPrimitiveType(this.type)
|
|
251
257
|
} else {
|
|
@@ -255,6 +261,20 @@ export class KotlinCxxBridgedType implements BridgedType<'kotlin', 'c++'> {
|
|
|
255
261
|
}
|
|
256
262
|
return this.type.getCode(language)
|
|
257
263
|
}
|
|
264
|
+
case 'uint64':
|
|
265
|
+
// ULong is unfortunately not representable in JNI. It's long + cast
|
|
266
|
+
switch (language) {
|
|
267
|
+
case 'c++':
|
|
268
|
+
if (isBoxed) {
|
|
269
|
+
return 'jni::JLong'
|
|
270
|
+
} else {
|
|
271
|
+
return 'jlong'
|
|
272
|
+
}
|
|
273
|
+
case 'kotlin':
|
|
274
|
+
return 'Long'
|
|
275
|
+
default:
|
|
276
|
+
return this.type.getCode(language)
|
|
277
|
+
}
|
|
258
278
|
case 'array':
|
|
259
279
|
const array = getTypeAs(this.type, ArrayType)
|
|
260
280
|
const bridgedItem = new KotlinCxxBridgedType(array.itemType)
|
|
@@ -265,7 +285,10 @@ export class KotlinCxxBridgedType implements BridgedType<'kotlin', 'c++'> {
|
|
|
265
285
|
return 'jni::JArrayDouble'
|
|
266
286
|
case 'boolean':
|
|
267
287
|
return 'jni::JArrayBoolean'
|
|
268
|
-
case '
|
|
288
|
+
case 'int64':
|
|
289
|
+
return 'jni::JArrayLong'
|
|
290
|
+
case 'uint64':
|
|
291
|
+
// ULong is Long, we have to reinterpret cast it
|
|
269
292
|
return 'jni::JArrayLong'
|
|
270
293
|
default:
|
|
271
294
|
return `jni::JArrayClass<${bridgedItem.getTypeCode(language)}>`
|
|
@@ -276,7 +299,10 @@ export class KotlinCxxBridgedType implements BridgedType<'kotlin', 'c++'> {
|
|
|
276
299
|
return 'DoubleArray'
|
|
277
300
|
case 'boolean':
|
|
278
301
|
return 'BooleanArray'
|
|
279
|
-
case '
|
|
302
|
+
case 'int64':
|
|
303
|
+
return 'LongArray'
|
|
304
|
+
case 'uint64':
|
|
305
|
+
// ULong is Long, we have to reinterpret cast it
|
|
280
306
|
return 'LongArray'
|
|
281
307
|
default:
|
|
282
308
|
return `Array<${bridgedItem.getTypeCode(language)}>`
|
|
@@ -400,7 +426,8 @@ export class KotlinCxxBridgedType implements BridgedType<'kotlin', 'c++'> {
|
|
|
400
426
|
// primitives need to be boxed to make them nullable
|
|
401
427
|
case 'number':
|
|
402
428
|
case 'boolean':
|
|
403
|
-
case '
|
|
429
|
+
case 'int64':
|
|
430
|
+
case 'uint64':
|
|
404
431
|
const boxed = getKotlinBoxedPrimitiveType(optional.wrappingType)
|
|
405
432
|
return boxed
|
|
406
433
|
default:
|
|
@@ -464,7 +491,8 @@ export class KotlinCxxBridgedType implements BridgedType<'kotlin', 'c++'> {
|
|
|
464
491
|
switch (this.type.kind) {
|
|
465
492
|
case 'number':
|
|
466
493
|
case 'boolean':
|
|
467
|
-
case '
|
|
494
|
+
case 'int64':
|
|
495
|
+
case 'uint64':
|
|
468
496
|
switch (language) {
|
|
469
497
|
case 'c++':
|
|
470
498
|
if (isBoxed) {
|
|
@@ -474,6 +502,14 @@ export class KotlinCxxBridgedType implements BridgedType<'kotlin', 'c++'> {
|
|
|
474
502
|
} else {
|
|
475
503
|
return parameterName
|
|
476
504
|
}
|
|
505
|
+
case 'kotlin':
|
|
506
|
+
switch (this.type.kind) {
|
|
507
|
+
case 'uint64':
|
|
508
|
+
// Long -> ULong
|
|
509
|
+
return `${parameterName}.toULong()`
|
|
510
|
+
default:
|
|
511
|
+
return parameterName
|
|
512
|
+
}
|
|
477
513
|
default:
|
|
478
514
|
return parameterName
|
|
479
515
|
}
|
|
@@ -623,7 +659,8 @@ export class KotlinCxxBridgedType implements BridgedType<'kotlin', 'c++'> {
|
|
|
623
659
|
switch (array.itemType.kind) {
|
|
624
660
|
case 'number':
|
|
625
661
|
case 'boolean':
|
|
626
|
-
case '
|
|
662
|
+
case 'int64':
|
|
663
|
+
case 'uint64': {
|
|
627
664
|
// primitive arrays can be constructed more efficiently with region/batch access.
|
|
628
665
|
// no need to iterate through the entire array.
|
|
629
666
|
return `
|
|
@@ -731,9 +768,10 @@ export class KotlinCxxBridgedType implements BridgedType<'kotlin', 'c++'> {
|
|
|
731
768
|
isBoxed = false
|
|
732
769
|
): string {
|
|
733
770
|
switch (this.type.kind) {
|
|
734
|
-
case 'number':
|
|
735
771
|
case 'boolean':
|
|
736
|
-
case '
|
|
772
|
+
case 'number':
|
|
773
|
+
case 'int64':
|
|
774
|
+
case 'uint64':
|
|
737
775
|
switch (language) {
|
|
738
776
|
case 'c++':
|
|
739
777
|
let code: string
|
|
@@ -744,11 +782,27 @@ export class KotlinCxxBridgedType implements BridgedType<'kotlin', 'c++'> {
|
|
|
744
782
|
// it's just the primitive type directly
|
|
745
783
|
code = parameterName
|
|
746
784
|
}
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
785
|
+
switch (this.type.kind) {
|
|
786
|
+
case 'boolean':
|
|
787
|
+
// jboolean =/= bool (it's a char in Java)
|
|
788
|
+
code = `static_cast<bool>(${code})`
|
|
789
|
+
break
|
|
790
|
+
case 'uint64':
|
|
791
|
+
// jlong =/= uint64 (it's signed in Java)
|
|
792
|
+
code = `static_cast<uint64_t>(${code})`
|
|
793
|
+
break
|
|
794
|
+
default:
|
|
795
|
+
break
|
|
750
796
|
}
|
|
751
797
|
return code
|
|
798
|
+
case 'kotlin':
|
|
799
|
+
switch (this.type.kind) {
|
|
800
|
+
case 'uint64':
|
|
801
|
+
// ULong -> Long
|
|
802
|
+
return `${parameterName}.toLong()`
|
|
803
|
+
default:
|
|
804
|
+
return parameterName
|
|
805
|
+
}
|
|
752
806
|
default:
|
|
753
807
|
return parameterName
|
|
754
808
|
}
|
|
@@ -907,7 +961,8 @@ export class KotlinCxxBridgedType implements BridgedType<'kotlin', 'c++'> {
|
|
|
907
961
|
switch (array.itemType.kind) {
|
|
908
962
|
case 'number':
|
|
909
963
|
case 'boolean':
|
|
910
|
-
case '
|
|
964
|
+
case 'int64':
|
|
965
|
+
case 'uint64': {
|
|
911
966
|
// primitive arrays can use region/batch access,
|
|
912
967
|
// which we can use to construct the vector directly instead of looping through it.
|
|
913
968
|
return `
|
|
@@ -35,7 +35,10 @@ export class ArrayType implements Type {
|
|
|
35
35
|
return 'DoubleArray'
|
|
36
36
|
case 'boolean':
|
|
37
37
|
return 'BooleanArray'
|
|
38
|
-
case '
|
|
38
|
+
case 'int64':
|
|
39
|
+
return 'LongArray'
|
|
40
|
+
case 'uint64':
|
|
41
|
+
// ULong is just interpret as LongArray in Java.
|
|
39
42
|
return 'LongArray'
|
|
40
43
|
default:
|
|
41
44
|
return `Array<${itemCode}>`
|
|
@@ -2,14 +2,14 @@ import type { Language } from '../../getPlatformSpecs.js'
|
|
|
2
2
|
import type { SourceFile, SourceImport } from '../SourceFile.js'
|
|
3
3
|
import type { Type, TypeKind } from './Type.js'
|
|
4
4
|
|
|
5
|
-
export class
|
|
5
|
+
export class Int64Type implements Type {
|
|
6
6
|
get canBePassedByReference(): boolean {
|
|
7
7
|
// It's a primitive.
|
|
8
8
|
return false
|
|
9
9
|
}
|
|
10
10
|
|
|
11
11
|
get kind(): TypeKind {
|
|
12
|
-
return '
|
|
12
|
+
return 'int64'
|
|
13
13
|
}
|
|
14
14
|
get isEquatable(): boolean {
|
|
15
15
|
return true
|
|
@@ -25,7 +25,7 @@ export class BigIntType implements Type {
|
|
|
25
25
|
return 'Long'
|
|
26
26
|
default:
|
|
27
27
|
throw new Error(
|
|
28
|
-
`Language ${language} is not yet supported for
|
|
28
|
+
`Language ${language} is not yet supported for Int64Type!`
|
|
29
29
|
)
|
|
30
30
|
}
|
|
31
31
|
}
|
package/src/syntax/types/Type.ts
CHANGED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { Language } from '../../getPlatformSpecs.js'
|
|
2
|
+
import type { SourceFile, SourceImport } from '../SourceFile.js'
|
|
3
|
+
import type { Type, TypeKind } from './Type.js'
|
|
4
|
+
|
|
5
|
+
export class UInt64Type implements Type {
|
|
6
|
+
get canBePassedByReference(): boolean {
|
|
7
|
+
// It's a primitive.
|
|
8
|
+
return false
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
get kind(): TypeKind {
|
|
12
|
+
return 'uint64'
|
|
13
|
+
}
|
|
14
|
+
get isEquatable(): boolean {
|
|
15
|
+
return true
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
getCode(language: Language): string {
|
|
19
|
+
switch (language) {
|
|
20
|
+
case 'c++':
|
|
21
|
+
return 'uint64_t'
|
|
22
|
+
case 'swift':
|
|
23
|
+
return 'UInt64'
|
|
24
|
+
case 'kotlin':
|
|
25
|
+
return 'ULong'
|
|
26
|
+
default:
|
|
27
|
+
throw new Error(
|
|
28
|
+
`Language ${language} is not yet supported for UInt64Type!`
|
|
29
|
+
)
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
getExtraFiles(): SourceFile[] {
|
|
33
|
+
return []
|
|
34
|
+
}
|
|
35
|
+
getRequiredImports(): SourceImport[] {
|
|
36
|
+
return []
|
|
37
|
+
}
|
|
38
|
+
}
|