@react-native/codegen 0.89.0-nightly-20260923-4b6cd413d → 0.89.0-nightly-20260925-de350e65e
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.
|
@@ -23,12 +23,16 @@ ${imports}
|
|
|
23
23
|
|
|
24
24
|
${componentConfig}
|
|
25
25
|
`;
|
|
26
|
-
|
|
27
|
-
|
|
26
|
+
function buildImport(source, imports) {
|
|
27
|
+
if (imports.size === 0) {
|
|
28
|
+
return '';
|
|
29
|
+
}
|
|
30
|
+
return `const {${Array.from(imports).sort().join(', ')}} = require('${source}');`;
|
|
31
|
+
}
|
|
28
32
|
function expression(input) {
|
|
29
33
|
return core.template.expression(input)();
|
|
30
34
|
}
|
|
31
|
-
function getReactDiffProcessValue(typeAnnotation) {
|
|
35
|
+
function getReactDiffProcessValue(typeAnnotation, unstableImports, reactNativeImports) {
|
|
32
36
|
switch (typeAnnotation.type) {
|
|
33
37
|
case 'BooleanTypeAnnotation':
|
|
34
38
|
case 'StringTypeAnnotation':
|
|
@@ -43,15 +47,19 @@ function getReactDiffProcessValue(typeAnnotation) {
|
|
|
43
47
|
case 'ReservedPropTypeAnnotation':
|
|
44
48
|
switch (typeAnnotation.name) {
|
|
45
49
|
case 'ColorPrimitive':
|
|
46
|
-
|
|
50
|
+
unstableImports.add('colorAttribute');
|
|
51
|
+
return expression('colorAttribute');
|
|
47
52
|
case 'ImageSourcePrimitive':
|
|
48
|
-
|
|
53
|
+
reactNativeImports.add('Image');
|
|
54
|
+
return expression('{process: Image.resolveAssetSource}');
|
|
49
55
|
case 'ImageRequestPrimitive':
|
|
50
56
|
throw new Error('ImageRequest should not be used in props');
|
|
51
57
|
case 'PointPrimitive':
|
|
52
|
-
|
|
58
|
+
unstableImports.add('pointsDiffer');
|
|
59
|
+
return expression('{diff: pointsDiffer}');
|
|
53
60
|
case 'EdgeInsetsPrimitive':
|
|
54
|
-
|
|
61
|
+
unstableImports.add('insetsDiffer');
|
|
62
|
+
return expression('{diff: insetsDiffer}');
|
|
55
63
|
case 'DimensionPrimitive':
|
|
56
64
|
return t.booleanLiteral(true);
|
|
57
65
|
default:
|
|
@@ -62,7 +70,8 @@ function getReactDiffProcessValue(typeAnnotation) {
|
|
|
62
70
|
if (typeAnnotation.elementType.type === 'ReservedPropTypeAnnotation') {
|
|
63
71
|
switch (typeAnnotation.elementType.name) {
|
|
64
72
|
case 'ColorPrimitive':
|
|
65
|
-
|
|
73
|
+
unstableImports.add('processColorArray');
|
|
74
|
+
return expression('{process: processColorArray}');
|
|
66
75
|
case 'ImageSourcePrimitive':
|
|
67
76
|
case 'PointPrimitive':
|
|
68
77
|
case 'EdgeInsetsPrimitive':
|
|
@@ -116,8 +125,8 @@ function normalizeInputEventName(name) {
|
|
|
116
125
|
}
|
|
117
126
|
return name;
|
|
118
127
|
}
|
|
119
|
-
function getValidAttributesForEvents(events,
|
|
120
|
-
|
|
128
|
+
function getValidAttributesForEvents(events, unstableImports) {
|
|
129
|
+
unstableImports.add('ConditionallyIgnoredEventHandlers');
|
|
121
130
|
const validAttributes = t.objectExpression(events.map(eventType => {
|
|
122
131
|
return t.objectProperty(t.identifier(eventType.name), t.booleanLiteral(true));
|
|
123
132
|
}));
|
|
@@ -129,7 +138,7 @@ function generateBubblingEventInfo(event, nameOveride) {
|
|
|
129
138
|
function generateDirectEventInfo(event, nameOveride) {
|
|
130
139
|
return t.objectProperty(t.identifier(normalizeInputEventName(nameOveride || event.name)), t.objectExpression([t.objectProperty(t.identifier('registrationName'), t.stringLiteral(event.name))]));
|
|
131
140
|
}
|
|
132
|
-
function buildViewConfig(schema, componentName, component,
|
|
141
|
+
function buildViewConfig(schema, componentName, component, unstableImports, reactNativeImports) {
|
|
133
142
|
const componentProps = component.props;
|
|
134
143
|
const componentEvents = component.events;
|
|
135
144
|
component.extendsProps.forEach(extendProps => {
|
|
@@ -137,7 +146,6 @@ function buildViewConfig(schema, componentName, component, imports) {
|
|
|
137
146
|
case 'ReactNativeBuiltInType':
|
|
138
147
|
switch (extendProps.knownTypeName) {
|
|
139
148
|
case 'ReactNativeCoreViewProps':
|
|
140
|
-
imports.add("const {NativeComponentRegistry} = require('react-native');");
|
|
141
149
|
return;
|
|
142
150
|
default:
|
|
143
151
|
extendProps.knownTypeName;
|
|
@@ -149,8 +157,8 @@ function buildViewConfig(schema, componentName, component, imports) {
|
|
|
149
157
|
}
|
|
150
158
|
});
|
|
151
159
|
const validAttributes = t.objectExpression([...componentProps.map(schemaProp => {
|
|
152
|
-
return t.objectProperty(t.identifier(schemaProp.name), getReactDiffProcessValue(schemaProp.typeAnnotation));
|
|
153
|
-
}), ...(componentEvents.length > 0 ? [t.spreadElement(getValidAttributesForEvents(componentEvents,
|
|
160
|
+
return t.objectProperty(t.identifier(schemaProp.name), getReactDiffProcessValue(schemaProp.typeAnnotation, unstableImports, reactNativeImports));
|
|
161
|
+
}), ...(componentEvents.length > 0 ? [t.spreadElement(getValidAttributesForEvents(componentEvents, unstableImports))] : [])]);
|
|
154
162
|
const bubblingEventNames = component.events.filter(event => event.bubblingType === 'bubble').reduce((bubblingEvents, event) => {
|
|
155
163
|
if (event.paperTopLevelNameDeprecated) {
|
|
156
164
|
bubblingEvents.push(generateBubblingEventInfo(event, event.paperTopLevelNameDeprecated));
|
|
@@ -177,16 +185,16 @@ function buildViewConfig(schema, componentName, component, imports) {
|
|
|
177
185
|
properties.push(t.objectProperty(t.identifier('validAttributes'), validAttributes));
|
|
178
186
|
return t.objectExpression(properties);
|
|
179
187
|
}
|
|
180
|
-
function buildCommands(schema, componentName, component,
|
|
188
|
+
function buildCommands(schema, componentName, component, unstableImports) {
|
|
181
189
|
const commands = component.commands;
|
|
182
190
|
if (commands.length === 0) {
|
|
183
191
|
return null;
|
|
184
192
|
}
|
|
185
|
-
|
|
193
|
+
unstableImports.add('dispatchCommand');
|
|
186
194
|
const commandsObject = t.objectExpression(commands.map(command => {
|
|
187
195
|
const commandName = command.name;
|
|
188
196
|
const params = command.typeAnnotation.params;
|
|
189
|
-
const dispatchCommandCall = t.callExpression(t.
|
|
197
|
+
const dispatchCommandCall = t.callExpression(t.identifier('dispatchCommand'), [t.identifier('ref'), t.stringLiteral(commandName), t.arrayExpression(params.map(param => t.identifier(param.name)))]);
|
|
190
198
|
return t.objectMethod('method', t.identifier(commandName), [t.identifier('ref'), ...params.map(param => t.identifier(param.name))], t.blockStatement([t.expressionStatement(dispatchCommandCall)]));
|
|
191
199
|
}));
|
|
192
200
|
return t.exportNamedDeclaration(t.variableDeclaration('const', [t.variableDeclarator(t.identifier('Commands'), commandsObject)]));
|
|
@@ -195,7 +203,8 @@ module.exports = {
|
|
|
195
203
|
generate(libraryName, schema) {
|
|
196
204
|
try {
|
|
197
205
|
const fileName = `${libraryName}NativeViewConfig.js`;
|
|
198
|
-
const
|
|
206
|
+
const unstableImports = new Set();
|
|
207
|
+
const reactNativeImports = new Set();
|
|
199
208
|
const moduleResults = Object.keys(schema.modules).map(moduleName => {
|
|
200
209
|
const module = schema.modules[moduleName];
|
|
201
210
|
if (module.type !== 'Component') {
|
|
@@ -208,8 +217,9 @@ module.exports = {
|
|
|
208
217
|
var _component$paperCompo;
|
|
209
218
|
const component = components[componentName];
|
|
210
219
|
if (component.paperComponentNameDeprecated) {
|
|
211
|
-
|
|
220
|
+
reactNativeImports.add('UIManager');
|
|
212
221
|
}
|
|
222
|
+
reactNativeImports.add('NativeComponentRegistry');
|
|
213
223
|
const replacedTemplate = ComponentTemplate({
|
|
214
224
|
componentName,
|
|
215
225
|
paperComponentName: component.paperComponentName,
|
|
@@ -217,9 +227,9 @@ module.exports = {
|
|
|
217
227
|
});
|
|
218
228
|
const paperComponentName = (_component$paperCompo = component.paperComponentName) !== null && _component$paperCompo !== void 0 ? _component$paperCompo : componentName;
|
|
219
229
|
const replacedSourceRoot = core.template.program(replacedTemplate)({
|
|
220
|
-
VIEW_CONFIG: buildViewConfig(schema, paperComponentName, component,
|
|
230
|
+
VIEW_CONFIG: buildViewConfig(schema, paperComponentName, component, unstableImports, reactNativeImports)
|
|
221
231
|
});
|
|
222
|
-
const commandsExport = buildCommands(schema, paperComponentName, component,
|
|
232
|
+
const commandsExport = buildCommands(schema, paperComponentName, component, unstableImports);
|
|
223
233
|
if (commandsExport) {
|
|
224
234
|
replacedSourceRoot.body.push(commandsExport);
|
|
225
235
|
}
|
|
@@ -233,7 +243,7 @@ module.exports = {
|
|
|
233
243
|
}).filter(Boolean).join('\n\n');
|
|
234
244
|
const replacedTemplate = FileTemplate({
|
|
235
245
|
componentConfig: moduleResults,
|
|
236
|
-
imports:
|
|
246
|
+
imports: [buildImport('react-native', reactNativeImports), buildImport('react-native/unstable-internals-do-not-use', unstableImports)].filter(Boolean).join('\n')
|
|
237
247
|
});
|
|
238
248
|
return new Map([[fileName, replacedTemplate]]);
|
|
239
249
|
} catch (error) {
|
|
@@ -53,17 +53,23 @@ ${imports}
|
|
|
53
53
|
${componentConfig}
|
|
54
54
|
`;
|
|
55
55
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
56
|
+
function buildImport(source: string, imports: Set<string>): string {
|
|
57
|
+
if (imports.size === 0) {
|
|
58
|
+
return '';
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
return `const {${Array.from(imports).sort().join(', ')}} = require('${source}');`;
|
|
62
|
+
}
|
|
61
63
|
|
|
62
64
|
function expression(input: string) {
|
|
63
65
|
return core.template.expression(input)();
|
|
64
66
|
}
|
|
65
67
|
|
|
66
|
-
function getReactDiffProcessValue(
|
|
68
|
+
function getReactDiffProcessValue(
|
|
69
|
+
typeAnnotation: PropTypeAnnotation,
|
|
70
|
+
unstableImports: Set<string>,
|
|
71
|
+
reactNativeImports: Set<string>,
|
|
72
|
+
) {
|
|
67
73
|
switch (typeAnnotation.type) {
|
|
68
74
|
case 'BooleanTypeAnnotation':
|
|
69
75
|
case 'StringTypeAnnotation':
|
|
@@ -78,23 +84,19 @@ function getReactDiffProcessValue(typeAnnotation: PropTypeAnnotation) {
|
|
|
78
84
|
case 'ReservedPropTypeAnnotation':
|
|
79
85
|
switch (typeAnnotation.name) {
|
|
80
86
|
case 'ColorPrimitive':
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
);
|
|
87
|
+
unstableImports.add('colorAttribute');
|
|
88
|
+
return expression('colorAttribute');
|
|
84
89
|
case 'ImageSourcePrimitive':
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
);
|
|
90
|
+
reactNativeImports.add('Image');
|
|
91
|
+
return expression('{process: Image.resolveAssetSource}');
|
|
88
92
|
case 'ImageRequestPrimitive':
|
|
89
93
|
throw new Error('ImageRequest should not be used in props');
|
|
90
94
|
case 'PointPrimitive':
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
);
|
|
95
|
+
unstableImports.add('pointsDiffer');
|
|
96
|
+
return expression('{diff: pointsDiffer}');
|
|
94
97
|
case 'EdgeInsetsPrimitive':
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
);
|
|
98
|
+
unstableImports.add('insetsDiffer');
|
|
99
|
+
return expression('{diff: insetsDiffer}');
|
|
98
100
|
case 'DimensionPrimitive':
|
|
99
101
|
return t.booleanLiteral(true);
|
|
100
102
|
default:
|
|
@@ -107,9 +109,8 @@ function getReactDiffProcessValue(typeAnnotation: PropTypeAnnotation) {
|
|
|
107
109
|
if (typeAnnotation.elementType.type === 'ReservedPropTypeAnnotation') {
|
|
108
110
|
switch (typeAnnotation.elementType.name) {
|
|
109
111
|
case 'ColorPrimitive':
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
);
|
|
112
|
+
unstableImports.add('processColorArray');
|
|
113
|
+
return expression('{process: processColorArray}');
|
|
113
114
|
case 'ImageSourcePrimitive':
|
|
114
115
|
case 'PointPrimitive':
|
|
115
116
|
case 'EdgeInsetsPrimitive':
|
|
@@ -192,13 +193,11 @@ function normalizeInputEventName(name: string) {
|
|
|
192
193
|
// Replicates the behavior of viewConfig in RCTComponentData.m
|
|
193
194
|
function getValidAttributesForEvents(
|
|
194
195
|
events: ReadonlyArray<EventTypeShape>,
|
|
195
|
-
|
|
196
|
+
unstableImports: Set<string>,
|
|
196
197
|
) {
|
|
197
198
|
// Generated files can live outside the React Native package, so they cannot
|
|
198
199
|
// use a relative import for this implementation detail.
|
|
199
|
-
|
|
200
|
-
"const {ConditionallyIgnoredEventHandlers} = require('react-native/unstable-internals-do-not-use');",
|
|
201
|
-
);
|
|
200
|
+
unstableImports.add('ConditionallyIgnoredEventHandlers');
|
|
202
201
|
|
|
203
202
|
const validAttributes = t.objectExpression(
|
|
204
203
|
events.map(eventType => {
|
|
@@ -257,7 +256,8 @@ function buildViewConfig(
|
|
|
257
256
|
schema: SchemaType,
|
|
258
257
|
componentName: string,
|
|
259
258
|
component: ComponentShape,
|
|
260
|
-
|
|
259
|
+
unstableImports: Set<string>,
|
|
260
|
+
reactNativeImports: Set<string>,
|
|
261
261
|
) {
|
|
262
262
|
const componentProps = component.props;
|
|
263
263
|
const componentEvents = component.events;
|
|
@@ -267,10 +267,6 @@ function buildViewConfig(
|
|
|
267
267
|
case 'ReactNativeBuiltInType':
|
|
268
268
|
switch (extendProps.knownTypeName) {
|
|
269
269
|
case 'ReactNativeCoreViewProps':
|
|
270
|
-
imports.add(
|
|
271
|
-
"const {NativeComponentRegistry} = require('react-native');",
|
|
272
|
-
);
|
|
273
|
-
|
|
274
270
|
return;
|
|
275
271
|
default:
|
|
276
272
|
extendProps.knownTypeName as empty;
|
|
@@ -286,11 +282,19 @@ function buildViewConfig(
|
|
|
286
282
|
...componentProps.map(schemaProp => {
|
|
287
283
|
return t.objectProperty(
|
|
288
284
|
t.identifier(schemaProp.name),
|
|
289
|
-
getReactDiffProcessValue(
|
|
285
|
+
getReactDiffProcessValue(
|
|
286
|
+
schemaProp.typeAnnotation,
|
|
287
|
+
unstableImports,
|
|
288
|
+
reactNativeImports,
|
|
289
|
+
),
|
|
290
290
|
);
|
|
291
291
|
}),
|
|
292
292
|
...(componentEvents.length > 0
|
|
293
|
-
? [
|
|
293
|
+
? [
|
|
294
|
+
t.spreadElement(
|
|
295
|
+
getValidAttributesForEvents(componentEvents, unstableImports),
|
|
296
|
+
),
|
|
297
|
+
]
|
|
294
298
|
: []),
|
|
295
299
|
]);
|
|
296
300
|
|
|
@@ -362,7 +366,7 @@ function buildCommands(
|
|
|
362
366
|
schema: SchemaType,
|
|
363
367
|
componentName: string,
|
|
364
368
|
component: ComponentShape,
|
|
365
|
-
|
|
369
|
+
unstableImports: Set<string>,
|
|
366
370
|
) {
|
|
367
371
|
const commands = component.commands;
|
|
368
372
|
|
|
@@ -370,7 +374,7 @@ function buildCommands(
|
|
|
370
374
|
return null;
|
|
371
375
|
}
|
|
372
376
|
|
|
373
|
-
|
|
377
|
+
unstableImports.add('dispatchCommand');
|
|
374
378
|
|
|
375
379
|
const commandsObject = t.objectExpression(
|
|
376
380
|
commands.map(command => {
|
|
@@ -378,10 +382,7 @@ function buildCommands(
|
|
|
378
382
|
const params = command.typeAnnotation.params;
|
|
379
383
|
|
|
380
384
|
const dispatchCommandCall = t.callExpression(
|
|
381
|
-
t.
|
|
382
|
-
t.identifier('Renderer'),
|
|
383
|
-
t.identifier('dispatchCommand'),
|
|
384
|
-
),
|
|
385
|
+
t.identifier('dispatchCommand'),
|
|
385
386
|
[
|
|
386
387
|
t.identifier('ref'),
|
|
387
388
|
t.stringLiteral(commandName),
|
|
@@ -409,7 +410,8 @@ module.exports = {
|
|
|
409
410
|
generate(libraryName: string, schema: SchemaType): FilesOutput {
|
|
410
411
|
try {
|
|
411
412
|
const fileName = `${libraryName}NativeViewConfig.js`;
|
|
412
|
-
const
|
|
413
|
+
const unstableImports: Set<string> = new Set();
|
|
414
|
+
const reactNativeImports: Set<string> = new Set();
|
|
413
415
|
|
|
414
416
|
const moduleResults = Object.keys(schema.modules)
|
|
415
417
|
.map(moduleName => {
|
|
@@ -425,9 +427,11 @@ module.exports = {
|
|
|
425
427
|
const component = components[componentName];
|
|
426
428
|
|
|
427
429
|
if (component.paperComponentNameDeprecated) {
|
|
428
|
-
|
|
430
|
+
reactNativeImports.add('UIManager');
|
|
429
431
|
}
|
|
430
432
|
|
|
433
|
+
reactNativeImports.add('NativeComponentRegistry');
|
|
434
|
+
|
|
431
435
|
const replacedTemplate = ComponentTemplate({
|
|
432
436
|
componentName,
|
|
433
437
|
paperComponentName: component.paperComponentName,
|
|
@@ -445,7 +449,8 @@ module.exports = {
|
|
|
445
449
|
schema,
|
|
446
450
|
paperComponentName,
|
|
447
451
|
component,
|
|
448
|
-
|
|
452
|
+
unstableImports,
|
|
453
|
+
reactNativeImports,
|
|
449
454
|
),
|
|
450
455
|
});
|
|
451
456
|
|
|
@@ -453,7 +458,7 @@ module.exports = {
|
|
|
453
458
|
schema,
|
|
454
459
|
paperComponentName,
|
|
455
460
|
component,
|
|
456
|
-
|
|
461
|
+
unstableImports,
|
|
457
462
|
);
|
|
458
463
|
if (commandsExport) {
|
|
459
464
|
replacedSourceRoot.body.push(commandsExport);
|
|
@@ -477,7 +482,15 @@ module.exports = {
|
|
|
477
482
|
|
|
478
483
|
const replacedTemplate = FileTemplate({
|
|
479
484
|
componentConfig: moduleResults,
|
|
480
|
-
imports:
|
|
485
|
+
imports: [
|
|
486
|
+
buildImport('react-native', reactNativeImports),
|
|
487
|
+
buildImport(
|
|
488
|
+
'react-native/unstable-internals-do-not-use',
|
|
489
|
+
unstableImports,
|
|
490
|
+
),
|
|
491
|
+
]
|
|
492
|
+
.filter(Boolean)
|
|
493
|
+
.join('\n'),
|
|
481
494
|
});
|
|
482
495
|
|
|
483
496
|
return new Map([[fileName, replacedTemplate]]);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@react-native/codegen",
|
|
3
|
-
"version": "0.89.0-nightly-
|
|
3
|
+
"version": "0.89.0-nightly-20260925-de350e65e",
|
|
4
4
|
"description": "Code generation tools for React Native",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
],
|
|
31
31
|
"dependencies": {
|
|
32
32
|
"@babel/core": "^7.25.2",
|
|
33
|
-
"@babel/parser": "^7.29.
|
|
33
|
+
"@babel/parser": "^7.29.9",
|
|
34
34
|
"flow-parser": "0.331.0",
|
|
35
35
|
"invariant": "^2.2.4",
|
|
36
36
|
"nullthrows": "^1.1.1",
|