@react-native/codegen 0.74.0-nightly-20231214-b0982971c → 0.74.0-nightly-20231216-479b4bb1b
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/CodegenSchema.d.ts +10 -1
- package/lib/parsers/flow/components/__test_fixtures__/fixtures.js +7 -1
- package/lib/parsers/flow/components/__test_fixtures__/fixtures.js.flow +7 -1
- package/lib/parsers/typescript/components/__test_fixtures__/fixtures.js +8 -1
- package/lib/parsers/typescript/components/__test_fixtures__/fixtures.js.flow +8 -1
- package/lib/parsers/typescript/components/commands.js +23 -15
- package/lib/parsers/typescript/components/commands.js.flow +22 -15
- package/lib/parsers/typescript/components/componentsUtils.js +29 -15
- package/lib/parsers/typescript/components/componentsUtils.js.flow +31 -15
- package/package.json +1 -1
package/lib/CodegenSchema.d.ts
CHANGED
|
@@ -199,7 +199,16 @@ export type CommandParamTypeAnnotation =
|
|
|
199
199
|
| Int32TypeAnnotation
|
|
200
200
|
| DoubleTypeAnnotation
|
|
201
201
|
| FloatTypeAnnotation
|
|
202
|
-
| StringTypeAnnotation
|
|
202
|
+
| StringTypeAnnotation
|
|
203
|
+
| {
|
|
204
|
+
readonly type: 'ArrayTypeAnnotation';
|
|
205
|
+
readonly elementType:
|
|
206
|
+
| Int32TypeAnnotation
|
|
207
|
+
| DoubleTypeAnnotation
|
|
208
|
+
| FloatTypeAnnotation
|
|
209
|
+
| BooleanTypeAnnotation
|
|
210
|
+
| StringTypeAnnotation
|
|
211
|
+
};
|
|
203
212
|
|
|
204
213
|
export interface ReservedTypeAnnotation {
|
|
205
214
|
readonly type: 'ReservedTypeAnnotation';
|
|
@@ -988,10 +988,16 @@ export type ScrollTo = (
|
|
|
988
988
|
|
|
989
989
|
interface NativeCommands {
|
|
990
990
|
+scrollTo: ScrollTo;
|
|
991
|
+
+addOverlays: (
|
|
992
|
+
viewRef: React.ElementRef<NativeType>,
|
|
993
|
+
overlayColorsReadOnly: $ReadOnlyArray<string>,
|
|
994
|
+
overlayColorsArray: Array<string>,
|
|
995
|
+
overlayColorsArrayAnnotation: string[],
|
|
996
|
+
) => void;
|
|
991
997
|
}
|
|
992
998
|
|
|
993
999
|
export const Commands = codegenNativeCommands<NativeCommands>({
|
|
994
|
-
supportedCommands: ['scrollTo'],
|
|
1000
|
+
supportedCommands: ['scrollTo', 'addOverlays'],
|
|
995
1001
|
});
|
|
996
1002
|
|
|
997
1003
|
export default (codegenNativeComponent<ModuleProps>(
|
|
@@ -1001,10 +1001,16 @@ export type ScrollTo = (
|
|
|
1001
1001
|
|
|
1002
1002
|
interface NativeCommands {
|
|
1003
1003
|
+scrollTo: ScrollTo;
|
|
1004
|
+
+addOverlays: (
|
|
1005
|
+
viewRef: React.ElementRef<NativeType>,
|
|
1006
|
+
overlayColorsReadOnly: $ReadOnlyArray<string>,
|
|
1007
|
+
overlayColorsArray: Array<string>,
|
|
1008
|
+
overlayColorsArrayAnnotation: string[],
|
|
1009
|
+
) => void;
|
|
1004
1010
|
}
|
|
1005
1011
|
|
|
1006
1012
|
export const Commands = codegenNativeCommands<NativeCommands>({
|
|
1007
|
-
supportedCommands: ['scrollTo'],
|
|
1013
|
+
supportedCommands: ['scrollTo', 'addOverlays'],
|
|
1008
1014
|
});
|
|
1009
1015
|
|
|
1010
1016
|
export default (codegenNativeComponent<ModuleProps>(
|
|
@@ -1094,13 +1094,20 @@ export type ScrollTo = (
|
|
|
1094
1094
|
y: Int,
|
|
1095
1095
|
animated: Boolean,
|
|
1096
1096
|
) => Void;
|
|
1097
|
+
export type AddOverlays = (
|
|
1098
|
+
viewRef: React.ElementRef<NativeType>,
|
|
1099
|
+
overlayColorsReadOnly: ReadOnlyArray<string>,
|
|
1100
|
+
overlayColorsArray: Array<string>,
|
|
1101
|
+
overlayColorsArrayAnnotation: string[],
|
|
1102
|
+
) => Void;
|
|
1097
1103
|
|
|
1098
1104
|
interface NativeCommands {
|
|
1099
1105
|
readonly scrollTo: ScrollTo;
|
|
1106
|
+
readonly addOverlays: AddOverlays;
|
|
1100
1107
|
}
|
|
1101
1108
|
|
|
1102
1109
|
export const Commands = codegenNativeCommands<NativeCommands>({
|
|
1103
|
-
supportedCommands: ['scrollTo'],
|
|
1110
|
+
supportedCommands: ['scrollTo', 'addOverlays'],
|
|
1104
1111
|
});
|
|
1105
1112
|
|
|
1106
1113
|
export default codegenNativeComponent<ModuleProps>('Module') as NativeType;
|
|
@@ -1108,13 +1108,20 @@ export type ScrollTo = (
|
|
|
1108
1108
|
y: Int,
|
|
1109
1109
|
animated: Boolean,
|
|
1110
1110
|
) => Void;
|
|
1111
|
+
export type AddOverlays = (
|
|
1112
|
+
viewRef: React.ElementRef<NativeType>,
|
|
1113
|
+
overlayColorsReadOnly: ReadOnlyArray<string>,
|
|
1114
|
+
overlayColorsArray: Array<string>,
|
|
1115
|
+
overlayColorsArrayAnnotation: string[],
|
|
1116
|
+
) => Void;
|
|
1111
1117
|
|
|
1112
1118
|
interface NativeCommands {
|
|
1113
1119
|
readonly scrollTo: ScrollTo;
|
|
1120
|
+
readonly addOverlays: AddOverlays;
|
|
1114
1121
|
}
|
|
1115
1122
|
|
|
1116
1123
|
export const Commands = codegenNativeCommands<NativeCommands>({
|
|
1117
|
-
supportedCommands: ['scrollTo'],
|
|
1124
|
+
supportedCommands: ['scrollTo', 'addOverlays'],
|
|
1118
1125
|
});
|
|
1119
1126
|
|
|
1120
1127
|
export default codegenNativeComponent<ModuleProps>('Module') as NativeType;
|
|
@@ -12,6 +12,8 @@
|
|
|
12
12
|
|
|
13
13
|
const _require = require('../parseTopLevelType'),
|
|
14
14
|
parseTopLevelType = _require.parseTopLevelType;
|
|
15
|
+
const _require2 = require('./componentsUtils'),
|
|
16
|
+
getPrimitiveTypeAnnotation = _require2.getPrimitiveTypeAnnotation;
|
|
15
17
|
|
|
16
18
|
// $FlowFixMe[unclear-type] there's no flowtype for ASTs
|
|
17
19
|
|
|
@@ -55,28 +57,34 @@ function buildCommandSchemaInternal(name, optional, parameters, types) {
|
|
|
55
57
|
};
|
|
56
58
|
break;
|
|
57
59
|
case 'TSBooleanKeyword':
|
|
58
|
-
returnType = {
|
|
59
|
-
type: 'BooleanTypeAnnotation',
|
|
60
|
-
};
|
|
61
|
-
break;
|
|
62
60
|
case 'Int32':
|
|
63
|
-
returnType = {
|
|
64
|
-
type: 'Int32TypeAnnotation',
|
|
65
|
-
};
|
|
66
|
-
break;
|
|
67
61
|
case 'Double':
|
|
68
|
-
returnType = {
|
|
69
|
-
type: 'DoubleTypeAnnotation',
|
|
70
|
-
};
|
|
71
|
-
break;
|
|
72
62
|
case 'Float':
|
|
63
|
+
case 'TSStringKeyword':
|
|
64
|
+
returnType = getPrimitiveTypeAnnotation(type);
|
|
65
|
+
break;
|
|
66
|
+
case 'Array':
|
|
67
|
+
case 'ReadOnlyArray':
|
|
68
|
+
if (!paramValue.type === 'TSTypeReference') {
|
|
69
|
+
throw new Error(
|
|
70
|
+
'Array and ReadOnlyArray are TSTypeReference for array',
|
|
71
|
+
);
|
|
72
|
+
}
|
|
73
73
|
returnType = {
|
|
74
|
-
type: '
|
|
74
|
+
type: 'ArrayTypeAnnotation',
|
|
75
|
+
elementType: getPrimitiveTypeAnnotation(
|
|
76
|
+
// TODO: T172453752 support complex type annotation for array element
|
|
77
|
+
paramValue.typeParameters.params[0].type,
|
|
78
|
+
),
|
|
75
79
|
};
|
|
76
80
|
break;
|
|
77
|
-
case '
|
|
81
|
+
case 'TSArrayType':
|
|
78
82
|
returnType = {
|
|
79
|
-
type: '
|
|
83
|
+
type: 'ArrayTypeAnnotation',
|
|
84
|
+
elementType: {
|
|
85
|
+
// TODO: T172453752 support complex type annotation for array element
|
|
86
|
+
type: getPrimitiveTypeAnnotation(paramValue.elementType.type).type,
|
|
87
|
+
},
|
|
80
88
|
};
|
|
81
89
|
break;
|
|
82
90
|
default:
|
|
@@ -17,6 +17,7 @@ import type {
|
|
|
17
17
|
import type {TypeDeclarationMap} from '../../utils';
|
|
18
18
|
|
|
19
19
|
const {parseTopLevelType} = require('../parseTopLevelType');
|
|
20
|
+
const {getPrimitiveTypeAnnotation} = require('./componentsUtils');
|
|
20
21
|
|
|
21
22
|
// $FlowFixMe[unclear-type] there's no flowtype for ASTs
|
|
22
23
|
type EventTypeAST = Object;
|
|
@@ -62,28 +63,34 @@ function buildCommandSchemaInternal(
|
|
|
62
63
|
};
|
|
63
64
|
break;
|
|
64
65
|
case 'TSBooleanKeyword':
|
|
65
|
-
returnType = {
|
|
66
|
-
type: 'BooleanTypeAnnotation',
|
|
67
|
-
};
|
|
68
|
-
break;
|
|
69
66
|
case 'Int32':
|
|
70
|
-
returnType = {
|
|
71
|
-
type: 'Int32TypeAnnotation',
|
|
72
|
-
};
|
|
73
|
-
break;
|
|
74
67
|
case 'Double':
|
|
75
|
-
returnType = {
|
|
76
|
-
type: 'DoubleTypeAnnotation',
|
|
77
|
-
};
|
|
78
|
-
break;
|
|
79
68
|
case 'Float':
|
|
69
|
+
case 'TSStringKeyword':
|
|
70
|
+
returnType = getPrimitiveTypeAnnotation(type);
|
|
71
|
+
break;
|
|
72
|
+
case 'Array':
|
|
73
|
+
case 'ReadOnlyArray':
|
|
74
|
+
if (!paramValue.type === 'TSTypeReference') {
|
|
75
|
+
throw new Error(
|
|
76
|
+
'Array and ReadOnlyArray are TSTypeReference for array',
|
|
77
|
+
);
|
|
78
|
+
}
|
|
80
79
|
returnType = {
|
|
81
|
-
type: '
|
|
80
|
+
type: 'ArrayTypeAnnotation',
|
|
81
|
+
elementType: getPrimitiveTypeAnnotation(
|
|
82
|
+
// TODO: T172453752 support complex type annotation for array element
|
|
83
|
+
paramValue.typeParameters.params[0].type,
|
|
84
|
+
),
|
|
82
85
|
};
|
|
83
86
|
break;
|
|
84
|
-
case '
|
|
87
|
+
case 'TSArrayType':
|
|
85
88
|
returnType = {
|
|
86
|
-
type: '
|
|
89
|
+
type: 'ArrayTypeAnnotation',
|
|
90
|
+
elementType: {
|
|
91
|
+
// TODO: T172453752 support complex type annotation for array element
|
|
92
|
+
type: getPrimitiveTypeAnnotation(paramValue.elementType.type).type,
|
|
93
|
+
},
|
|
87
94
|
};
|
|
88
95
|
break;
|
|
89
96
|
default:
|
|
@@ -147,6 +147,33 @@ function buildObjectType(rawProperties, types, parser, buildSchema) {
|
|
|
147
147
|
properties,
|
|
148
148
|
};
|
|
149
149
|
}
|
|
150
|
+
function getPrimitiveTypeAnnotation(type) {
|
|
151
|
+
switch (type) {
|
|
152
|
+
case 'Int32':
|
|
153
|
+
return {
|
|
154
|
+
type: 'Int32TypeAnnotation',
|
|
155
|
+
};
|
|
156
|
+
case 'Double':
|
|
157
|
+
return {
|
|
158
|
+
type: 'DoubleTypeAnnotation',
|
|
159
|
+
};
|
|
160
|
+
case 'Float':
|
|
161
|
+
return {
|
|
162
|
+
type: 'FloatTypeAnnotation',
|
|
163
|
+
};
|
|
164
|
+
case 'TSBooleanKeyword':
|
|
165
|
+
return {
|
|
166
|
+
type: 'BooleanTypeAnnotation',
|
|
167
|
+
};
|
|
168
|
+
case 'Stringish':
|
|
169
|
+
case 'TSStringKeyword':
|
|
170
|
+
return {
|
|
171
|
+
type: 'StringTypeAnnotation',
|
|
172
|
+
};
|
|
173
|
+
default:
|
|
174
|
+
throw new Error(`Unknown primitive type "${type}"`);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
150
177
|
function getCommonTypeAnnotation(
|
|
151
178
|
name,
|
|
152
179
|
forArray,
|
|
@@ -214,26 +241,12 @@ function getCommonTypeAnnotation(
|
|
|
214
241
|
types,
|
|
215
242
|
);
|
|
216
243
|
case 'Int32':
|
|
217
|
-
return {
|
|
218
|
-
type: 'Int32TypeAnnotation',
|
|
219
|
-
};
|
|
220
244
|
case 'Double':
|
|
221
|
-
return {
|
|
222
|
-
type: 'DoubleTypeAnnotation',
|
|
223
|
-
};
|
|
224
245
|
case 'Float':
|
|
225
|
-
return {
|
|
226
|
-
type: 'FloatTypeAnnotation',
|
|
227
|
-
};
|
|
228
246
|
case 'TSBooleanKeyword':
|
|
229
|
-
return {
|
|
230
|
-
type: 'BooleanTypeAnnotation',
|
|
231
|
-
};
|
|
232
247
|
case 'Stringish':
|
|
233
248
|
case 'TSStringKeyword':
|
|
234
|
-
return
|
|
235
|
-
type: 'StringTypeAnnotation',
|
|
236
|
-
};
|
|
249
|
+
return getPrimitiveTypeAnnotation(type);
|
|
237
250
|
case 'UnsafeMixed':
|
|
238
251
|
return {
|
|
239
252
|
type: 'MixedTypeAnnotation',
|
|
@@ -472,5 +485,6 @@ function flattenProperties(typeDefinition, types, parser) {
|
|
|
472
485
|
module.exports = {
|
|
473
486
|
getSchemaInfo,
|
|
474
487
|
getTypeAnnotation,
|
|
488
|
+
getPrimitiveTypeAnnotation,
|
|
475
489
|
flattenProperties,
|
|
476
490
|
};
|
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
11
|
'use strict';
|
|
12
|
+
|
|
12
13
|
import type {BuildSchemaFN, Parser} from '../../parser';
|
|
13
14
|
import type {ASTNode, PropAST, TypeDeclarationMap} from '../../utils';
|
|
14
15
|
|
|
@@ -158,6 +159,34 @@ function buildObjectType<T>(
|
|
|
158
159
|
};
|
|
159
160
|
}
|
|
160
161
|
|
|
162
|
+
function getPrimitiveTypeAnnotation(type: string): $FlowFixMe {
|
|
163
|
+
switch (type) {
|
|
164
|
+
case 'Int32':
|
|
165
|
+
return {
|
|
166
|
+
type: 'Int32TypeAnnotation',
|
|
167
|
+
};
|
|
168
|
+
case 'Double':
|
|
169
|
+
return {
|
|
170
|
+
type: 'DoubleTypeAnnotation',
|
|
171
|
+
};
|
|
172
|
+
case 'Float':
|
|
173
|
+
return {
|
|
174
|
+
type: 'FloatTypeAnnotation',
|
|
175
|
+
};
|
|
176
|
+
case 'TSBooleanKeyword':
|
|
177
|
+
return {
|
|
178
|
+
type: 'BooleanTypeAnnotation',
|
|
179
|
+
};
|
|
180
|
+
case 'Stringish':
|
|
181
|
+
case 'TSStringKeyword':
|
|
182
|
+
return {
|
|
183
|
+
type: 'StringTypeAnnotation',
|
|
184
|
+
};
|
|
185
|
+
default:
|
|
186
|
+
throw new Error(`Unknown primitive type "${type}"`);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
|
|
161
190
|
function getCommonTypeAnnotation<T>(
|
|
162
191
|
name: string,
|
|
163
192
|
forArray: boolean,
|
|
@@ -225,26 +254,12 @@ function getCommonTypeAnnotation<T>(
|
|
|
225
254
|
types,
|
|
226
255
|
);
|
|
227
256
|
case 'Int32':
|
|
228
|
-
return {
|
|
229
|
-
type: 'Int32TypeAnnotation',
|
|
230
|
-
};
|
|
231
257
|
case 'Double':
|
|
232
|
-
return {
|
|
233
|
-
type: 'DoubleTypeAnnotation',
|
|
234
|
-
};
|
|
235
258
|
case 'Float':
|
|
236
|
-
return {
|
|
237
|
-
type: 'FloatTypeAnnotation',
|
|
238
|
-
};
|
|
239
259
|
case 'TSBooleanKeyword':
|
|
240
|
-
return {
|
|
241
|
-
type: 'BooleanTypeAnnotation',
|
|
242
|
-
};
|
|
243
260
|
case 'Stringish':
|
|
244
261
|
case 'TSStringKeyword':
|
|
245
|
-
return
|
|
246
|
-
type: 'StringTypeAnnotation',
|
|
247
|
-
};
|
|
262
|
+
return getPrimitiveTypeAnnotation(type);
|
|
248
263
|
case 'UnsafeMixed':
|
|
249
264
|
return {
|
|
250
265
|
type: 'MixedTypeAnnotation',
|
|
@@ -513,5 +528,6 @@ function flattenProperties(
|
|
|
513
528
|
module.exports = {
|
|
514
529
|
getSchemaInfo,
|
|
515
530
|
getTypeAnnotation,
|
|
531
|
+
getPrimitiveTypeAnnotation,
|
|
516
532
|
flattenProperties,
|
|
517
533
|
};
|