nitrogen 0.35.4 → 0.35.6

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.
@@ -632,18 +632,24 @@ export class KotlinCxxBridgedType {
632
632
  `.trim();
633
633
  }
634
634
  default: {
635
- // other arrays need to loop through
635
+ // other arrays need to loop through.
636
+ // we wrap the lambda with a parameter (`__input`) so that nested arrays
637
+ // don't end up shadowing `__element` in their own initializers
638
+ // (which would be `const auto& __element = __element[__i]`,
639
+ // an invalid self-referential `auto`-type deduction).
640
+ // `auto&&` is a forwarding reference so it binds to both const and
641
+ // non-const inputs across nesting levels.
636
642
  return `
637
- [&]() {
638
- size_t __size = ${parameterName}.size();
643
+ [&](auto&& __input) {
644
+ size_t __size = __input.size();
639
645
  jni::local_ref<${arrayType}> __array = ${arrayType}::newArray(__size);
640
646
  for (size_t __i = 0; __i < __size; __i++) {
641
- const auto& __element = ${parameterName}[__i];
647
+ const auto& __element = __input[__i];
642
648
  auto __elementJni = ${indent(bridge.parseFromCppToKotlin('__element', 'c++'), ' ')};
643
649
  __array->setElement(__i, ${bridge.dereferenceToJObject('__elementJni')});
644
650
  }
645
651
  return __array;
646
- }()
652
+ }(${parameterName})
647
653
  `.trim();
648
654
  }
649
655
  }
@@ -915,18 +921,25 @@ export class KotlinCxxBridgedType {
915
921
  `.trim();
916
922
  }
917
923
  default: {
918
- // other arrays need to loop through
924
+ // other arrays need to loop through.
925
+ // we wrap the lambda with a parameter (`__input`) so that nested arrays
926
+ // don't end up shadowing `__element` in their own initializers
927
+ // (which would be `auto __element = __element->getElement(__i)`,
928
+ // an invalid self-referential `auto`-type deduction).
929
+ // `auto&&` is a forwarding reference so it binds to both const and
930
+ // non-const inputs across nesting levels (and to JNI `local_ref`s,
931
+ // which expose non-const `getElement(...)`).
919
932
  return `
920
- [&]() {
921
- size_t __size = ${parameterName}->size();
933
+ [&](auto&& __input) {
934
+ size_t __size = __input->size();
922
935
  std::vector<${itemType}> __vector;
923
936
  __vector.reserve(__size);
924
937
  for (size_t __i = 0; __i < __size; __i++) {
925
- auto __element = ${parameterName}->getElement(__i);
926
- __vector.push_back(${bridge.parseFromKotlinToCpp('__element', 'c++')});
938
+ auto __element = __input->getElement(__i);
939
+ __vector.push_back(${indent(bridge.parseFromKotlinToCpp('__element', 'c++'), ' ')});
927
940
  }
928
941
  return __vector;
929
- }()
942
+ }(${parameterName})
930
943
  `.trim();
931
944
  }
932
945
  }
@@ -134,7 +134,7 @@ class ${name}_java(private val function: ${lambdaSignature}): ${name} {
134
134
  let jniCallBody;
135
135
  if (functionType.returnType.kind === 'void') {
136
136
  // It returns void
137
- cppCallBody = `_func(${indent(paramsForward.join(', '), ' ')});`;
137
+ cppCallBody = `_func(${paramsForward.join(', ')});`;
138
138
  jniCallBody = `
139
139
  static const auto method = javaClassStatic()->getMethod<${jniSignature}>("invoke");
140
140
  method(${jniParamsForward.join(', ')});
@@ -143,7 +143,7 @@ method(${jniParamsForward.join(', ')});
143
143
  else {
144
144
  // It returns a type!
145
145
  cppCallBody = `
146
- ${functionType.returnType.getCode('c++')} __result = _func(${indent(paramsForward.join(', '), ' ')});
146
+ ${functionType.returnType.getCode('c++')} __result = _func(${paramsForward.join(', ')});
147
147
  return ${bridgedReturn.parseFromCppToKotlin('__result', 'c++')};
148
148
  `.trim();
149
149
  jniCallBody = `
@@ -32,6 +32,10 @@ val ${name}: ${type.getTypeCode('kotlin', false)}
32
32
  .map((i) => `import ${i.name}`)
33
33
  .filter(isNotDuplicate);
34
34
  const secondaryConstructor = createKotlinConstructor(structType);
35
+ const equalityComparators = structType.properties.map((p) => `Objects.deepEquals(this.${p.escapedName}, other.${p.escapedName})`);
36
+ const propertiesList = structType.properties
37
+ .map((p) => p.escapedName)
38
+ .join(',\n');
35
39
  const code = `
36
40
  ${createFileMetadataString(`${structType.structName}.kt`)}
37
41
 
@@ -39,6 +43,7 @@ package ${packageName}
39
43
 
40
44
  import androidx.annotation.Keep
41
45
  import com.facebook.proguard.annotations.DoNotStrip
46
+ import java.util.Objects
42
47
  ${extraImports.join('\n')}
43
48
 
44
49
  /**
@@ -51,6 +56,18 @@ data class ${structType.structName}(
51
56
  ) {
52
57
  ${indent(secondaryConstructor, ' ')}
53
58
 
59
+ override fun equals(other: Any?): Boolean {
60
+ if (this === other) return true
61
+ if (other !is ${structType.structName}) return false
62
+ return ${equalityComparators.join(`\n && `)}
63
+ }
64
+
65
+ override fun hashCode(): Int {
66
+ return arrayOf(
67
+ ${indent(propertiesList, ' ')}
68
+ ).contentDeepHashCode()
69
+ }
70
+
54
71
  companion object {
55
72
  /**
56
73
  * Constructor called from C++
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nitrogen",
3
- "version": "0.35.4",
3
+ "version": "0.35.6",
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.35.4",
38
+ "react-native-nitro-modules": "^0.35.6",
39
39
  "ts-morph": "^27.0.0",
40
40
  "yargs": "^18.0.0",
41
41
  "zod": "^4.0.5"
@@ -672,18 +672,24 @@ export class KotlinCxxBridgedType implements BridgedType<'kotlin', 'c++'> {
672
672
  `.trim()
673
673
  }
674
674
  default: {
675
- // other arrays need to loop through
675
+ // other arrays need to loop through.
676
+ // we wrap the lambda with a parameter (`__input`) so that nested arrays
677
+ // don't end up shadowing `__element` in their own initializers
678
+ // (which would be `const auto& __element = __element[__i]`,
679
+ // an invalid self-referential `auto`-type deduction).
680
+ // `auto&&` is a forwarding reference so it binds to both const and
681
+ // non-const inputs across nesting levels.
676
682
  return `
677
- [&]() {
678
- size_t __size = ${parameterName}.size();
683
+ [&](auto&& __input) {
684
+ size_t __size = __input.size();
679
685
  jni::local_ref<${arrayType}> __array = ${arrayType}::newArray(__size);
680
686
  for (size_t __i = 0; __i < __size; __i++) {
681
- const auto& __element = ${parameterName}[__i];
687
+ const auto& __element = __input[__i];
682
688
  auto __elementJni = ${indent(bridge.parseFromCppToKotlin('__element', 'c++'), ' ')};
683
689
  __array->setElement(__i, ${bridge.dereferenceToJObject('__elementJni')});
684
690
  }
685
691
  return __array;
686
- }()
692
+ }(${parameterName})
687
693
  `.trim()
688
694
  }
689
695
  }
@@ -976,18 +982,25 @@ export class KotlinCxxBridgedType implements BridgedType<'kotlin', 'c++'> {
976
982
  `.trim()
977
983
  }
978
984
  default: {
979
- // other arrays need to loop through
985
+ // other arrays need to loop through.
986
+ // we wrap the lambda with a parameter (`__input`) so that nested arrays
987
+ // don't end up shadowing `__element` in their own initializers
988
+ // (which would be `auto __element = __element->getElement(__i)`,
989
+ // an invalid self-referential `auto`-type deduction).
990
+ // `auto&&` is a forwarding reference so it binds to both const and
991
+ // non-const inputs across nesting levels (and to JNI `local_ref`s,
992
+ // which expose non-const `getElement(...)`).
980
993
  return `
981
- [&]() {
982
- size_t __size = ${parameterName}->size();
994
+ [&](auto&& __input) {
995
+ size_t __size = __input->size();
983
996
  std::vector<${itemType}> __vector;
984
997
  __vector.reserve(__size);
985
998
  for (size_t __i = 0; __i < __size; __i++) {
986
- auto __element = ${parameterName}->getElement(__i);
987
- __vector.push_back(${bridge.parseFromKotlinToCpp('__element', 'c++')});
999
+ auto __element = __input->getElement(__i);
1000
+ __vector.push_back(${indent(bridge.parseFromKotlinToCpp('__element', 'c++'), ' ')});
988
1001
  }
989
1002
  return __vector;
990
- }()
1003
+ }(${parameterName})
991
1004
  `.trim()
992
1005
  }
993
1006
  }
@@ -152,7 +152,7 @@ class ${name}_java(private val function: ${lambdaSignature}): ${name} {
152
152
  let jniCallBody: string
153
153
  if (functionType.returnType.kind === 'void') {
154
154
  // It returns void
155
- cppCallBody = `_func(${indent(paramsForward.join(', '), ' ')});`
155
+ cppCallBody = `_func(${paramsForward.join(', ')});`
156
156
  jniCallBody = `
157
157
  static const auto method = javaClassStatic()->getMethod<${jniSignature}>("invoke");
158
158
  method(${jniParamsForward.join(', ')});
@@ -160,7 +160,7 @@ method(${jniParamsForward.join(', ')});
160
160
  } else {
161
161
  // It returns a type!
162
162
  cppCallBody = `
163
- ${functionType.returnType.getCode('c++')} __result = _func(${indent(paramsForward.join(', '), ' ')});
163
+ ${functionType.returnType.getCode('c++')} __result = _func(${paramsForward.join(', ')});
164
164
  return ${bridgedReturn.parseFromCppToKotlin('__result', 'c++')};
165
165
  `.trim()
166
166
  jniCallBody = `
@@ -45,6 +45,13 @@ val ${name}: ${type.getTypeCode('kotlin', false)}
45
45
 
46
46
  const secondaryConstructor = createKotlinConstructor(structType)
47
47
 
48
+ const equalityComparators = structType.properties.map(
49
+ (p) => `Objects.deepEquals(this.${p.escapedName}, other.${p.escapedName})`
50
+ )
51
+ const propertiesList = structType.properties
52
+ .map((p) => p.escapedName)
53
+ .join(',\n')
54
+
48
55
  const code = `
49
56
  ${createFileMetadataString(`${structType.structName}.kt`)}
50
57
 
@@ -52,6 +59,7 @@ package ${packageName}
52
59
 
53
60
  import androidx.annotation.Keep
54
61
  import com.facebook.proguard.annotations.DoNotStrip
62
+ import java.util.Objects
55
63
  ${extraImports.join('\n')}
56
64
 
57
65
  /**
@@ -64,6 +72,18 @@ data class ${structType.structName}(
64
72
  ) {
65
73
  ${indent(secondaryConstructor, ' ')}
66
74
 
75
+ override fun equals(other: Any?): Boolean {
76
+ if (this === other) return true
77
+ if (other !is ${structType.structName}) return false
78
+ return ${equalityComparators.join(`\n && `)}
79
+ }
80
+
81
+ override fun hashCode(): Int {
82
+ return arrayOf(
83
+ ${indent(propertiesList, ' ')}
84
+ ).contentDeepHashCode()
85
+ }
86
+
67
87
  companion object {
68
88
  /**
69
89
  * Constructor called from C++