@react-native/codegen 0.73.0-nightly-20230807-f9a63ec00 → 0.73.0-nightly-20230807-2bf59c764
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/parsers/flow/components/events.js +6 -18
- package/lib/parsers/flow/components/events.js.flow +7 -22
- package/lib/parsers/parsers-commons.js +29 -0
- package/lib/parsers/parsers-commons.js.flow +43 -0
- package/lib/parsers/typescript/components/events.js +9 -21
- package/lib/parsers/typescript/components/events.js.flow +8 -21
- package/package.json +1 -1
|
@@ -16,7 +16,8 @@ const _require = require('../../error-utils'),
|
|
|
16
16
|
throwIfArgumentPropsAreNull = _require.throwIfArgumentPropsAreNull;
|
|
17
17
|
const _require2 = require('../../parsers-commons'),
|
|
18
18
|
getEventArgument = _require2.getEventArgument,
|
|
19
|
-
buildPropertiesForEvent = _require2.buildPropertiesForEvent
|
|
19
|
+
buildPropertiesForEvent = _require2.buildPropertiesForEvent,
|
|
20
|
+
handleEventHandler = _require2.handleEventHandler;
|
|
20
21
|
const _require3 = require('../../parsers-primitives'),
|
|
21
22
|
emitBoolProp = _require3.emitBoolProp,
|
|
22
23
|
emitDoubleProp = _require3.emitDoubleProp,
|
|
@@ -174,25 +175,12 @@ function findEventArgumentsAndType(
|
|
|
174
175
|
bubblingType,
|
|
175
176
|
};
|
|
176
177
|
} else if (name === 'BubblingEventHandler' || name === 'DirectEventHandler') {
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
if (
|
|
181
|
-
typeAnnotation.typeParameters.params[0].type ===
|
|
182
|
-
parser.nullLiteralTypeAnnotation
|
|
183
|
-
) {
|
|
184
|
-
return {
|
|
185
|
-
argumentProps: [],
|
|
186
|
-
bubblingType: eventType,
|
|
187
|
-
paperTopLevelNameDeprecated,
|
|
188
|
-
};
|
|
189
|
-
}
|
|
190
|
-
return findEventArgumentsAndType(
|
|
178
|
+
return handleEventHandler(
|
|
179
|
+
name,
|
|
180
|
+
typeAnnotation,
|
|
191
181
|
parser,
|
|
192
|
-
typeAnnotation.typeParameters.params[0],
|
|
193
182
|
types,
|
|
194
|
-
|
|
195
|
-
paperTopLevelNameDeprecated,
|
|
183
|
+
findEventArgumentsAndType,
|
|
196
184
|
);
|
|
197
185
|
} else if (types[name]) {
|
|
198
186
|
return findEventArgumentsAndType(
|
|
@@ -16,6 +16,7 @@ import type {
|
|
|
16
16
|
EventTypeAnnotation,
|
|
17
17
|
} from '../../../CodegenSchema.js';
|
|
18
18
|
import type {Parser} from '../../parser';
|
|
19
|
+
import type {EventArgumentReturnType} from '../../parsers-commons';
|
|
19
20
|
|
|
20
21
|
const {
|
|
21
22
|
throwIfEventHasNoName,
|
|
@@ -25,6 +26,7 @@ const {
|
|
|
25
26
|
const {
|
|
26
27
|
getEventArgument,
|
|
27
28
|
buildPropertiesForEvent,
|
|
29
|
+
handleEventHandler,
|
|
28
30
|
} = require('../../parsers-commons');
|
|
29
31
|
const {
|
|
30
32
|
emitBoolProp,
|
|
@@ -178,11 +180,7 @@ function findEventArgumentsAndType(
|
|
|
178
180
|
types: TypeMap,
|
|
179
181
|
bubblingType: void | 'direct' | 'bubble',
|
|
180
182
|
paperName: ?$FlowFixMe,
|
|
181
|
-
): {
|
|
182
|
-
argumentProps: $FlowFixMe,
|
|
183
|
-
bubblingType: ?('direct' | 'bubble'),
|
|
184
|
-
paperTopLevelNameDeprecated: ?$FlowFixMe,
|
|
185
|
-
} {
|
|
183
|
+
): EventArgumentReturnType {
|
|
186
184
|
throwIfEventHasNoName(typeAnnotation, parser);
|
|
187
185
|
const name = parser.getTypeAnnotationName(typeAnnotation);
|
|
188
186
|
if (name === '$ReadOnly') {
|
|
@@ -192,25 +190,12 @@ function findEventArgumentsAndType(
|
|
|
192
190
|
bubblingType,
|
|
193
191
|
};
|
|
194
192
|
} else if (name === 'BubblingEventHandler' || name === 'DirectEventHandler') {
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
if (
|
|
199
|
-
typeAnnotation.typeParameters.params[0].type ===
|
|
200
|
-
parser.nullLiteralTypeAnnotation
|
|
201
|
-
) {
|
|
202
|
-
return {
|
|
203
|
-
argumentProps: [],
|
|
204
|
-
bubblingType: eventType,
|
|
205
|
-
paperTopLevelNameDeprecated,
|
|
206
|
-
};
|
|
207
|
-
}
|
|
208
|
-
return findEventArgumentsAndType(
|
|
193
|
+
return handleEventHandler(
|
|
194
|
+
name,
|
|
195
|
+
typeAnnotation,
|
|
209
196
|
parser,
|
|
210
|
-
typeAnnotation.typeParameters.params[0],
|
|
211
197
|
types,
|
|
212
|
-
|
|
213
|
-
paperTopLevelNameDeprecated,
|
|
198
|
+
findEventArgumentsAndType,
|
|
214
199
|
);
|
|
215
200
|
} else if (types[name]) {
|
|
216
201
|
return findEventArgumentsAndType(
|
|
@@ -1007,6 +1007,34 @@ function verifyPropNotAlreadyDefined(props, needleProp) {
|
|
|
1007
1007
|
throw new Error(`A prop was already defined with the name ${propName}`);
|
|
1008
1008
|
}
|
|
1009
1009
|
}
|
|
1010
|
+
function handleEventHandler(
|
|
1011
|
+
name,
|
|
1012
|
+
typeAnnotation,
|
|
1013
|
+
parser,
|
|
1014
|
+
types,
|
|
1015
|
+
findEventArgumentsAndType,
|
|
1016
|
+
) {
|
|
1017
|
+
const eventType = name === 'BubblingEventHandler' ? 'bubble' : 'direct';
|
|
1018
|
+
const paperTopLevelNameDeprecated =
|
|
1019
|
+
parser.getPaperTopLevelNameDeprecated(typeAnnotation);
|
|
1020
|
+
switch (typeAnnotation.typeParameters.params[0].type) {
|
|
1021
|
+
case parser.nullLiteralTypeAnnotation:
|
|
1022
|
+
case parser.undefinedLiteralTypeAnnotation:
|
|
1023
|
+
return {
|
|
1024
|
+
argumentProps: [],
|
|
1025
|
+
bubblingType: eventType,
|
|
1026
|
+
paperTopLevelNameDeprecated,
|
|
1027
|
+
};
|
|
1028
|
+
default:
|
|
1029
|
+
return findEventArgumentsAndType(
|
|
1030
|
+
parser,
|
|
1031
|
+
typeAnnotation.typeParameters.params[0],
|
|
1032
|
+
types,
|
|
1033
|
+
eventType,
|
|
1034
|
+
paperTopLevelNameDeprecated,
|
|
1035
|
+
);
|
|
1036
|
+
}
|
|
1037
|
+
}
|
|
1010
1038
|
module.exports = {
|
|
1011
1039
|
wrapModuleSchema,
|
|
1012
1040
|
unwrapNullable,
|
|
@@ -1035,4 +1063,5 @@ module.exports = {
|
|
|
1035
1063
|
getTypeResolutionStatus,
|
|
1036
1064
|
buildPropertiesForEvent,
|
|
1037
1065
|
verifyPropNotAlreadyDefined,
|
|
1066
|
+
handleEventHandler,
|
|
1038
1067
|
};
|
|
@@ -87,6 +87,12 @@ type ExtendedPropResult = {
|
|
|
87
87
|
knownTypeName: 'ReactNativeCoreViewProps',
|
|
88
88
|
} | null;
|
|
89
89
|
|
|
90
|
+
export type EventArgumentReturnType = {
|
|
91
|
+
argumentProps: ?$ReadOnlyArray<$FlowFixMe>,
|
|
92
|
+
paperTopLevelNameDeprecated: ?$FlowFixMe,
|
|
93
|
+
bubblingType: ?'direct' | 'bubble',
|
|
94
|
+
};
|
|
95
|
+
|
|
90
96
|
function wrapModuleSchema(
|
|
91
97
|
nativeModuleSchema: NativeModuleSchema,
|
|
92
98
|
hasteModuleName: string,
|
|
@@ -1083,6 +1089,42 @@ function verifyPropNotAlreadyDefined(
|
|
|
1083
1089
|
}
|
|
1084
1090
|
}
|
|
1085
1091
|
|
|
1092
|
+
function handleEventHandler(
|
|
1093
|
+
name: 'BubblingEventHandler' | 'DirectEventHandler',
|
|
1094
|
+
typeAnnotation: $FlowFixMe,
|
|
1095
|
+
parser: Parser,
|
|
1096
|
+
types: TypeDeclarationMap,
|
|
1097
|
+
findEventArgumentsAndType: (
|
|
1098
|
+
parser: Parser,
|
|
1099
|
+
typeAnnotation: $FlowFixMe,
|
|
1100
|
+
types: TypeDeclarationMap,
|
|
1101
|
+
bubblingType: void | 'direct' | 'bubble',
|
|
1102
|
+
paperName: ?$FlowFixMe,
|
|
1103
|
+
) => EventArgumentReturnType,
|
|
1104
|
+
): EventArgumentReturnType {
|
|
1105
|
+
const eventType = name === 'BubblingEventHandler' ? 'bubble' : 'direct';
|
|
1106
|
+
const paperTopLevelNameDeprecated =
|
|
1107
|
+
parser.getPaperTopLevelNameDeprecated(typeAnnotation);
|
|
1108
|
+
|
|
1109
|
+
switch (typeAnnotation.typeParameters.params[0].type) {
|
|
1110
|
+
case parser.nullLiteralTypeAnnotation:
|
|
1111
|
+
case parser.undefinedLiteralTypeAnnotation:
|
|
1112
|
+
return {
|
|
1113
|
+
argumentProps: [],
|
|
1114
|
+
bubblingType: eventType,
|
|
1115
|
+
paperTopLevelNameDeprecated,
|
|
1116
|
+
};
|
|
1117
|
+
default:
|
|
1118
|
+
return findEventArgumentsAndType(
|
|
1119
|
+
parser,
|
|
1120
|
+
typeAnnotation.typeParameters.params[0],
|
|
1121
|
+
types,
|
|
1122
|
+
eventType,
|
|
1123
|
+
paperTopLevelNameDeprecated,
|
|
1124
|
+
);
|
|
1125
|
+
}
|
|
1126
|
+
}
|
|
1127
|
+
|
|
1086
1128
|
module.exports = {
|
|
1087
1129
|
wrapModuleSchema,
|
|
1088
1130
|
unwrapNullable,
|
|
@@ -1111,4 +1153,5 @@ module.exports = {
|
|
|
1111
1153
|
getTypeResolutionStatus,
|
|
1112
1154
|
buildPropertiesForEvent,
|
|
1113
1155
|
verifyPropNotAlreadyDefined,
|
|
1156
|
+
handleEventHandler,
|
|
1114
1157
|
};
|
|
@@ -20,7 +20,8 @@ const _require3 = require('../../error-utils'),
|
|
|
20
20
|
throwIfArgumentPropsAreNull = _require3.throwIfArgumentPropsAreNull;
|
|
21
21
|
const _require4 = require('../../parsers-commons'),
|
|
22
22
|
getEventArgument = _require4.getEventArgument,
|
|
23
|
-
buildPropertiesForEvent = _require4.buildPropertiesForEvent
|
|
23
|
+
buildPropertiesForEvent = _require4.buildPropertiesForEvent,
|
|
24
|
+
handleEventHandler = _require4.handleEventHandler;
|
|
24
25
|
const _require5 = require('../../parsers-primitives'),
|
|
25
26
|
emitBoolProp = _require5.emitBoolProp,
|
|
26
27
|
emitDoubleProp = _require5.emitDoubleProp,
|
|
@@ -182,26 +183,13 @@ function findEventArgumentsAndType(
|
|
|
182
183
|
paperName,
|
|
183
184
|
);
|
|
184
185
|
} else if (name === 'BubblingEventHandler' || name === 'DirectEventHandler') {
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
argumentProps: [],
|
|
193
|
-
bubblingType: eventType,
|
|
194
|
-
paperTopLevelNameDeprecated,
|
|
195
|
-
};
|
|
196
|
-
default:
|
|
197
|
-
return findEventArgumentsAndType(
|
|
198
|
-
parser,
|
|
199
|
-
typeAnnotation.typeParameters.params[0],
|
|
200
|
-
types,
|
|
201
|
-
eventType,
|
|
202
|
-
paperTopLevelNameDeprecated,
|
|
203
|
-
);
|
|
204
|
-
}
|
|
186
|
+
return handleEventHandler(
|
|
187
|
+
name,
|
|
188
|
+
typeAnnotation,
|
|
189
|
+
parser,
|
|
190
|
+
types,
|
|
191
|
+
findEventArgumentsAndType,
|
|
192
|
+
);
|
|
205
193
|
} else if (types[name]) {
|
|
206
194
|
let elementType = types[name];
|
|
207
195
|
if (elementType.type === 'TSTypeAliasDeclaration') {
|
|
@@ -27,6 +27,7 @@ const {
|
|
|
27
27
|
const {
|
|
28
28
|
getEventArgument,
|
|
29
29
|
buildPropertiesForEvent,
|
|
30
|
+
handleEventHandler,
|
|
30
31
|
} = require('../../parsers-commons');
|
|
31
32
|
const {
|
|
32
33
|
emitBoolProp,
|
|
@@ -204,27 +205,13 @@ function findEventArgumentsAndType(
|
|
|
204
205
|
paperName,
|
|
205
206
|
);
|
|
206
207
|
} else if (name === 'BubblingEventHandler' || name === 'DirectEventHandler') {
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
return {
|
|
215
|
-
argumentProps: [],
|
|
216
|
-
bubblingType: eventType,
|
|
217
|
-
paperTopLevelNameDeprecated,
|
|
218
|
-
};
|
|
219
|
-
default:
|
|
220
|
-
return findEventArgumentsAndType(
|
|
221
|
-
parser,
|
|
222
|
-
typeAnnotation.typeParameters.params[0],
|
|
223
|
-
types,
|
|
224
|
-
eventType,
|
|
225
|
-
paperTopLevelNameDeprecated,
|
|
226
|
-
);
|
|
227
|
-
}
|
|
208
|
+
return handleEventHandler(
|
|
209
|
+
name,
|
|
210
|
+
typeAnnotation,
|
|
211
|
+
parser,
|
|
212
|
+
types,
|
|
213
|
+
findEventArgumentsAndType,
|
|
214
|
+
);
|
|
228
215
|
} else if (types[name]) {
|
|
229
216
|
let elementType = types[name];
|
|
230
217
|
if (elementType.type === 'TSTypeAliasDeclaration') {
|