nitrogen 0.33.8 → 0.34.0
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/autolinking/android/createHybridObjectInitializer.js +22 -10
- package/lib/syntax/Property.js +32 -9
- package/lib/syntax/helpers.d.ts +0 -1
- package/lib/syntax/helpers.js +0 -3
- package/lib/syntax/swift/SwiftCxxBridgedType.js +8 -4
- package/lib/syntax/swift/SwiftCxxTypeHelper.js +1 -1
- package/package.json +2 -2
- package/src/autolinking/android/createHybridObjectInitializer.ts +22 -10
- package/src/syntax/Property.ts +28 -9
- package/src/syntax/helpers.ts +0 -4
- package/src/syntax/swift/SwiftCxxBridgedType.ts +8 -4
- package/src/syntax/swift/SwiftCxxTypeHelper.ts +1 -1
- package/lib/syntax/types/BigIntType.d.ts +0 -13
- package/lib/syntax/types/BigIntType.js +0 -48
|
@@ -49,21 +49,30 @@ export function createHybridObjectIntializer() {
|
|
|
49
49
|
${createFileMetadataString(`${autolinkingClassName}.hpp`)}
|
|
50
50
|
|
|
51
51
|
#include <jni.h>
|
|
52
|
+
#include <functional>
|
|
52
53
|
#include <NitroModules/NitroDefines.hpp>
|
|
53
54
|
|
|
54
55
|
namespace ${cxxNamespace} {
|
|
55
56
|
|
|
57
|
+
[[deprecated("Use registerNatives() instead.")]]
|
|
58
|
+
int initialize(JavaVM* vm);
|
|
59
|
+
|
|
56
60
|
/**
|
|
57
|
-
*
|
|
58
|
-
* Call this in your \`JNI_OnLoad\` function (probably inside \`cpp-adapter.cpp\`)
|
|
61
|
+
* Register the native (C++) part of ${cppLibName}, and autolinks all Hybrid Objects.
|
|
62
|
+
* Call this in your \`JNI_OnLoad\` function (probably inside \`cpp-adapter.cpp\`),
|
|
63
|
+
* inside a \`facebook::jni::initialize(vm, ...)\` call.
|
|
59
64
|
* Example:
|
|
60
65
|
* \`\`\`cpp (cpp-adapter.cpp)
|
|
61
66
|
* JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM* vm, void*) {
|
|
62
|
-
* return
|
|
67
|
+
* return facebook::jni::initialize(vm, []() {
|
|
68
|
+
* // register all ${cppLibName} HybridObjects
|
|
69
|
+
* ${cxxNamespace}::registerNatives();
|
|
70
|
+
* // any other custom registrations go here.
|
|
71
|
+
* });
|
|
63
72
|
* }
|
|
64
73
|
* \`\`\`
|
|
65
74
|
*/
|
|
66
|
-
|
|
75
|
+
void registerAllNatives();
|
|
67
76
|
|
|
68
77
|
} // namespace ${cxxNamespace}
|
|
69
78
|
|
|
@@ -86,17 +95,20 @@ ${includes}
|
|
|
86
95
|
namespace ${cxxNamespace} {
|
|
87
96
|
|
|
88
97
|
int initialize(JavaVM* vm) {
|
|
98
|
+
return facebook::jni::initialize(vm, []() {
|
|
99
|
+
::${cxxNamespace}::registerAllNatives();
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
void registerAllNatives() {
|
|
89
104
|
using namespace margelo::nitro;
|
|
90
105
|
using namespace ${cxxNamespace};
|
|
91
|
-
using namespace facebook;
|
|
92
106
|
|
|
93
|
-
return facebook::jni::initialize(vm, [] {
|
|
94
107
|
// Register native JNI methods
|
|
95
|
-
|
|
108
|
+
${indent(jniRegistrations.join('\n'), ' ')}
|
|
96
109
|
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
});
|
|
110
|
+
// Register Nitro Hybrid Objects
|
|
111
|
+
${indent(cppRegistrations.join('\n'), ' ')}
|
|
100
112
|
}
|
|
101
113
|
|
|
102
114
|
} // namespace ${cxxNamespace}
|
package/lib/syntax/Property.js
CHANGED
|
@@ -3,7 +3,6 @@ import {} from './SourceFile.js';
|
|
|
3
3
|
import { Method } from './Method.js';
|
|
4
4
|
import { VoidType } from './types/VoidType.js';
|
|
5
5
|
import { Parameter } from './Parameter.js';
|
|
6
|
-
import { isBooleanPropertyPrefix } from './helpers.js';
|
|
7
6
|
export class Property {
|
|
8
7
|
name;
|
|
9
8
|
type;
|
|
@@ -26,13 +25,29 @@ export class Property {
|
|
|
26
25
|
return this.type.getRequiredImports(language);
|
|
27
26
|
}
|
|
28
27
|
getGetterName(environment) {
|
|
29
|
-
if (this.type.kind === 'boolean'
|
|
28
|
+
if (this.type.kind === 'boolean') {
|
|
30
29
|
// Boolean accessors where the property starts with "is" or "has" are renamed in JVM and Swift
|
|
31
30
|
switch (environment) {
|
|
32
31
|
case 'jvm':
|
|
32
|
+
if (this.name.startsWith('is')) {
|
|
33
|
+
// isSomething -> isSomething()
|
|
34
|
+
return this.name;
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
break;
|
|
38
|
+
}
|
|
33
39
|
case 'swift':
|
|
34
|
-
|
|
35
|
-
|
|
40
|
+
if (this.name.startsWith('is')) {
|
|
41
|
+
// isSomething -> isSomething()
|
|
42
|
+
return this.name;
|
|
43
|
+
}
|
|
44
|
+
else if (this.name.startsWith('has')) {
|
|
45
|
+
// hasSomething -> hasSomething()
|
|
46
|
+
return this.name;
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
break;
|
|
50
|
+
}
|
|
36
51
|
default:
|
|
37
52
|
break;
|
|
38
53
|
}
|
|
@@ -41,12 +56,20 @@ export class Property {
|
|
|
41
56
|
return `get${capitalizeName(this.name)}`;
|
|
42
57
|
}
|
|
43
58
|
getSetterName(environment) {
|
|
44
|
-
if (this.type.kind === 'boolean'
|
|
59
|
+
if (this.type.kind === 'boolean') {
|
|
45
60
|
// Boolean accessors where the property starts with "is" are renamed in JVM
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
61
|
+
switch (environment) {
|
|
62
|
+
case 'jvm':
|
|
63
|
+
if (this.name.startsWith('is')) {
|
|
64
|
+
// isSomething -> setSomething()
|
|
65
|
+
const cleanName = this.name.replace('is', '');
|
|
66
|
+
return `set${capitalizeName(cleanName)}`;
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
break;
|
|
70
|
+
}
|
|
71
|
+
default:
|
|
72
|
+
break;
|
|
50
73
|
}
|
|
51
74
|
}
|
|
52
75
|
// isSomething -> setIsSomething()
|
package/lib/syntax/helpers.d.ts
CHANGED
|
@@ -11,7 +11,6 @@ export declare function escapeCppName(string: string): string;
|
|
|
11
11
|
* and a negative number if otherwise.
|
|
12
12
|
*/
|
|
13
13
|
export declare function compareLooselyness(a: Type, b: Type): number;
|
|
14
|
-
export declare function isBooleanPropertyPrefix(name: string): boolean;
|
|
15
14
|
export declare function isNotDuplicate<T>(item: T, index: number, array: T[]): boolean;
|
|
16
15
|
export declare function isCppFile(file: SourceFile): boolean;
|
|
17
16
|
export declare function getRelativeDirectory(file: SourceFile): string;
|
package/lib/syntax/helpers.js
CHANGED
|
@@ -134,9 +134,6 @@ function getTypeLooselyness(type) {
|
|
|
134
134
|
export function compareLooselyness(a, b) {
|
|
135
135
|
return getTypeLooselyness(a) - getTypeLooselyness(b);
|
|
136
136
|
}
|
|
137
|
-
export function isBooleanPropertyPrefix(name) {
|
|
138
|
-
return name.startsWith('is') || name.startsWith('has');
|
|
139
|
-
}
|
|
140
137
|
export function isNotDuplicate(item, index, array) {
|
|
141
138
|
return array.indexOf(item) === index;
|
|
142
139
|
}
|
|
@@ -425,10 +425,14 @@ export class SwiftCxxBridgedType {
|
|
|
425
425
|
return `${cppParameterName}.has_value() ? ${cppParameterName}.pointee : nil`;
|
|
426
426
|
}
|
|
427
427
|
}
|
|
428
|
-
// TODO: Remove this check for booleans once https://github.com/swiftlang/swift/issues/84848 is fixed.
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
428
|
+
// TODO: Remove this check for booleans/doubles once https://github.com/swiftlang/swift/issues/84848 is fixed.
|
|
429
|
+
// Right now, optionals of doubles or booleans (and who knows what else?) fail to compile when `.value` is used.
|
|
430
|
+
const swiftBug84848Workaround = optional.wrappingType.kind === 'boolean' ||
|
|
431
|
+
optional.wrappingType.kind === 'number';
|
|
432
|
+
if (!swiftBug84848Workaround) {
|
|
433
|
+
if (!wrapping.needsSpecialHandling) {
|
|
434
|
+
return `${cppParameterName}.value`;
|
|
435
|
+
}
|
|
432
436
|
}
|
|
433
437
|
return `
|
|
434
438
|
{ () -> ${optional.getCode('swift')} in
|
|
@@ -209,7 +209,7 @@ inline bool has_value_${name}(const ${actualType}& optional) noexcept {
|
|
|
209
209
|
return optional.has_value();
|
|
210
210
|
}
|
|
211
211
|
inline ${wrappedBridge.getTypeCode('c++')} get_${name}(const ${actualType}& optional) noexcept {
|
|
212
|
-
return
|
|
212
|
+
return optional.value();
|
|
213
213
|
}
|
|
214
214
|
`.trim(),
|
|
215
215
|
requiredIncludes: [
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nitrogen",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.34.0",
|
|
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.
|
|
38
|
+
"react-native-nitro-modules": "^0.34.0",
|
|
39
39
|
"ts-morph": "^27.0.0",
|
|
40
40
|
"yargs": "^18.0.0",
|
|
41
41
|
"zod": "^4.0.5"
|
|
@@ -62,21 +62,30 @@ export function createHybridObjectIntializer(): SourceFile[] {
|
|
|
62
62
|
${createFileMetadataString(`${autolinkingClassName}.hpp`)}
|
|
63
63
|
|
|
64
64
|
#include <jni.h>
|
|
65
|
+
#include <functional>
|
|
65
66
|
#include <NitroModules/NitroDefines.hpp>
|
|
66
67
|
|
|
67
68
|
namespace ${cxxNamespace} {
|
|
68
69
|
|
|
70
|
+
[[deprecated("Use registerNatives() instead.")]]
|
|
71
|
+
int initialize(JavaVM* vm);
|
|
72
|
+
|
|
69
73
|
/**
|
|
70
|
-
*
|
|
71
|
-
* Call this in your \`JNI_OnLoad\` function (probably inside \`cpp-adapter.cpp\`)
|
|
74
|
+
* Register the native (C++) part of ${cppLibName}, and autolinks all Hybrid Objects.
|
|
75
|
+
* Call this in your \`JNI_OnLoad\` function (probably inside \`cpp-adapter.cpp\`),
|
|
76
|
+
* inside a \`facebook::jni::initialize(vm, ...)\` call.
|
|
72
77
|
* Example:
|
|
73
78
|
* \`\`\`cpp (cpp-adapter.cpp)
|
|
74
79
|
* JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM* vm, void*) {
|
|
75
|
-
* return
|
|
80
|
+
* return facebook::jni::initialize(vm, []() {
|
|
81
|
+
* // register all ${cppLibName} HybridObjects
|
|
82
|
+
* ${cxxNamespace}::registerNatives();
|
|
83
|
+
* // any other custom registrations go here.
|
|
84
|
+
* });
|
|
76
85
|
* }
|
|
77
86
|
* \`\`\`
|
|
78
87
|
*/
|
|
79
|
-
|
|
88
|
+
void registerAllNatives();
|
|
80
89
|
|
|
81
90
|
} // namespace ${cxxNamespace}
|
|
82
91
|
|
|
@@ -99,17 +108,20 @@ ${includes}
|
|
|
99
108
|
namespace ${cxxNamespace} {
|
|
100
109
|
|
|
101
110
|
int initialize(JavaVM* vm) {
|
|
111
|
+
return facebook::jni::initialize(vm, []() {
|
|
112
|
+
::${cxxNamespace}::registerAllNatives();
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
void registerAllNatives() {
|
|
102
117
|
using namespace margelo::nitro;
|
|
103
118
|
using namespace ${cxxNamespace};
|
|
104
|
-
using namespace facebook;
|
|
105
119
|
|
|
106
|
-
return facebook::jni::initialize(vm, [] {
|
|
107
120
|
// Register native JNI methods
|
|
108
|
-
|
|
121
|
+
${indent(jniRegistrations.join('\n'), ' ')}
|
|
109
122
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
});
|
|
123
|
+
// Register Nitro Hybrid Objects
|
|
124
|
+
${indent(cppRegistrations.join('\n'), ' ')}
|
|
113
125
|
}
|
|
114
126
|
|
|
115
127
|
} // namespace ${cxxNamespace}
|
package/src/syntax/Property.ts
CHANGED
|
@@ -6,7 +6,6 @@ import type { Type } from './types/Type.js'
|
|
|
6
6
|
import { Method } from './Method.js'
|
|
7
7
|
import { VoidType } from './types/VoidType.js'
|
|
8
8
|
import { Parameter } from './Parameter.js'
|
|
9
|
-
import { isBooleanPropertyPrefix } from './helpers.js'
|
|
10
9
|
|
|
11
10
|
export interface PropertyBody {
|
|
12
11
|
getter: string
|
|
@@ -73,13 +72,26 @@ export class Property implements CodeNode {
|
|
|
73
72
|
}
|
|
74
73
|
|
|
75
74
|
getGetterName(environment: LanguageEnvironment): string {
|
|
76
|
-
if (this.type.kind === 'boolean'
|
|
75
|
+
if (this.type.kind === 'boolean') {
|
|
77
76
|
// Boolean accessors where the property starts with "is" or "has" are renamed in JVM and Swift
|
|
78
77
|
switch (environment) {
|
|
79
78
|
case 'jvm':
|
|
79
|
+
if (this.name.startsWith('is')) {
|
|
80
|
+
// isSomething -> isSomething()
|
|
81
|
+
return this.name
|
|
82
|
+
} else {
|
|
83
|
+
break
|
|
84
|
+
}
|
|
80
85
|
case 'swift':
|
|
81
|
-
|
|
82
|
-
|
|
86
|
+
if (this.name.startsWith('is')) {
|
|
87
|
+
// isSomething -> isSomething()
|
|
88
|
+
return this.name
|
|
89
|
+
} else if (this.name.startsWith('has')) {
|
|
90
|
+
// hasSomething -> hasSomething()
|
|
91
|
+
return this.name
|
|
92
|
+
} else {
|
|
93
|
+
break
|
|
94
|
+
}
|
|
83
95
|
default:
|
|
84
96
|
break
|
|
85
97
|
}
|
|
@@ -89,12 +101,19 @@ export class Property implements CodeNode {
|
|
|
89
101
|
}
|
|
90
102
|
|
|
91
103
|
getSetterName(environment: LanguageEnvironment): string {
|
|
92
|
-
if (this.type.kind === 'boolean'
|
|
104
|
+
if (this.type.kind === 'boolean') {
|
|
93
105
|
// Boolean accessors where the property starts with "is" are renamed in JVM
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
106
|
+
switch (environment) {
|
|
107
|
+
case 'jvm':
|
|
108
|
+
if (this.name.startsWith('is')) {
|
|
109
|
+
// isSomething -> setSomething()
|
|
110
|
+
const cleanName = this.name.replace('is', '')
|
|
111
|
+
return `set${capitalizeName(cleanName)}`
|
|
112
|
+
} else {
|
|
113
|
+
break
|
|
114
|
+
}
|
|
115
|
+
default:
|
|
116
|
+
break
|
|
98
117
|
}
|
|
99
118
|
}
|
|
100
119
|
// isSomething -> setIsSomething()
|
package/src/syntax/helpers.ts
CHANGED
|
@@ -150,10 +150,6 @@ export function compareLooselyness(a: Type, b: Type): number {
|
|
|
150
150
|
return getTypeLooselyness(a) - getTypeLooselyness(b)
|
|
151
151
|
}
|
|
152
152
|
|
|
153
|
-
export function isBooleanPropertyPrefix(name: string): boolean {
|
|
154
|
-
return name.startsWith('is') || name.startsWith('has')
|
|
155
|
-
}
|
|
156
|
-
|
|
157
153
|
export function isNotDuplicate<T>(item: T, index: number, array: T[]): boolean {
|
|
158
154
|
return array.indexOf(item) === index
|
|
159
155
|
}
|
|
@@ -465,11 +465,15 @@ export class SwiftCxxBridgedType implements BridgedType<'swift', 'c++'> {
|
|
|
465
465
|
return `${cppParameterName}.has_value() ? ${cppParameterName}.pointee : nil`
|
|
466
466
|
}
|
|
467
467
|
}
|
|
468
|
-
// TODO: Remove this check for booleans once https://github.com/swiftlang/swift/issues/84848 is fixed.
|
|
468
|
+
// TODO: Remove this check for booleans/doubles once https://github.com/swiftlang/swift/issues/84848 is fixed.
|
|
469
|
+
// Right now, optionals of doubles or booleans (and who knows what else?) fail to compile when `.value` is used.
|
|
469
470
|
const swiftBug84848Workaround =
|
|
470
|
-
optional.wrappingType.kind === 'boolean'
|
|
471
|
-
|
|
472
|
-
|
|
471
|
+
optional.wrappingType.kind === 'boolean' ||
|
|
472
|
+
optional.wrappingType.kind === 'number'
|
|
473
|
+
if (!swiftBug84848Workaround) {
|
|
474
|
+
if (!wrapping.needsSpecialHandling) {
|
|
475
|
+
return `${cppParameterName}.value`
|
|
476
|
+
}
|
|
473
477
|
}
|
|
474
478
|
return `
|
|
475
479
|
{ () -> ${optional.getCode('swift')} in
|
|
@@ -249,7 +249,7 @@ inline bool has_value_${name}(const ${actualType}& optional) noexcept {
|
|
|
249
249
|
return optional.has_value();
|
|
250
250
|
}
|
|
251
251
|
inline ${wrappedBridge.getTypeCode('c++')} get_${name}(const ${actualType}& optional) noexcept {
|
|
252
|
-
return
|
|
252
|
+
return optional.value();
|
|
253
253
|
}
|
|
254
254
|
`.trim(),
|
|
255
255
|
requiredIncludes: [
|
|
@@ -1,13 +0,0 @@
|
|
|
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 BigIntType implements Type {
|
|
5
|
-
private signed;
|
|
6
|
-
constructor(signed: boolean);
|
|
7
|
-
get canBePassedByReference(): boolean;
|
|
8
|
-
get kind(): TypeKind;
|
|
9
|
-
get isEquatable(): boolean;
|
|
10
|
-
getCode(language: Language): string;
|
|
11
|
-
getExtraFiles(): SourceFile[];
|
|
12
|
-
getRequiredImports(): SourceImport[];
|
|
13
|
-
}
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
export class BigIntType {
|
|
2
|
-
signed;
|
|
3
|
-
constructor(signed) {
|
|
4
|
-
this.signed = signed;
|
|
5
|
-
}
|
|
6
|
-
get canBePassedByReference() {
|
|
7
|
-
// It's a primitive.
|
|
8
|
-
return false;
|
|
9
|
-
}
|
|
10
|
-
get kind() {
|
|
11
|
-
return 'bigint';
|
|
12
|
-
}
|
|
13
|
-
get isEquatable() {
|
|
14
|
-
return true;
|
|
15
|
-
}
|
|
16
|
-
getCode(language) {
|
|
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
|
-
}
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
getExtraFiles() {
|
|
43
|
-
return [];
|
|
44
|
-
}
|
|
45
|
-
getRequiredImports() {
|
|
46
|
-
return [];
|
|
47
|
-
}
|
|
48
|
-
}
|