nitrogen 0.31.8 → 0.31.9

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.
@@ -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 params = functionType.parameters.map((p) => `${p.getCode('c++')} ${p.escapedName}`);
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 [${parameterName}Ref](${params.join(', ')}) -> ${returnType} {
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();
@@ -191,7 +191,7 @@ namespace ${cxxNamespace} {
191
191
  /**
192
192
  * An implementation of ${name} that is backed by a C++ implementation (using \`std::function<...>\`)
193
193
  */
194
- struct J${name}_cxx final: public jni::HybridClass<J${name}_cxx, J${name}> {
194
+ class J${name}_cxx final: public jni::HybridClass<J${name}_cxx, J${name}> {
195
195
  public:
196
196
  static jni::local_ref<J${name}::javaobject> fromCpp(const ${typename}& func) {
197
197
  return J${name}_cxx::newObjectCxxArgs(func);
@@ -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
  });
@@ -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.8",
3
+ "version": "0.31.9",
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.8",
39
+ "react-native-nitro-modules": "^0.31.9",
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 params = functionType.parameters.map(
816
- (p) => `${p.getCode('c++')} ${p.escapedName}`
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 [${parameterName}Ref](${params.join(', ')}) -> ${returnType} {
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()
@@ -210,7 +210,7 @@ namespace ${cxxNamespace} {
210
210
  /**
211
211
  * An implementation of ${name} that is backed by a C++ implementation (using \`std::function<...>\`)
212
212
  */
213
- struct J${name}_cxx final: public jni::HybridClass<J${name}_cxx, J${name}> {
213
+ class J${name}_cxx final: public jni::HybridClass<J${name}_cxx, J${name}> {
214
214
  public:
215
215
  static jni::local_ref<J${name}::javaobject> fromCpp(const ${typename}& func) {
216
216
  return J${name}_cxx::newObjectCxxArgs(func);
@@ -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
  })