@react-native/codegen 0.79.0-rc.1 → 0.79.0-rc.2
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.
|
@@ -10,7 +10,8 @@
|
|
|
10
10
|
|
|
11
11
|
'use strict';
|
|
12
12
|
|
|
13
|
-
const
|
|
13
|
+
const core = require('@babel/core');
|
|
14
|
+
const t = core.types;
|
|
14
15
|
|
|
15
16
|
// File path -> contents
|
|
16
17
|
|
|
@@ -36,6 +37,9 @@ ${componentConfig}
|
|
|
36
37
|
// We use this to add to a set. Need to make sure we aren't importing
|
|
37
38
|
// this multiple times.
|
|
38
39
|
const UIMANAGER_IMPORT = 'const {UIManager} = require("react-native")';
|
|
40
|
+
function expression(input) {
|
|
41
|
+
return core.template.expression(input)();
|
|
42
|
+
}
|
|
39
43
|
function getReactDiffProcessValue(typeAnnotation) {
|
|
40
44
|
switch (typeAnnotation.type) {
|
|
41
45
|
case 'BooleanTypeAnnotation':
|
|
@@ -47,25 +51,29 @@ function getReactDiffProcessValue(typeAnnotation) {
|
|
|
47
51
|
case 'StringEnumTypeAnnotation':
|
|
48
52
|
case 'Int32EnumTypeAnnotation':
|
|
49
53
|
case 'MixedTypeAnnotation':
|
|
50
|
-
return
|
|
54
|
+
return t.booleanLiteral(true);
|
|
51
55
|
case 'ReservedPropTypeAnnotation':
|
|
52
56
|
switch (typeAnnotation.name) {
|
|
53
57
|
case 'ColorPrimitive':
|
|
54
|
-
return
|
|
55
|
-
|
|
58
|
+
return expression(
|
|
59
|
+
`{ process: require('react-native/Libraries/StyleSheet/processColor').default }`,
|
|
60
|
+
);
|
|
56
61
|
case 'ImageSourcePrimitive':
|
|
57
|
-
return
|
|
58
|
-
|
|
62
|
+
return expression(
|
|
63
|
+
`{ process: require('react-native/Libraries/Image/resolveAssetSource') }`,
|
|
64
|
+
);
|
|
59
65
|
case 'ImageRequestPrimitive':
|
|
60
66
|
throw new Error('ImageRequest should not be used in props');
|
|
61
67
|
case 'PointPrimitive':
|
|
62
|
-
return
|
|
63
|
-
|
|
68
|
+
return expression(
|
|
69
|
+
`{ diff: ((req) => 'default' in req ? req.default : req)(require('react-native/Libraries/Utilities/differ/pointsDiffer')) }`,
|
|
70
|
+
);
|
|
64
71
|
case 'EdgeInsetsPrimitive':
|
|
65
|
-
return
|
|
66
|
-
|
|
72
|
+
return expression(
|
|
73
|
+
`{ diff: ((req) => 'default' in req ? req.default : req)(require('react-native/Libraries/Utilities/differ/insetsDiffer')) }`,
|
|
74
|
+
);
|
|
67
75
|
case 'DimensionPrimitive':
|
|
68
|
-
return
|
|
76
|
+
return t.booleanLiteral(true);
|
|
69
77
|
default:
|
|
70
78
|
typeAnnotation.name;
|
|
71
79
|
throw new Error(
|
|
@@ -76,20 +84,21 @@ function getReactDiffProcessValue(typeAnnotation) {
|
|
|
76
84
|
if (typeAnnotation.elementType.type === 'ReservedPropTypeAnnotation') {
|
|
77
85
|
switch (typeAnnotation.elementType.name) {
|
|
78
86
|
case 'ColorPrimitive':
|
|
79
|
-
return
|
|
80
|
-
|
|
87
|
+
return expression(
|
|
88
|
+
`{ process: ((req) => 'default' in req ? req.default : req)(require('react-native/Libraries/StyleSheet/processColorArray')) }`,
|
|
89
|
+
);
|
|
81
90
|
case 'ImageSourcePrimitive':
|
|
82
91
|
case 'PointPrimitive':
|
|
83
92
|
case 'EdgeInsetsPrimitive':
|
|
84
93
|
case 'DimensionPrimitive':
|
|
85
|
-
return
|
|
94
|
+
return t.booleanLiteral(true);
|
|
86
95
|
default:
|
|
87
96
|
throw new Error(
|
|
88
97
|
`Received unknown array native typeAnnotation: "${typeAnnotation.elementType.name}"`,
|
|
89
98
|
);
|
|
90
99
|
}
|
|
91
100
|
}
|
|
92
|
-
return
|
|
101
|
+
return t.booleanLiteral(true);
|
|
93
102
|
default:
|
|
94
103
|
typeAnnotation;
|
|
95
104
|
throw new Error(
|
|
@@ -117,7 +126,7 @@ ${
|
|
|
117
126
|
: ''
|
|
118
127
|
}
|
|
119
128
|
|
|
120
|
-
export const __INTERNAL_VIEW_CONFIG = VIEW_CONFIG
|
|
129
|
+
export const __INTERNAL_VIEW_CONFIG = %%VIEW_CONFIG%%;
|
|
121
130
|
|
|
122
131
|
export default NativeComponentRegistry.get(nativeComponentName, () => __INTERNAL_VIEW_CONFIG);
|
|
123
132
|
`.trim();
|
|
@@ -155,44 +164,45 @@ function getValidAttributesForEvents(events, imports) {
|
|
|
155
164
|
imports.add(
|
|
156
165
|
"const {ConditionallyIgnoredEventHandlers} = require('react-native/Libraries/NativeComponent/ViewConfigIgnore');",
|
|
157
166
|
);
|
|
158
|
-
const validAttributes =
|
|
167
|
+
const validAttributes = t.objectExpression(
|
|
159
168
|
events.map(eventType => {
|
|
160
|
-
return
|
|
169
|
+
return t.objectProperty(
|
|
170
|
+
t.identifier(eventType.name),
|
|
171
|
+
t.booleanLiteral(true),
|
|
172
|
+
);
|
|
161
173
|
}),
|
|
162
174
|
);
|
|
163
|
-
return
|
|
175
|
+
return t.callExpression(t.identifier('ConditionallyIgnoredEventHandlers'), [
|
|
164
176
|
validAttributes,
|
|
165
177
|
]);
|
|
166
178
|
}
|
|
167
179
|
function generateBubblingEventInfo(event, nameOveride) {
|
|
168
|
-
return
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
+
return t.objectProperty(
|
|
181
|
+
t.identifier(normalizeInputEventName(nameOveride || event.name)),
|
|
182
|
+
t.objectExpression([
|
|
183
|
+
t.objectProperty(
|
|
184
|
+
t.identifier('phasedRegistrationNames'),
|
|
185
|
+
t.objectExpression([
|
|
186
|
+
t.objectProperty(
|
|
187
|
+
t.identifier('captured'),
|
|
188
|
+
t.stringLiteral(`${event.name}Capture`),
|
|
189
|
+
),
|
|
190
|
+
t.objectProperty(
|
|
191
|
+
t.identifier('bubbled'),
|
|
192
|
+
t.stringLiteral(event.name),
|
|
180
193
|
),
|
|
181
|
-
j.property('init', j.identifier('bubbled'), j.literal(event.name)),
|
|
182
194
|
]),
|
|
183
195
|
),
|
|
184
196
|
]),
|
|
185
197
|
);
|
|
186
198
|
}
|
|
187
199
|
function generateDirectEventInfo(event, nameOveride) {
|
|
188
|
-
return
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
j.identifier('registrationName'),
|
|
195
|
-
j.literal(event.name),
|
|
200
|
+
return t.objectProperty(
|
|
201
|
+
t.identifier(normalizeInputEventName(nameOveride || event.name)),
|
|
202
|
+
t.objectExpression([
|
|
203
|
+
t.objectProperty(
|
|
204
|
+
t.identifier('registrationName'),
|
|
205
|
+
t.stringLiteral(event.name),
|
|
196
206
|
),
|
|
197
207
|
]),
|
|
198
208
|
);
|
|
@@ -218,20 +228,15 @@ function buildViewConfig(schema, componentName, component, imports) {
|
|
|
218
228
|
throw new Error('Invalid extended type');
|
|
219
229
|
}
|
|
220
230
|
});
|
|
221
|
-
const validAttributes =
|
|
231
|
+
const validAttributes = t.objectExpression([
|
|
222
232
|
...componentProps.map(schemaProp => {
|
|
223
|
-
return
|
|
224
|
-
|
|
225
|
-
j.identifier(schemaProp.name),
|
|
233
|
+
return t.objectProperty(
|
|
234
|
+
t.identifier(schemaProp.name),
|
|
226
235
|
getReactDiffProcessValue(schemaProp.typeAnnotation),
|
|
227
236
|
);
|
|
228
237
|
}),
|
|
229
238
|
...(componentEvents.length > 0
|
|
230
|
-
? [
|
|
231
|
-
j.spreadProperty(
|
|
232
|
-
getValidAttributesForEvents(componentEvents, imports),
|
|
233
|
-
),
|
|
234
|
-
]
|
|
239
|
+
? [t.spreadElement(getValidAttributesForEvents(componentEvents, imports))]
|
|
235
240
|
: []),
|
|
236
241
|
]);
|
|
237
242
|
const bubblingEventNames = component.events
|
|
@@ -249,14 +254,6 @@ function buildViewConfig(schema, componentName, component, imports) {
|
|
|
249
254
|
}
|
|
250
255
|
return bubblingEvents;
|
|
251
256
|
}, []);
|
|
252
|
-
const bubblingEvents =
|
|
253
|
-
bubblingEventNames.length > 0
|
|
254
|
-
? j.property(
|
|
255
|
-
'init',
|
|
256
|
-
j.identifier('bubblingEventTypes'),
|
|
257
|
-
j.objectExpression(bubblingEventNames),
|
|
258
|
-
)
|
|
259
|
-
: null;
|
|
260
257
|
const directEventNames = component.events
|
|
261
258
|
.filter(event => event.bubblingType === 'direct')
|
|
262
259
|
.reduce((directEvents, event) => {
|
|
@@ -272,25 +269,32 @@ function buildViewConfig(schema, componentName, component, imports) {
|
|
|
272
269
|
}
|
|
273
270
|
return directEvents;
|
|
274
271
|
}, []);
|
|
275
|
-
const directEvents =
|
|
276
|
-
directEventNames.length > 0
|
|
277
|
-
? j.property(
|
|
278
|
-
'init',
|
|
279
|
-
j.identifier('directEventTypes'),
|
|
280
|
-
j.objectExpression(directEventNames),
|
|
281
|
-
)
|
|
282
|
-
: null;
|
|
283
272
|
const properties = [
|
|
284
|
-
|
|
285
|
-
'
|
|
286
|
-
|
|
287
|
-
j.literal(componentName),
|
|
273
|
+
t.objectProperty(
|
|
274
|
+
t.identifier('uiViewClassName'),
|
|
275
|
+
t.stringLiteral(componentName),
|
|
288
276
|
),
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
277
|
+
];
|
|
278
|
+
if (bubblingEventNames.length > 0) {
|
|
279
|
+
properties.push(
|
|
280
|
+
t.objectProperty(
|
|
281
|
+
t.identifier('bubblingEventTypes'),
|
|
282
|
+
t.objectExpression(bubblingEventNames),
|
|
283
|
+
),
|
|
284
|
+
);
|
|
285
|
+
}
|
|
286
|
+
if (directEventNames.length > 0) {
|
|
287
|
+
properties.push(
|
|
288
|
+
t.objectProperty(
|
|
289
|
+
t.identifier('directEventTypes'),
|
|
290
|
+
t.objectExpression(directEventNames),
|
|
291
|
+
),
|
|
292
|
+
);
|
|
293
|
+
}
|
|
294
|
+
properties.push(
|
|
295
|
+
t.objectProperty(t.identifier('validAttributes'), validAttributes),
|
|
296
|
+
);
|
|
297
|
+
return t.objectExpression(properties);
|
|
294
298
|
}
|
|
295
299
|
function buildCommands(schema, componentName, component, imports) {
|
|
296
300
|
const commands = component.commands;
|
|
@@ -300,39 +304,29 @@ function buildCommands(schema, componentName, component, imports) {
|
|
|
300
304
|
imports.add(
|
|
301
305
|
'const {dispatchCommand} = require("react-native/Libraries/ReactNative/RendererProxy");',
|
|
302
306
|
);
|
|
303
|
-
const
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
),
|
|
326
|
-
);
|
|
327
|
-
property.method = true;
|
|
328
|
-
return property;
|
|
329
|
-
});
|
|
330
|
-
return j.exportNamedDeclaration(
|
|
331
|
-
j.variableDeclaration('const', [
|
|
332
|
-
j.variableDeclarator(
|
|
333
|
-
j.identifier('Commands'),
|
|
334
|
-
j.objectExpression(properties),
|
|
335
|
-
),
|
|
307
|
+
const commandsObject = t.objectExpression(
|
|
308
|
+
commands.map(command => {
|
|
309
|
+
const commandName = command.name;
|
|
310
|
+
const params = command.typeAnnotation.params;
|
|
311
|
+
const dispatchCommandCall = t.callExpression(
|
|
312
|
+
t.identifier('dispatchCommand'),
|
|
313
|
+
[
|
|
314
|
+
t.identifier('ref'),
|
|
315
|
+
t.stringLiteral(commandName),
|
|
316
|
+
t.arrayExpression(params.map(param => t.identifier(param.name))),
|
|
317
|
+
],
|
|
318
|
+
);
|
|
319
|
+
return t.objectMethod(
|
|
320
|
+
'method',
|
|
321
|
+
t.identifier(commandName),
|
|
322
|
+
[t.identifier('ref'), ...params.map(param => t.identifier(param.name))],
|
|
323
|
+
t.blockStatement([t.expressionStatement(dispatchCommandCall)]),
|
|
324
|
+
);
|
|
325
|
+
}),
|
|
326
|
+
);
|
|
327
|
+
return t.exportNamedDeclaration(
|
|
328
|
+
t.variableDeclaration('const', [
|
|
329
|
+
t.variableDeclarator(t.identifier('Commands'), commandsObject),
|
|
336
330
|
]),
|
|
337
331
|
);
|
|
338
332
|
}
|
|
@@ -361,40 +355,40 @@ module.exports = {
|
|
|
361
355
|
paperComponentNameDeprecated:
|
|
362
356
|
component.paperComponentNameDeprecated,
|
|
363
357
|
});
|
|
364
|
-
const replacedSourceRoot = j.withParser('flow')(replacedTemplate);
|
|
365
358
|
const paperComponentName =
|
|
366
359
|
(_component$paperCompo = component.paperComponentName) !==
|
|
367
360
|
null && _component$paperCompo !== void 0
|
|
368
361
|
? _component$paperCompo
|
|
369
362
|
: componentName;
|
|
370
|
-
replacedSourceRoot
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
);
|
|
382
|
-
const commands = buildCommands(
|
|
363
|
+
const replacedSourceRoot = core.template.program(
|
|
364
|
+
replacedTemplate,
|
|
365
|
+
)({
|
|
366
|
+
VIEW_CONFIG: buildViewConfig(
|
|
367
|
+
schema,
|
|
368
|
+
paperComponentName,
|
|
369
|
+
component,
|
|
370
|
+
imports,
|
|
371
|
+
),
|
|
372
|
+
});
|
|
373
|
+
const commandsExport = buildCommands(
|
|
383
374
|
schema,
|
|
384
375
|
paperComponentName,
|
|
385
376
|
component,
|
|
386
377
|
imports,
|
|
387
378
|
);
|
|
388
|
-
if (
|
|
389
|
-
replacedSourceRoot
|
|
390
|
-
.find(j.ExportDefaultDeclaration)
|
|
391
|
-
.insertAfter(j(commands).toSource());
|
|
379
|
+
if (commandsExport) {
|
|
380
|
+
replacedSourceRoot.body.push(commandsExport);
|
|
392
381
|
}
|
|
393
|
-
const replacedSource =
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
382
|
+
const replacedSource = core.transformFromAstSync(
|
|
383
|
+
replacedSourceRoot,
|
|
384
|
+
undefined,
|
|
385
|
+
{
|
|
386
|
+
babelrc: false,
|
|
387
|
+
browserslistConfigFile: false,
|
|
388
|
+
configFile: false,
|
|
389
|
+
},
|
|
390
|
+
);
|
|
391
|
+
return replacedSource.code;
|
|
398
392
|
})
|
|
399
393
|
.join('\n\n');
|
|
400
394
|
})
|
|
@@ -16,7 +16,8 @@ import type {
|
|
|
16
16
|
} from '../../CodegenSchema';
|
|
17
17
|
import type {SchemaType} from '../../CodegenSchema';
|
|
18
18
|
|
|
19
|
-
const
|
|
19
|
+
const core = require('@babel/core');
|
|
20
|
+
const t = core.types;
|
|
20
21
|
|
|
21
22
|
// File path -> contents
|
|
22
23
|
type FilesOutput = Map<string, string>;
|
|
@@ -50,6 +51,10 @@ ${componentConfig}
|
|
|
50
51
|
// this multiple times.
|
|
51
52
|
const UIMANAGER_IMPORT = 'const {UIManager} = require("react-native")';
|
|
52
53
|
|
|
54
|
+
function expression(input: string) {
|
|
55
|
+
return core.template.expression(input)();
|
|
56
|
+
}
|
|
57
|
+
|
|
53
58
|
function getReactDiffProcessValue(typeAnnotation: PropTypeAnnotation) {
|
|
54
59
|
switch (typeAnnotation.type) {
|
|
55
60
|
case 'BooleanTypeAnnotation':
|
|
@@ -61,25 +66,29 @@ function getReactDiffProcessValue(typeAnnotation: PropTypeAnnotation) {
|
|
|
61
66
|
case 'StringEnumTypeAnnotation':
|
|
62
67
|
case 'Int32EnumTypeAnnotation':
|
|
63
68
|
case 'MixedTypeAnnotation':
|
|
64
|
-
return
|
|
69
|
+
return t.booleanLiteral(true);
|
|
65
70
|
case 'ReservedPropTypeAnnotation':
|
|
66
71
|
switch (typeAnnotation.name) {
|
|
67
72
|
case 'ColorPrimitive':
|
|
68
|
-
return
|
|
69
|
-
|
|
73
|
+
return expression(
|
|
74
|
+
`{ process: require('react-native/Libraries/StyleSheet/processColor').default }`,
|
|
75
|
+
);
|
|
70
76
|
case 'ImageSourcePrimitive':
|
|
71
|
-
return
|
|
72
|
-
|
|
77
|
+
return expression(
|
|
78
|
+
`{ process: require('react-native/Libraries/Image/resolveAssetSource') }`,
|
|
79
|
+
);
|
|
73
80
|
case 'ImageRequestPrimitive':
|
|
74
81
|
throw new Error('ImageRequest should not be used in props');
|
|
75
82
|
case 'PointPrimitive':
|
|
76
|
-
return
|
|
77
|
-
|
|
83
|
+
return expression(
|
|
84
|
+
`{ diff: ((req) => 'default' in req ? req.default : req)(require('react-native/Libraries/Utilities/differ/pointsDiffer')) }`,
|
|
85
|
+
);
|
|
78
86
|
case 'EdgeInsetsPrimitive':
|
|
79
|
-
return
|
|
80
|
-
|
|
87
|
+
return expression(
|
|
88
|
+
`{ diff: ((req) => 'default' in req ? req.default : req)(require('react-native/Libraries/Utilities/differ/insetsDiffer')) }`,
|
|
89
|
+
);
|
|
81
90
|
case 'DimensionPrimitive':
|
|
82
|
-
return
|
|
91
|
+
return t.booleanLiteral(true);
|
|
83
92
|
default:
|
|
84
93
|
(typeAnnotation.name: empty);
|
|
85
94
|
throw new Error(
|
|
@@ -90,20 +99,21 @@ function getReactDiffProcessValue(typeAnnotation: PropTypeAnnotation) {
|
|
|
90
99
|
if (typeAnnotation.elementType.type === 'ReservedPropTypeAnnotation') {
|
|
91
100
|
switch (typeAnnotation.elementType.name) {
|
|
92
101
|
case 'ColorPrimitive':
|
|
93
|
-
return
|
|
94
|
-
|
|
102
|
+
return expression(
|
|
103
|
+
`{ process: ((req) => 'default' in req ? req.default : req)(require('react-native/Libraries/StyleSheet/processColorArray')) }`,
|
|
104
|
+
);
|
|
95
105
|
case 'ImageSourcePrimitive':
|
|
96
106
|
case 'PointPrimitive':
|
|
97
107
|
case 'EdgeInsetsPrimitive':
|
|
98
108
|
case 'DimensionPrimitive':
|
|
99
|
-
return
|
|
109
|
+
return t.booleanLiteral(true);
|
|
100
110
|
default:
|
|
101
111
|
throw new Error(
|
|
102
112
|
`Received unknown array native typeAnnotation: "${typeAnnotation.elementType.name}"`,
|
|
103
113
|
);
|
|
104
114
|
}
|
|
105
115
|
}
|
|
106
|
-
return
|
|
116
|
+
return t.booleanLiteral(true);
|
|
107
117
|
default:
|
|
108
118
|
(typeAnnotation: empty);
|
|
109
119
|
throw new Error(
|
|
@@ -134,7 +144,7 @@ ${
|
|
|
134
144
|
: ''
|
|
135
145
|
}
|
|
136
146
|
|
|
137
|
-
export const __INTERNAL_VIEW_CONFIG = VIEW_CONFIG
|
|
147
|
+
export const __INTERNAL_VIEW_CONFIG = %%VIEW_CONFIG%%;
|
|
138
148
|
|
|
139
149
|
export default NativeComponentRegistry.get(nativeComponentName, () => __INTERNAL_VIEW_CONFIG);
|
|
140
150
|
`.trim();
|
|
@@ -180,13 +190,16 @@ function getValidAttributesForEvents(
|
|
|
180
190
|
"const {ConditionallyIgnoredEventHandlers} = require('react-native/Libraries/NativeComponent/ViewConfigIgnore');",
|
|
181
191
|
);
|
|
182
192
|
|
|
183
|
-
const validAttributes =
|
|
193
|
+
const validAttributes = t.objectExpression(
|
|
184
194
|
events.map(eventType => {
|
|
185
|
-
return
|
|
195
|
+
return t.objectProperty(
|
|
196
|
+
t.identifier(eventType.name),
|
|
197
|
+
t.booleanLiteral(true),
|
|
198
|
+
);
|
|
186
199
|
}),
|
|
187
200
|
);
|
|
188
201
|
|
|
189
|
-
return
|
|
202
|
+
return t.callExpression(t.identifier('ConditionallyIgnoredEventHandlers'), [
|
|
190
203
|
validAttributes,
|
|
191
204
|
]);
|
|
192
205
|
}
|
|
@@ -195,20 +208,20 @@ function generateBubblingEventInfo(
|
|
|
195
208
|
event: EventTypeShape,
|
|
196
209
|
nameOveride: void | string,
|
|
197
210
|
) {
|
|
198
|
-
return
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
211
|
+
return t.objectProperty(
|
|
212
|
+
t.identifier(normalizeInputEventName(nameOveride || event.name)),
|
|
213
|
+
t.objectExpression([
|
|
214
|
+
t.objectProperty(
|
|
215
|
+
t.identifier('phasedRegistrationNames'),
|
|
216
|
+
t.objectExpression([
|
|
217
|
+
t.objectProperty(
|
|
218
|
+
t.identifier('captured'),
|
|
219
|
+
t.stringLiteral(`${event.name}Capture`),
|
|
220
|
+
),
|
|
221
|
+
t.objectProperty(
|
|
222
|
+
t.identifier('bubbled'),
|
|
223
|
+
t.stringLiteral(event.name),
|
|
210
224
|
),
|
|
211
|
-
j.property('init', j.identifier('bubbled'), j.literal(event.name)),
|
|
212
225
|
]),
|
|
213
226
|
),
|
|
214
227
|
]),
|
|
@@ -219,14 +232,12 @@ function generateDirectEventInfo(
|
|
|
219
232
|
event: EventTypeShape,
|
|
220
233
|
nameOveride: void | string,
|
|
221
234
|
) {
|
|
222
|
-
return
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
j.identifier('registrationName'),
|
|
229
|
-
j.literal(event.name),
|
|
235
|
+
return t.objectProperty(
|
|
236
|
+
t.identifier(normalizeInputEventName(nameOveride || event.name)),
|
|
237
|
+
t.objectExpression([
|
|
238
|
+
t.objectProperty(
|
|
239
|
+
t.identifier('registrationName'),
|
|
240
|
+
t.stringLiteral(event.name),
|
|
230
241
|
),
|
|
231
242
|
]),
|
|
232
243
|
);
|
|
@@ -261,20 +272,15 @@ function buildViewConfig(
|
|
|
261
272
|
}
|
|
262
273
|
});
|
|
263
274
|
|
|
264
|
-
const validAttributes =
|
|
275
|
+
const validAttributes = t.objectExpression([
|
|
265
276
|
...componentProps.map(schemaProp => {
|
|
266
|
-
return
|
|
267
|
-
|
|
268
|
-
j.identifier(schemaProp.name),
|
|
277
|
+
return t.objectProperty(
|
|
278
|
+
t.identifier(schemaProp.name),
|
|
269
279
|
getReactDiffProcessValue(schemaProp.typeAnnotation),
|
|
270
280
|
);
|
|
271
281
|
}),
|
|
272
282
|
...(componentEvents.length > 0
|
|
273
|
-
? [
|
|
274
|
-
j.spreadProperty(
|
|
275
|
-
getValidAttributesForEvents(componentEvents, imports),
|
|
276
|
-
),
|
|
277
|
-
]
|
|
283
|
+
? [t.spreadElement(getValidAttributesForEvents(componentEvents, imports))]
|
|
278
284
|
: []),
|
|
279
285
|
]);
|
|
280
286
|
|
|
@@ -294,15 +300,6 @@ function buildViewConfig(
|
|
|
294
300
|
return bubblingEvents;
|
|
295
301
|
}, []);
|
|
296
302
|
|
|
297
|
-
const bubblingEvents =
|
|
298
|
-
bubblingEventNames.length > 0
|
|
299
|
-
? j.property(
|
|
300
|
-
'init',
|
|
301
|
-
j.identifier('bubblingEventTypes'),
|
|
302
|
-
j.objectExpression(bubblingEventNames),
|
|
303
|
-
)
|
|
304
|
-
: null;
|
|
305
|
-
|
|
306
303
|
const directEventNames = component.events
|
|
307
304
|
.filter(event => event.bubblingType === 'direct')
|
|
308
305
|
.reduce((directEvents: Array<any>, event) => {
|
|
@@ -319,27 +316,34 @@ function buildViewConfig(
|
|
|
319
316
|
return directEvents;
|
|
320
317
|
}, []);
|
|
321
318
|
|
|
322
|
-
const directEvents =
|
|
323
|
-
directEventNames.length > 0
|
|
324
|
-
? j.property(
|
|
325
|
-
'init',
|
|
326
|
-
j.identifier('directEventTypes'),
|
|
327
|
-
j.objectExpression(directEventNames),
|
|
328
|
-
)
|
|
329
|
-
: null;
|
|
330
|
-
|
|
331
319
|
const properties = [
|
|
332
|
-
|
|
333
|
-
'
|
|
334
|
-
|
|
335
|
-
j.literal(componentName),
|
|
320
|
+
t.objectProperty(
|
|
321
|
+
t.identifier('uiViewClassName'),
|
|
322
|
+
t.stringLiteral(componentName),
|
|
336
323
|
),
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
324
|
+
];
|
|
325
|
+
|
|
326
|
+
if (bubblingEventNames.length > 0) {
|
|
327
|
+
properties.push(
|
|
328
|
+
t.objectProperty(
|
|
329
|
+
t.identifier('bubblingEventTypes'),
|
|
330
|
+
t.objectExpression(bubblingEventNames),
|
|
331
|
+
),
|
|
332
|
+
);
|
|
333
|
+
}
|
|
334
|
+
if (directEventNames.length > 0) {
|
|
335
|
+
properties.push(
|
|
336
|
+
t.objectProperty(
|
|
337
|
+
t.identifier('directEventTypes'),
|
|
338
|
+
t.objectExpression(directEventNames),
|
|
339
|
+
),
|
|
340
|
+
);
|
|
341
|
+
}
|
|
341
342
|
|
|
342
|
-
|
|
343
|
+
properties.push(
|
|
344
|
+
t.objectProperty(t.identifier('validAttributes'), validAttributes),
|
|
345
|
+
);
|
|
346
|
+
return t.objectExpression(properties);
|
|
343
347
|
}
|
|
344
348
|
|
|
345
349
|
function buildCommands(
|
|
@@ -358,45 +362,32 @@ function buildCommands(
|
|
|
358
362
|
'const {dispatchCommand} = require("react-native/Libraries/ReactNative/RendererProxy");',
|
|
359
363
|
);
|
|
360
364
|
|
|
361
|
-
const
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
.expression`dispatchCommand(ref, ${commandNameLiteral}, ${arrayParams})`;
|
|
375
|
-
|
|
376
|
-
const functionParams = params.map(param => {
|
|
377
|
-
return j.identifier(param.name);
|
|
378
|
-
});
|
|
379
|
-
|
|
380
|
-
const property = j.property(
|
|
381
|
-
'init',
|
|
382
|
-
commandNameIdentifier,
|
|
383
|
-
j.functionExpression(
|
|
384
|
-
null,
|
|
385
|
-
[j.identifier('ref'), ...functionParams],
|
|
386
|
-
j.blockStatement([j.expressionStatement(expression)]),
|
|
387
|
-
),
|
|
388
|
-
);
|
|
389
|
-
property.method = true;
|
|
365
|
+
const commandsObject = t.objectExpression(
|
|
366
|
+
commands.map(command => {
|
|
367
|
+
const commandName = command.name;
|
|
368
|
+
const params = command.typeAnnotation.params;
|
|
369
|
+
|
|
370
|
+
const dispatchCommandCall = t.callExpression(
|
|
371
|
+
t.identifier('dispatchCommand'),
|
|
372
|
+
[
|
|
373
|
+
t.identifier('ref'),
|
|
374
|
+
t.stringLiteral(commandName),
|
|
375
|
+
t.arrayExpression(params.map(param => t.identifier(param.name))),
|
|
376
|
+
],
|
|
377
|
+
);
|
|
390
378
|
|
|
391
|
-
|
|
392
|
-
|
|
379
|
+
return t.objectMethod(
|
|
380
|
+
'method',
|
|
381
|
+
t.identifier(commandName),
|
|
382
|
+
[t.identifier('ref'), ...params.map(param => t.identifier(param.name))],
|
|
383
|
+
t.blockStatement([t.expressionStatement(dispatchCommandCall)]),
|
|
384
|
+
);
|
|
385
|
+
}),
|
|
386
|
+
);
|
|
393
387
|
|
|
394
|
-
return
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
j.identifier('Commands'),
|
|
398
|
-
j.objectExpression(properties),
|
|
399
|
-
),
|
|
388
|
+
return t.exportNamedDeclaration(
|
|
389
|
+
t.variableDeclaration('const', [
|
|
390
|
+
t.variableDeclarator(t.identifier('Commands'), commandsObject),
|
|
400
391
|
]),
|
|
401
392
|
);
|
|
402
393
|
}
|
|
@@ -431,42 +422,40 @@ module.exports = {
|
|
|
431
422
|
component.paperComponentNameDeprecated,
|
|
432
423
|
});
|
|
433
424
|
|
|
434
|
-
const replacedSourceRoot = j.withParser('flow')(replacedTemplate);
|
|
435
|
-
|
|
436
425
|
const paperComponentName =
|
|
437
426
|
component.paperComponentName ?? componentName;
|
|
438
427
|
|
|
439
|
-
replacedSourceRoot
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
const commands = buildCommands(
|
|
428
|
+
const replacedSourceRoot = core.template.program(
|
|
429
|
+
replacedTemplate,
|
|
430
|
+
)({
|
|
431
|
+
VIEW_CONFIG: buildViewConfig(
|
|
432
|
+
schema,
|
|
433
|
+
paperComponentName,
|
|
434
|
+
component,
|
|
435
|
+
imports,
|
|
436
|
+
),
|
|
437
|
+
});
|
|
438
|
+
|
|
439
|
+
const commandsExport = buildCommands(
|
|
453
440
|
schema,
|
|
454
441
|
paperComponentName,
|
|
455
442
|
component,
|
|
456
443
|
imports,
|
|
457
444
|
);
|
|
458
|
-
if (
|
|
459
|
-
replacedSourceRoot
|
|
460
|
-
.find(j.ExportDefaultDeclaration)
|
|
461
|
-
.insertAfter(j(commands).toSource());
|
|
445
|
+
if (commandsExport) {
|
|
446
|
+
replacedSourceRoot.body.push(commandsExport);
|
|
462
447
|
}
|
|
463
448
|
|
|
464
|
-
const replacedSource
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
449
|
+
const replacedSource = core.transformFromAstSync(
|
|
450
|
+
replacedSourceRoot,
|
|
451
|
+
undefined,
|
|
452
|
+
{
|
|
453
|
+
babelrc: false,
|
|
454
|
+
browserslistConfigFile: false,
|
|
455
|
+
configFile: false,
|
|
456
|
+
},
|
|
457
|
+
);
|
|
458
|
+
return replacedSource.code;
|
|
470
459
|
})
|
|
471
460
|
.join('\n\n');
|
|
472
461
|
})
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@react-native/codegen",
|
|
3
|
-
"version": "0.79.0-rc.
|
|
3
|
+
"version": "0.79.0-rc.2",
|
|
4
4
|
"description": "Code generation tools for React Native",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -29,24 +29,22 @@
|
|
|
29
29
|
"lib"
|
|
30
30
|
],
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@babel/parser": "^7.25.3",
|
|
33
32
|
"glob": "^7.1.1",
|
|
34
33
|
"hermes-parser": "0.25.1",
|
|
35
34
|
"invariant": "^2.2.4",
|
|
36
|
-
"jscodeshift": "^17.0.0",
|
|
37
35
|
"nullthrows": "^1.1.1",
|
|
38
36
|
"yargs": "^17.6.2"
|
|
39
37
|
},
|
|
40
38
|
"devDependencies": {
|
|
41
39
|
"@babel/core": "^7.25.2",
|
|
42
|
-
"@babel/plugin-transform-class-properties": "^7.25.4",
|
|
43
|
-
"@babel/plugin-transform-nullish-coalescing-operator": "^7.24.7",
|
|
44
|
-
"@babel/plugin-transform-object-rest-spread": "^7.24.7",
|
|
45
|
-
"@babel/plugin-transform-optional-chaining": "^7.24.8",
|
|
46
40
|
"@babel/plugin-syntax-dynamic-import": "^7.8.3",
|
|
47
41
|
"@babel/plugin-transform-async-to-generator": "^7.24.7",
|
|
42
|
+
"@babel/plugin-transform-class-properties": "^7.25.4",
|
|
48
43
|
"@babel/plugin-transform-destructuring": "^7.24.8",
|
|
49
44
|
"@babel/plugin-transform-flow-strip-types": "^7.25.2",
|
|
45
|
+
"@babel/plugin-transform-nullish-coalescing-operator": "^7.24.7",
|
|
46
|
+
"@babel/plugin-transform-object-rest-spread": "^7.24.7",
|
|
47
|
+
"@babel/plugin-transform-optional-chaining": "^7.24.8",
|
|
50
48
|
"@babel/preset-env": "^7.25.3",
|
|
51
49
|
"chalk": "^4.0.0",
|
|
52
50
|
"hermes-estree": "0.25.1",
|
|
@@ -55,6 +53,6 @@
|
|
|
55
53
|
"rimraf": "^3.0.2"
|
|
56
54
|
},
|
|
57
55
|
"peerDependencies": {
|
|
58
|
-
"@babel/
|
|
56
|
+
"@babel/core": "*"
|
|
59
57
|
}
|
|
60
58
|
}
|