nitrogen 0.33.9 → 0.34.1
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 +23 -11
- package/lib/syntax/Property.js +32 -9
- package/lib/syntax/helpers.d.ts +0 -1
- package/lib/syntax/helpers.js +0 -3
- package/package.json +2 -2
- package/src/autolinking/android/createHybridObjectInitializer.ts +23 -11
- package/src/syntax/Property.ts +28 -9
- package/src/syntax/helpers.ts +0 -4
|
@@ -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
|
-
|
|
94
|
-
|
|
95
|
-
${indent(jniRegistrations.join('\n'), ' ')}
|
|
107
|
+
// Register native JNI methods
|
|
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
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nitrogen",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.34.1",
|
|
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.1",
|
|
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
|
-
|
|
107
|
-
|
|
108
|
-
${indent(jniRegistrations.join('\n'), ' ')}
|
|
120
|
+
// Register native JNI methods
|
|
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
|
}
|