@react-native/codegen 0.74.82 → 0.74.83
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/generators/components/CppHelpers.js +5 -0
- package/lib/generators/components/CppHelpers.js.flow +9 -0
- package/lib/generators/components/GeneratePropsH.js +18 -14
- package/lib/generators/components/GeneratePropsH.js.flow +18 -14
- package/lib/generators/components/__test_fixtures__/fixtures.js +32 -0
- package/lib/generators/components/__test_fixtures__/fixtures.js.flow +32 -0
- package/package.json +1 -1
|
@@ -122,6 +122,10 @@ function generateStructName(componentName, parts = []) {
|
|
|
122
122
|
function getEnumMaskName(enumName) {
|
|
123
123
|
return `${enumName}Mask`;
|
|
124
124
|
}
|
|
125
|
+
function getDefaultInitializerString(componentName, prop) {
|
|
126
|
+
const defaultValue = convertDefaultTypeToString(componentName, prop);
|
|
127
|
+
return `{${defaultValue}}`;
|
|
128
|
+
}
|
|
125
129
|
function convertDefaultTypeToString(componentName, prop) {
|
|
126
130
|
const typeAnnotation = prop.typeAnnotation;
|
|
127
131
|
switch (typeAnnotation.type) {
|
|
@@ -215,6 +219,7 @@ const IncludeTemplate = ({headerPrefix, file}) => {
|
|
|
215
219
|
return `#include <${headerPrefix}${file}>`;
|
|
216
220
|
};
|
|
217
221
|
module.exports = {
|
|
222
|
+
getDefaultInitializerString,
|
|
218
223
|
convertDefaultTypeToString,
|
|
219
224
|
getCppArrayTypeForAnnotation,
|
|
220
225
|
getCppTypeForAnnotation,
|
|
@@ -166,6 +166,14 @@ function getEnumMaskName(enumName: string): string {
|
|
|
166
166
|
return `${enumName}Mask`;
|
|
167
167
|
}
|
|
168
168
|
|
|
169
|
+
function getDefaultInitializerString(
|
|
170
|
+
componentName: string,
|
|
171
|
+
prop: NamedShape<PropTypeAnnotation>,
|
|
172
|
+
): string {
|
|
173
|
+
const defaultValue = convertDefaultTypeToString(componentName, prop);
|
|
174
|
+
return `{${defaultValue}}`;
|
|
175
|
+
}
|
|
176
|
+
|
|
169
177
|
function convertDefaultTypeToString(
|
|
170
178
|
componentName: string,
|
|
171
179
|
prop: NamedShape<PropTypeAnnotation>,
|
|
@@ -270,6 +278,7 @@ const IncludeTemplate = ({
|
|
|
270
278
|
};
|
|
271
279
|
|
|
272
280
|
module.exports = {
|
|
281
|
+
getDefaultInitializerString,
|
|
273
282
|
convertDefaultTypeToString,
|
|
274
283
|
getCppArrayTypeForAnnotation,
|
|
275
284
|
getCppTypeForAnnotation,
|
|
@@ -17,8 +17,8 @@ const _require2 = require('./ComponentsGeneratorUtils.js'),
|
|
|
17
17
|
getLocalImports = _require2.getLocalImports,
|
|
18
18
|
getNativeTypeFromAnnotation = _require2.getNativeTypeFromAnnotation;
|
|
19
19
|
const _require3 = require('./CppHelpers.js'),
|
|
20
|
-
convertDefaultTypeToString = _require3.convertDefaultTypeToString,
|
|
21
20
|
generateStructName = _require3.generateStructName,
|
|
21
|
+
getDefaultInitializerString = _require3.getDefaultInitializerString,
|
|
22
22
|
getEnumMaskName = _require3.getEnumMaskName,
|
|
23
23
|
toIntEnumValueName = _require3.toIntEnumValueName;
|
|
24
24
|
|
|
@@ -335,12 +335,19 @@ function generateEnumString(componentName, component) {
|
|
|
335
335
|
.filter(Boolean)
|
|
336
336
|
.join('\n');
|
|
337
337
|
}
|
|
338
|
-
function generatePropsString(componentName, props) {
|
|
338
|
+
function generatePropsString(componentName, props, nameParts) {
|
|
339
339
|
return props
|
|
340
340
|
.map(prop => {
|
|
341
|
-
const nativeType = getNativeTypeFromAnnotation(
|
|
342
|
-
|
|
343
|
-
|
|
341
|
+
const nativeType = getNativeTypeFromAnnotation(
|
|
342
|
+
componentName,
|
|
343
|
+
prop,
|
|
344
|
+
nameParts,
|
|
345
|
+
);
|
|
346
|
+
const defaultInitializer = getDefaultInitializerString(
|
|
347
|
+
componentName,
|
|
348
|
+
prop,
|
|
349
|
+
);
|
|
350
|
+
return `${nativeType} ${prop.name}${defaultInitializer};`;
|
|
344
351
|
})
|
|
345
352
|
.join('\n' + ' ');
|
|
346
353
|
}
|
|
@@ -483,15 +490,11 @@ function generateStructs(componentName, properties, nameParts) {
|
|
|
483
490
|
function generateStruct(structs, componentName, nameParts, properties) {
|
|
484
491
|
const structNameParts = nameParts;
|
|
485
492
|
const structName = generateStructName(componentName, structNameParts);
|
|
486
|
-
const fields =
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
structNameParts,
|
|
492
|
-
)} ${property.name};`;
|
|
493
|
-
})
|
|
494
|
-
.join('\n' + ' ');
|
|
493
|
+
const fields = generatePropsString(
|
|
494
|
+
componentName,
|
|
495
|
+
properties,
|
|
496
|
+
structNameParts,
|
|
497
|
+
);
|
|
495
498
|
properties.forEach(property => {
|
|
496
499
|
const name = property.name;
|
|
497
500
|
switch (property.typeAnnotation.type) {
|
|
@@ -582,6 +585,7 @@ module.exports = {
|
|
|
582
585
|
const propsString = generatePropsString(
|
|
583
586
|
componentName,
|
|
584
587
|
component.props,
|
|
588
|
+
[],
|
|
585
589
|
);
|
|
586
590
|
const extendString = getClassExtendString(component);
|
|
587
591
|
const extendsImports = getExtendsImports(component.extendsProps);
|
|
@@ -23,8 +23,8 @@ const {
|
|
|
23
23
|
getNativeTypeFromAnnotation,
|
|
24
24
|
} = require('./ComponentsGeneratorUtils.js');
|
|
25
25
|
const {
|
|
26
|
-
convertDefaultTypeToString,
|
|
27
26
|
generateStructName,
|
|
27
|
+
getDefaultInitializerString,
|
|
28
28
|
getEnumMaskName,
|
|
29
29
|
toIntEnumValueName,
|
|
30
30
|
} = require('./CppHelpers.js');
|
|
@@ -456,13 +456,21 @@ function generateEnumString(
|
|
|
456
456
|
function generatePropsString(
|
|
457
457
|
componentName: string,
|
|
458
458
|
props: $ReadOnlyArray<NamedShape<PropTypeAnnotation>>,
|
|
459
|
+
nameParts: $ReadOnlyArray<string>,
|
|
459
460
|
) {
|
|
460
461
|
return props
|
|
461
462
|
.map(prop => {
|
|
462
|
-
const nativeType = getNativeTypeFromAnnotation(
|
|
463
|
-
|
|
463
|
+
const nativeType = getNativeTypeFromAnnotation(
|
|
464
|
+
componentName,
|
|
465
|
+
prop,
|
|
466
|
+
nameParts,
|
|
467
|
+
);
|
|
468
|
+
const defaultInitializer = getDefaultInitializerString(
|
|
469
|
+
componentName,
|
|
470
|
+
prop,
|
|
471
|
+
);
|
|
464
472
|
|
|
465
|
-
return `${nativeType} ${prop.name}
|
|
473
|
+
return `${nativeType} ${prop.name}${defaultInitializer};`;
|
|
466
474
|
})
|
|
467
475
|
.join('\n' + ' ');
|
|
468
476
|
}
|
|
@@ -629,16 +637,11 @@ function generateStruct(
|
|
|
629
637
|
): void {
|
|
630
638
|
const structNameParts = nameParts;
|
|
631
639
|
const structName = generateStructName(componentName, structNameParts);
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
property,
|
|
638
|
-
structNameParts,
|
|
639
|
-
)} ${property.name};`;
|
|
640
|
-
})
|
|
641
|
-
.join('\n' + ' ');
|
|
640
|
+
const fields = generatePropsString(
|
|
641
|
+
componentName,
|
|
642
|
+
properties,
|
|
643
|
+
structNameParts,
|
|
644
|
+
);
|
|
642
645
|
|
|
643
646
|
properties.forEach((property: NamedShape<PropTypeAnnotation>) => {
|
|
644
647
|
const name = property.name;
|
|
@@ -738,6 +741,7 @@ module.exports = {
|
|
|
738
741
|
const propsString = generatePropsString(
|
|
739
742
|
componentName,
|
|
740
743
|
component.props,
|
|
744
|
+
[],
|
|
741
745
|
);
|
|
742
746
|
const extendString = getClassExtendString(component);
|
|
743
747
|
const extendsImports = getExtendsImports(component.extendsProps);
|
|
@@ -854,6 +854,38 @@ const OBJECT_PROPS = {
|
|
|
854
854
|
default: 0,
|
|
855
855
|
},
|
|
856
856
|
},
|
|
857
|
+
{
|
|
858
|
+
name: 'stringUserDefaultProp',
|
|
859
|
+
optional: true,
|
|
860
|
+
typeAnnotation: {
|
|
861
|
+
type: 'StringTypeAnnotation',
|
|
862
|
+
default: 'user_default',
|
|
863
|
+
},
|
|
864
|
+
},
|
|
865
|
+
{
|
|
866
|
+
name: 'booleanUserDefaultProp',
|
|
867
|
+
optional: true,
|
|
868
|
+
typeAnnotation: {
|
|
869
|
+
type: 'BooleanTypeAnnotation',
|
|
870
|
+
default: true,
|
|
871
|
+
},
|
|
872
|
+
},
|
|
873
|
+
{
|
|
874
|
+
name: 'floatUserDefaultProp',
|
|
875
|
+
optional: true,
|
|
876
|
+
typeAnnotation: {
|
|
877
|
+
type: 'FloatTypeAnnotation',
|
|
878
|
+
default: 3.14,
|
|
879
|
+
},
|
|
880
|
+
},
|
|
881
|
+
{
|
|
882
|
+
name: 'intUserDefaultProp',
|
|
883
|
+
optional: true,
|
|
884
|
+
typeAnnotation: {
|
|
885
|
+
type: 'Int32TypeAnnotation',
|
|
886
|
+
default: 9999,
|
|
887
|
+
},
|
|
888
|
+
},
|
|
857
889
|
{
|
|
858
890
|
name: 'stringEnumProp',
|
|
859
891
|
optional: true,
|
|
@@ -871,6 +871,38 @@ const OBJECT_PROPS: SchemaType = {
|
|
|
871
871
|
default: 0,
|
|
872
872
|
},
|
|
873
873
|
},
|
|
874
|
+
{
|
|
875
|
+
name: 'stringUserDefaultProp',
|
|
876
|
+
optional: true,
|
|
877
|
+
typeAnnotation: {
|
|
878
|
+
type: 'StringTypeAnnotation',
|
|
879
|
+
default: 'user_default',
|
|
880
|
+
},
|
|
881
|
+
},
|
|
882
|
+
{
|
|
883
|
+
name: 'booleanUserDefaultProp',
|
|
884
|
+
optional: true,
|
|
885
|
+
typeAnnotation: {
|
|
886
|
+
type: 'BooleanTypeAnnotation',
|
|
887
|
+
default: true,
|
|
888
|
+
},
|
|
889
|
+
},
|
|
890
|
+
{
|
|
891
|
+
name: 'floatUserDefaultProp',
|
|
892
|
+
optional: true,
|
|
893
|
+
typeAnnotation: {
|
|
894
|
+
type: 'FloatTypeAnnotation',
|
|
895
|
+
default: 3.14,
|
|
896
|
+
},
|
|
897
|
+
},
|
|
898
|
+
{
|
|
899
|
+
name: 'intUserDefaultProp',
|
|
900
|
+
optional: true,
|
|
901
|
+
typeAnnotation: {
|
|
902
|
+
type: 'Int32TypeAnnotation',
|
|
903
|
+
default: 9999,
|
|
904
|
+
},
|
|
905
|
+
},
|
|
874
906
|
{
|
|
875
907
|
name: 'stringEnumProp',
|
|
876
908
|
optional: true,
|