nitrogen 0.31.8 → 0.31.10
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/kotlin/KotlinCxxBridgedType.js +7 -5
- package/lib/syntax/kotlin/KotlinFunction.js +5 -2
- package/lib/syntax/kotlin/KotlinStruct.js +0 -9
- package/lib/syntax/kotlin/KotlinVariant.js +1 -1
- package/lib/syntax/swift/SwiftStruct.js +2 -2
- package/lib/syntax/types/UndefinedType.d.ts +10 -0
- package/lib/syntax/types/UndefinedType.js +23 -0
- package/package.json +2 -2
- package/src/syntax/kotlin/KotlinCxxBridgedType.ts +8 -8
- package/src/syntax/kotlin/KotlinFunction.ts +7 -2
- package/src/syntax/kotlin/KotlinStruct.ts +0 -9
- package/src/syntax/kotlin/KotlinVariant.ts +1 -1
- package/src/syntax/swift/SwiftStruct.ts +2 -2
|
@@ -81,6 +81,11 @@ export class KotlinCxxBridgedType {
|
|
|
81
81
|
name: `J${functionType.specializationName}.hpp`,
|
|
82
82
|
space: 'user',
|
|
83
83
|
});
|
|
84
|
+
imports.push({
|
|
85
|
+
language: 'c++',
|
|
86
|
+
name: `NitroModules/JNICallable.hpp`,
|
|
87
|
+
space: 'system',
|
|
88
|
+
});
|
|
84
89
|
break;
|
|
85
90
|
case 'null':
|
|
86
91
|
imports.push({
|
|
@@ -769,8 +774,7 @@ export class KotlinCxxBridgedType {
|
|
|
769
774
|
switch (language) {
|
|
770
775
|
case 'c++': {
|
|
771
776
|
const returnType = functionType.returnType.getCode('c++');
|
|
772
|
-
const
|
|
773
|
-
const paramsForward = functionType.parameters.map((p) => p.escapedName);
|
|
777
|
+
const paramTypes = functionType.parameters.map((p) => p.getCode('c++'));
|
|
774
778
|
const jniType = `J${functionType.specializationName}_cxx`;
|
|
775
779
|
return `
|
|
776
780
|
[&]() -> ${functionType.getCode('c++')} {
|
|
@@ -779,9 +783,7 @@ export class KotlinCxxBridgedType {
|
|
|
779
783
|
return downcast->cthis()->getFunction();
|
|
780
784
|
} else {
|
|
781
785
|
auto ${parameterName}Ref = jni::make_global(${parameterName});
|
|
782
|
-
return
|
|
783
|
-
return ${parameterName}Ref->invoke(${paramsForward});
|
|
784
|
-
};
|
|
786
|
+
return JNICallable<J${functionType.specializationName}, ${returnType}(${paramTypes.join(', ')})>(std::move(${parameterName}Ref));
|
|
785
787
|
}
|
|
786
788
|
}()
|
|
787
789
|
`.trim();
|
|
@@ -152,6 +152,9 @@ auto __result = method(${jniParamsForward.join(', ')});
|
|
|
152
152
|
return ${bridgedReturn.parseFromKotlinToCpp('__result', 'c++', false)};
|
|
153
153
|
`.trim();
|
|
154
154
|
}
|
|
155
|
+
const fbjniReturnType = functionType.returnType.kind === 'hybrid-object'
|
|
156
|
+
? bridgedReturn.asJniReferenceType('global')
|
|
157
|
+
: bridgedReturn.asJniReferenceType('local');
|
|
155
158
|
const bridged = new KotlinCxxBridgedType(functionType);
|
|
156
159
|
const imports = bridged
|
|
157
160
|
.getRequiredImports('c++')
|
|
@@ -191,7 +194,7 @@ namespace ${cxxNamespace} {
|
|
|
191
194
|
/**
|
|
192
195
|
* An implementation of ${name} that is backed by a C++ implementation (using \`std::function<...>\`)
|
|
193
196
|
*/
|
|
194
|
-
|
|
197
|
+
class J${name}_cxx final: public jni::HybridClass<J${name}_cxx, J${name}> {
|
|
195
198
|
public:
|
|
196
199
|
static jni::local_ref<J${name}::javaobject> fromCpp(const ${typename}& func) {
|
|
197
200
|
return J${name}_cxx::newObjectCxxArgs(func);
|
|
@@ -201,7 +204,7 @@ namespace ${cxxNamespace} {
|
|
|
201
204
|
/**
|
|
202
205
|
* Invokes the C++ \`std::function<...>\` this \`J${name}_cxx\` instance holds.
|
|
203
206
|
*/
|
|
204
|
-
${
|
|
207
|
+
${fbjniReturnType} invoke_cxx(${cppParams.join(', ')}) {
|
|
205
208
|
${indent(cppCallBody, ' ')}
|
|
206
209
|
}
|
|
207
210
|
|
|
@@ -10,15 +10,6 @@ export function createKotlinStruct(structType) {
|
|
|
10
10
|
name: p.escapedName,
|
|
11
11
|
type: new KotlinCxxBridgedType(p),
|
|
12
12
|
}));
|
|
13
|
-
// const parameters = structType.properties
|
|
14
|
-
// .map((p) =>
|
|
15
|
-
// `
|
|
16
|
-
// @DoNotStrip
|
|
17
|
-
// @Keep
|
|
18
|
-
// val ${p.escapedName}: ${p.getCode('kotlin')}
|
|
19
|
-
// `.trim()
|
|
20
|
-
// )
|
|
21
|
-
// .join(',\n')
|
|
22
13
|
const properties = bridgedProperties
|
|
23
14
|
.map(({ name, type }) => {
|
|
24
15
|
return `
|
|
@@ -125,7 +125,7 @@ static jni::local_ref<J${kotlinName}> create_${i}(${bridge.asJniReferenceType('a
|
|
|
125
125
|
if (isInstanceOf(${namespace}::${innerName}::javaClassStatic())) {
|
|
126
126
|
// It's a \`${v.getCode('c++')}\`
|
|
127
127
|
auto jniValue = static_cast<const ${namespace}::${innerName}*>(this)->getValue();
|
|
128
|
-
return ${bridge.parseFromKotlinToCpp('jniValue', 'c++')};
|
|
128
|
+
return ${indent(bridge.parseFromKotlinToCpp('jniValue', 'c++'), ' ')};
|
|
129
129
|
}
|
|
130
130
|
`.trim();
|
|
131
131
|
});
|
|
@@ -26,8 +26,8 @@ var ${p.escapedName}: ${p.getCode('swift')} {
|
|
|
26
26
|
`.trim();
|
|
27
27
|
})
|
|
28
28
|
.join('\n\n');
|
|
29
|
-
const requiredImports = struct
|
|
30
|
-
.getRequiredImports('swift')
|
|
29
|
+
const requiredImports = struct.properties
|
|
30
|
+
.flatMap((p) => p.getRequiredImports('swift'))
|
|
31
31
|
.map((i) => `import ${i.name}`);
|
|
32
32
|
requiredImports.push('import NitroModules');
|
|
33
33
|
const imports = requiredImports.filter(isNotDuplicate);
|
|
@@ -0,0 +1,10 @@
|
|
|
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 UndefinedType implements Type {
|
|
5
|
+
get canBePassedByReference(): boolean;
|
|
6
|
+
get kind(): TypeKind;
|
|
7
|
+
getCode(language: Language): string;
|
|
8
|
+
getExtraFiles(): SourceFile[];
|
|
9
|
+
getRequiredImports(): SourceImport[];
|
|
10
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export class UndefinedType {
|
|
2
|
+
get canBePassedByReference() {
|
|
3
|
+
// It's a primitive.
|
|
4
|
+
return false;
|
|
5
|
+
}
|
|
6
|
+
get kind() {
|
|
7
|
+
return 'undefined';
|
|
8
|
+
}
|
|
9
|
+
getCode(language) {
|
|
10
|
+
switch (language) {
|
|
11
|
+
case 'c++':
|
|
12
|
+
return 'std::nullopt_t';
|
|
13
|
+
default:
|
|
14
|
+
throw new Error(`Language ${language} is not yet supported for UndefinedType!`);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
getExtraFiles() {
|
|
18
|
+
return [];
|
|
19
|
+
}
|
|
20
|
+
getRequiredImports() {
|
|
21
|
+
return [];
|
|
22
|
+
}
|
|
23
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nitrogen",
|
|
3
|
-
"version": "0.31.
|
|
3
|
+
"version": "0.31.10",
|
|
4
4
|
"description": "The code-generator for react-native-nitro-modules.",
|
|
5
5
|
"main": "lib/index",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
38
|
"chalk": "^5.3.0",
|
|
39
|
-
"react-native-nitro-modules": "^0.31.
|
|
39
|
+
"react-native-nitro-modules": "^0.31.10",
|
|
40
40
|
"ts-morph": "^27.0.0",
|
|
41
41
|
"yargs": "^18.0.0",
|
|
42
42
|
"zod": "^4.0.5"
|
|
@@ -92,6 +92,11 @@ export class KotlinCxxBridgedType implements BridgedType<'kotlin', 'c++'> {
|
|
|
92
92
|
name: `J${functionType.specializationName}.hpp`,
|
|
93
93
|
space: 'user',
|
|
94
94
|
})
|
|
95
|
+
imports.push({
|
|
96
|
+
language: 'c++',
|
|
97
|
+
name: `NitroModules/JNICallable.hpp`,
|
|
98
|
+
space: 'system',
|
|
99
|
+
})
|
|
95
100
|
break
|
|
96
101
|
case 'null':
|
|
97
102
|
imports.push({
|
|
@@ -812,11 +817,8 @@ export class KotlinCxxBridgedType implements BridgedType<'kotlin', 'c++'> {
|
|
|
812
817
|
switch (language) {
|
|
813
818
|
case 'c++': {
|
|
814
819
|
const returnType = functionType.returnType.getCode('c++')
|
|
815
|
-
const
|
|
816
|
-
|
|
817
|
-
)
|
|
818
|
-
const paramsForward = functionType.parameters.map(
|
|
819
|
-
(p) => p.escapedName
|
|
820
|
+
const paramTypes = functionType.parameters.map((p) =>
|
|
821
|
+
p.getCode('c++')
|
|
820
822
|
)
|
|
821
823
|
const jniType = `J${functionType.specializationName}_cxx`
|
|
822
824
|
return `
|
|
@@ -826,9 +828,7 @@ export class KotlinCxxBridgedType implements BridgedType<'kotlin', 'c++'> {
|
|
|
826
828
|
return downcast->cthis()->getFunction();
|
|
827
829
|
} else {
|
|
828
830
|
auto ${parameterName}Ref = jni::make_global(${parameterName});
|
|
829
|
-
return
|
|
830
|
-
return ${parameterName}Ref->invoke(${paramsForward});
|
|
831
|
-
};
|
|
831
|
+
return JNICallable<J${functionType.specializationName}, ${returnType}(${paramTypes.join(', ')})>(std::move(${parameterName}Ref));
|
|
832
832
|
}
|
|
833
833
|
}()
|
|
834
834
|
`.trim()
|
|
@@ -170,6 +170,11 @@ return ${bridgedReturn.parseFromKotlinToCpp('__result', 'c++', false)};
|
|
|
170
170
|
`.trim()
|
|
171
171
|
}
|
|
172
172
|
|
|
173
|
+
const fbjniReturnType =
|
|
174
|
+
functionType.returnType.kind === 'hybrid-object'
|
|
175
|
+
? bridgedReturn.asJniReferenceType('global')
|
|
176
|
+
: bridgedReturn.asJniReferenceType('local')
|
|
177
|
+
|
|
173
178
|
const bridged = new KotlinCxxBridgedType(functionType)
|
|
174
179
|
const imports = bridged
|
|
175
180
|
.getRequiredImports('c++')
|
|
@@ -210,7 +215,7 @@ namespace ${cxxNamespace} {
|
|
|
210
215
|
/**
|
|
211
216
|
* An implementation of ${name} that is backed by a C++ implementation (using \`std::function<...>\`)
|
|
212
217
|
*/
|
|
213
|
-
|
|
218
|
+
class J${name}_cxx final: public jni::HybridClass<J${name}_cxx, J${name}> {
|
|
214
219
|
public:
|
|
215
220
|
static jni::local_ref<J${name}::javaobject> fromCpp(const ${typename}& func) {
|
|
216
221
|
return J${name}_cxx::newObjectCxxArgs(func);
|
|
@@ -220,7 +225,7 @@ namespace ${cxxNamespace} {
|
|
|
220
225
|
/**
|
|
221
226
|
* Invokes the C++ \`std::function<...>\` this \`J${name}_cxx\` instance holds.
|
|
222
227
|
*/
|
|
223
|
-
${
|
|
228
|
+
${fbjniReturnType} invoke_cxx(${cppParams.join(', ')}) {
|
|
224
229
|
${indent(cppCallBody, ' ')}
|
|
225
230
|
}
|
|
226
231
|
|
|
@@ -19,15 +19,6 @@ export function createKotlinStruct(structType: StructType): SourceFile[] {
|
|
|
19
19
|
name: p.escapedName,
|
|
20
20
|
type: new KotlinCxxBridgedType(p),
|
|
21
21
|
}))
|
|
22
|
-
// const parameters = structType.properties
|
|
23
|
-
// .map((p) =>
|
|
24
|
-
// `
|
|
25
|
-
// @DoNotStrip
|
|
26
|
-
// @Keep
|
|
27
|
-
// val ${p.escapedName}: ${p.getCode('kotlin')}
|
|
28
|
-
// `.trim()
|
|
29
|
-
// )
|
|
30
|
-
// .join(',\n')
|
|
31
22
|
const properties = bridgedProperties
|
|
32
23
|
.map(({ name, type }) => {
|
|
33
24
|
return `
|
|
@@ -140,7 +140,7 @@ static jni::local_ref<J${kotlinName}> create_${i}(${bridge.asJniReferenceType('a
|
|
|
140
140
|
if (isInstanceOf(${namespace}::${innerName}::javaClassStatic())) {
|
|
141
141
|
// It's a \`${v.getCode('c++')}\`
|
|
142
142
|
auto jniValue = static_cast<const ${namespace}::${innerName}*>(this)->getValue();
|
|
143
|
-
return ${bridge.parseFromKotlinToCpp('jniValue', 'c++')};
|
|
143
|
+
return ${indent(bridge.parseFromKotlinToCpp('jniValue', 'c++'), ' ')};
|
|
144
144
|
}
|
|
145
145
|
`.trim()
|
|
146
146
|
})
|
|
@@ -34,8 +34,8 @@ var ${p.escapedName}: ${p.getCode('swift')} {
|
|
|
34
34
|
})
|
|
35
35
|
.join('\n\n')
|
|
36
36
|
|
|
37
|
-
const requiredImports = struct
|
|
38
|
-
.getRequiredImports('swift')
|
|
37
|
+
const requiredImports = struct.properties
|
|
38
|
+
.flatMap((p) => p.getRequiredImports('swift'))
|
|
39
39
|
.map((i) => `import ${i.name}`)
|
|
40
40
|
requiredImports.push('import NitroModules')
|
|
41
41
|
const imports = requiredImports.filter(isNotDuplicate)
|