nitrogen 0.36.2 → 0.36.3

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.
@@ -16,6 +16,12 @@ export function createKotlinFunction(functionType) {
16
16
  .getRequiredImports('kotlin')
17
17
  .map((i) => `import ${i.name}`)
18
18
  .filter(isNotDuplicate);
19
+ const funcAnnotations = [];
20
+ if (!functionType.isSync) {
21
+ // Async functions immediately schedule calls on a Dispatcher,
22
+ // we can make those @FastNative as they are not doing any JNI allocations
23
+ funcAnnotations.push('@FastNative');
24
+ }
19
25
  const kotlinCode = `
20
26
  ${createFileMetadataString(`${name}.kt`)}
21
27
 
@@ -73,7 +79,7 @@ class ${name}_cxx: ${name} {
73
79
  override fun invoke(${kotlinParams.join(', ')}): ${kotlinReturnType}
74
80
  = invoke_cxx(${kotlinParamsForward.join(',')})
75
81
 
76
- @FastNative
82
+ ${funcAnnotations.join('\n')}
77
83
  private external fun invoke_cxx(${kotlinParams.join(', ')}): ${kotlinReturnType}
78
84
  }
79
85
 
@@ -7,6 +7,7 @@ export interface GetFunctionCodeOptions extends GetCodeOptions {
7
7
  export declare class FunctionType implements Type {
8
8
  readonly returnType: Type;
9
9
  readonly parameters: NamedType[];
10
+ readonly isSync: boolean;
10
11
  constructor(returnType: Type, parameters: NamedType[], isSync?: boolean);
11
12
  get specializationName(): string;
12
13
  get jsName(): string;
@@ -5,6 +5,7 @@ import { PromiseType } from './PromiseType.js';
5
5
  export class FunctionType {
6
6
  returnType;
7
7
  parameters;
8
+ isSync;
8
9
  constructor(returnType, parameters, isSync = false) {
9
10
  if (returnType.kind === 'void' || isSync) {
10
11
  // void callbacks are async, but we don't care about the result.
@@ -15,6 +16,7 @@ export class FunctionType {
15
16
  this.returnType = new PromiseType(returnType);
16
17
  }
17
18
  this.parameters = parameters;
19
+ this.isSync = isSync;
18
20
  if (isSync && returnType.kind === 'void') {
19
21
  throw new Error(`Function \`${this.jsName}\` cannot be sync (\`Sync<...>\`) AND return \`void\`, as this is ambiguous. ` +
20
22
  `Either return a value (even if it's just a \`boolean\`) to keep it sync, or make it async.`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nitrogen",
3
- "version": "0.36.2",
3
+ "version": "0.36.3",
4
4
  "description": "Code generator for React Native Nitro Modules that turns TypeScript specs into C++, Swift, and Kotlin bindings.",
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.36.2",
38
+ "react-native-nitro-modules": "^0.36.3",
39
39
  "ts-morph": "^28.0.0",
40
40
  "yargs": "^18.0.0",
41
41
  "zod": "^4.4.3"
@@ -24,6 +24,12 @@ export function createKotlinFunction(functionType: FunctionType): SourceFile[] {
24
24
  .getRequiredImports('kotlin')
25
25
  .map((i) => `import ${i.name}`)
26
26
  .filter(isNotDuplicate)
27
+ const funcAnnotations: string[] = []
28
+ if (!functionType.isSync) {
29
+ // Async functions immediately schedule calls on a Dispatcher,
30
+ // we can make those @FastNative as they are not doing any JNI allocations
31
+ funcAnnotations.push('@FastNative')
32
+ }
27
33
 
28
34
  const kotlinCode = `
29
35
  ${createFileMetadataString(`${name}.kt`)}
@@ -82,7 +88,7 @@ class ${name}_cxx: ${name} {
82
88
  override fun invoke(${kotlinParams.join(', ')}): ${kotlinReturnType}
83
89
  = invoke_cxx(${kotlinParamsForward.join(',')})
84
90
 
85
- @FastNative
91
+ ${funcAnnotations.join('\n')}
86
92
  private external fun invoke_cxx(${kotlinParams.join(', ')}): ${kotlinReturnType}
87
93
  }
88
94
 
@@ -12,6 +12,7 @@ export interface GetFunctionCodeOptions extends GetCodeOptions {
12
12
  export class FunctionType implements Type {
13
13
  readonly returnType: Type
14
14
  readonly parameters: NamedType[]
15
+ readonly isSync: boolean
15
16
 
16
17
  constructor(returnType: Type, parameters: NamedType[], isSync = false) {
17
18
  if (returnType.kind === 'void' || isSync) {
@@ -22,6 +23,7 @@ export class FunctionType implements Type {
22
23
  this.returnType = new PromiseType(returnType)
23
24
  }
24
25
  this.parameters = parameters
26
+ this.isSync = isSync
25
27
 
26
28
  if (isSync && returnType.kind === 'void') {
27
29
  throw new Error(