@react-native/codegen 0.72.3 → 0.73.0
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 -10
- package/lib/CodegenSchema.js.flow +6 -1
- package/lib/SchemaValidator.d.ts +1 -1
- package/lib/generators/RNCodegen.d.ts +98 -0
- package/lib/generators/RNCodegen.js +33 -4
- package/lib/generators/RNCodegen.js.flow +35 -4
- package/lib/generators/components/ComponentsGeneratorUtils.js +2 -0
- package/lib/generators/components/ComponentsGeneratorUtils.js.flow +2 -0
- package/lib/generators/components/CppHelpers.js +2 -0
- package/lib/generators/components/CppHelpers.js.flow +2 -0
- package/lib/generators/components/GenerateEventEmitterCpp.js +33 -44
- package/lib/generators/components/GenerateEventEmitterCpp.js.flow +35 -44
- package/lib/generators/components/GenerateEventEmitterH.js +0 -2
- package/lib/generators/components/GenerateEventEmitterH.js.flow +0 -2
- package/lib/generators/components/GeneratePropsH.js +2 -0
- package/lib/generators/components/GeneratePropsH.js.flow +2 -0
- package/lib/generators/components/GeneratePropsJavaDelegate.js +2 -0
- package/lib/generators/components/GeneratePropsJavaDelegate.js.flow +2 -0
- package/lib/generators/components/GeneratePropsJavaInterface.js +2 -0
- package/lib/generators/components/GeneratePropsJavaInterface.js.flow +2 -0
- package/lib/generators/components/GeneratePropsJavaPojo/PojoCollector.js.flow +3 -1
- package/lib/generators/components/GeneratePropsJavaPojo/serializePojo.js +5 -0
- package/lib/generators/components/GeneratePropsJavaPojo/serializePojo.js.flow +6 -0
- package/lib/generators/components/GenerateViewConfigJs.js +1 -0
- package/lib/generators/components/GenerateViewConfigJs.js.flow +1 -0
- package/lib/generators/components/JavaHelpers.js +7 -0
- package/lib/generators/components/JavaHelpers.js.flow +8 -0
- package/lib/generators/components/__test_fixtures__/fixtures.js +29 -0
- package/lib/generators/components/__test_fixtures__/fixtures.js.flow +30 -0
- package/lib/generators/modules/GenerateModuleCpp.js +3 -3
- package/lib/generators/modules/GenerateModuleCpp.js.flow +3 -3
- package/lib/generators/modules/GenerateModuleJavaSpec.js +1 -2
- package/lib/generators/modules/GenerateModuleJavaSpec.js.flow +1 -2
- package/lib/parsers/error-utils.js +9 -15
- package/lib/parsers/error-utils.js.flow +12 -15
- package/lib/parsers/flow/components/__test_fixtures__/fixtures.js +5 -1
- package/lib/parsers/flow/components/__test_fixtures__/fixtures.js.flow +5 -1
- package/lib/parsers/flow/components/componentsUtils.js +4 -0
- package/lib/parsers/flow/components/componentsUtils.js.flow +4 -0
- package/lib/parsers/flow/components/index.js +35 -168
- package/lib/parsers/flow/components/index.js.flow +33 -107
- package/lib/parsers/flow/modules/__test_fixtures__/fixtures.js +4 -4
- package/lib/parsers/flow/modules/__test_fixtures__/fixtures.js.flow +4 -4
- package/lib/parsers/flow/modules/index.js +51 -327
- package/lib/parsers/flow/modules/index.js.flow +34 -258
- package/lib/parsers/flow/parser.js +84 -13
- package/lib/parsers/flow/parser.js.flow +80 -4
- package/lib/parsers/parser.d.ts +2 -2
- package/lib/parsers/parser.js.flow +84 -3
- package/lib/parsers/parserMock.js +53 -0
- package/lib/parsers/parserMock.js.flow +64 -1
- package/lib/parsers/parsers-commons.js +397 -4
- package/lib/parsers/parsers-commons.js.flow +391 -4
- package/lib/parsers/parsers-primitives.js +121 -3
- package/lib/parsers/parsers-primitives.js.flow +134 -3
- package/lib/parsers/schema/index.d.ts +1 -1
- package/lib/parsers/typescript/components/__test_fixtures__/fixtures.js +5 -1
- package/lib/parsers/typescript/components/__test_fixtures__/fixtures.js.flow +5 -1
- package/lib/parsers/typescript/components/componentsUtils.js +8 -0
- package/lib/parsers/typescript/components/componentsUtils.js.flow +8 -0
- package/lib/parsers/typescript/components/index.js +37 -170
- package/lib/parsers/typescript/components/index.js.flow +33 -109
- package/lib/parsers/typescript/modules/index.js +113 -441
- package/lib/parsers/typescript/modules/index.js.flow +100 -309
- package/lib/parsers/typescript/parser.js +97 -13
- package/lib/parsers/typescript/parser.js.flow +94 -4
- package/lib/parsers/utils.js +4 -0
- package/lib/parsers/utils.js.flow +3 -0
- package/package.json +1 -1
- package/lib/parsers/flow/Visitor.js +0 -37
- package/lib/parsers/flow/Visitor.js.flow +0 -41
- package/lib/parsers/flow/components/options.js +0 -72
- package/lib/parsers/flow/components/options.js.flow +0 -87
- package/lib/parsers/typescript/Visitor.js +0 -42
- package/lib/parsers/typescript/Visitor.js.flow +0 -47
- package/lib/parsers/typescript/components/options.js +0 -72
- package/lib/parsers/typescript/components/options.js.flow +0 -87
|
@@ -120,6 +120,8 @@ function getJavaValueForProp(prop, componentName) {
|
|
|
120
120
|
return '(String) value';
|
|
121
121
|
case 'Int32EnumTypeAnnotation':
|
|
122
122
|
return `value == null ? ${typeAnnotation.default} : ((Double) value).intValue()`;
|
|
123
|
+
case 'MixedTypeAnnotation':
|
|
124
|
+
return 'new DynamicFromObject(value)';
|
|
123
125
|
default:
|
|
124
126
|
typeAnnotation;
|
|
125
127
|
throw new Error('Received invalid typeAnnotation');
|
|
@@ -144,6 +144,8 @@ function getJavaValueForProp(
|
|
|
144
144
|
return '(String) value';
|
|
145
145
|
case 'Int32EnumTypeAnnotation':
|
|
146
146
|
return `value == null ? ${typeAnnotation.default} : ((Double) value).intValue()`;
|
|
147
|
+
case 'MixedTypeAnnotation':
|
|
148
|
+
return 'new DynamicFromObject(value)';
|
|
147
149
|
default:
|
|
148
150
|
(typeAnnotation: empty);
|
|
149
151
|
throw new Error('Received invalid typeAnnotation');
|
|
@@ -105,6 +105,8 @@ function getJavaValueForProp(prop, imports) {
|
|
|
105
105
|
case 'Int32EnumTypeAnnotation':
|
|
106
106
|
addNullable(imports);
|
|
107
107
|
return '@Nullable Integer value';
|
|
108
|
+
case 'MixedTypeAnnotation':
|
|
109
|
+
return 'Dynamic value';
|
|
108
110
|
default:
|
|
109
111
|
typeAnnotation;
|
|
110
112
|
throw new Error('Received invalid typeAnnotation');
|
|
@@ -127,6 +127,8 @@ function getJavaValueForProp(
|
|
|
127
127
|
case 'Int32EnumTypeAnnotation':
|
|
128
128
|
addNullable(imports);
|
|
129
129
|
return '@Nullable Integer value';
|
|
130
|
+
case 'MixedTypeAnnotation':
|
|
131
|
+
return 'Dynamic value';
|
|
130
132
|
default:
|
|
131
133
|
(typeAnnotation: empty);
|
|
132
134
|
throw new Error('Received invalid typeAnnotation');
|
|
@@ -20,6 +20,7 @@ import type {
|
|
|
20
20
|
FloatTypeAnnotation,
|
|
21
21
|
Int32TypeAnnotation,
|
|
22
22
|
PropTypeAnnotation,
|
|
23
|
+
MixedTypeAnnotation,
|
|
23
24
|
} from '../../../CodegenSchema';
|
|
24
25
|
|
|
25
26
|
const {capitalize} = require('../../Utils');
|
|
@@ -89,7 +90,8 @@ export type PojoTypeAnnotation =
|
|
|
89
90
|
type: 'ArrayTypeAnnotation',
|
|
90
91
|
elementType: PojoTypeAliasAnnotation,
|
|
91
92
|
}>,
|
|
92
|
-
}
|
|
93
|
+
}>
|
|
94
|
+
| MixedTypeAnnotation;
|
|
93
95
|
|
|
94
96
|
class PojoCollector {
|
|
95
97
|
_pojos: Map<string, Pojo> = new Map();
|
|
@@ -18,6 +18,7 @@ function toJavaType(typeAnnotation, addImport) {
|
|
|
18
18
|
addImport('com.facebook.react.bridge.ReadableMap');
|
|
19
19
|
const importArrayList = () => addImport('java.util.ArrayList');
|
|
20
20
|
const importYogaValue = () => addImport('com.facebook.yoga.YogaValue');
|
|
21
|
+
const importDynamic = () => addImport('com.facebook.react.bridge.Dynamic');
|
|
21
22
|
switch (typeAnnotation.type) {
|
|
22
23
|
/**
|
|
23
24
|
* Primitives
|
|
@@ -208,6 +209,10 @@ function toJavaType(typeAnnotation, addImport) {
|
|
|
208
209
|
importArrayList();
|
|
209
210
|
return `ArrayList<${elementTypeString}>`;
|
|
210
211
|
}
|
|
212
|
+
case 'MixedTypeAnnotation': {
|
|
213
|
+
importDynamic();
|
|
214
|
+
return 'Dynamic';
|
|
215
|
+
}
|
|
211
216
|
default: {
|
|
212
217
|
typeAnnotation.type;
|
|
213
218
|
throw new Error(
|
|
@@ -24,6 +24,7 @@ function toJavaType(
|
|
|
24
24
|
addImport('com.facebook.react.bridge.ReadableMap');
|
|
25
25
|
const importArrayList = () => addImport('java.util.ArrayList');
|
|
26
26
|
const importYogaValue = () => addImport('com.facebook.yoga.YogaValue');
|
|
27
|
+
const importDynamic = () => addImport('com.facebook.react.bridge.Dynamic');
|
|
27
28
|
switch (typeAnnotation.type) {
|
|
28
29
|
/**
|
|
29
30
|
* Primitives
|
|
@@ -222,6 +223,11 @@ function toJavaType(
|
|
|
222
223
|
return `ArrayList<${elementTypeString}>`;
|
|
223
224
|
}
|
|
224
225
|
|
|
226
|
+
case 'MixedTypeAnnotation': {
|
|
227
|
+
importDynamic();
|
|
228
|
+
return 'Dynamic';
|
|
229
|
+
}
|
|
230
|
+
|
|
225
231
|
default: {
|
|
226
232
|
(typeAnnotation.type: empty);
|
|
227
233
|
throw new Error(
|
|
@@ -46,6 +46,7 @@ function getReactDiffProcessValue(typeAnnotation) {
|
|
|
46
46
|
case 'ObjectTypeAnnotation':
|
|
47
47
|
case 'StringEnumTypeAnnotation':
|
|
48
48
|
case 'Int32EnumTypeAnnotation':
|
|
49
|
+
case 'MixedTypeAnnotation':
|
|
49
50
|
return j.literal(true);
|
|
50
51
|
case 'ReservedPropTypeAnnotation':
|
|
51
52
|
switch (typeAnnotation.name) {
|
|
@@ -60,6 +60,7 @@ function getReactDiffProcessValue(typeAnnotation: PropTypeAnnotation) {
|
|
|
60
60
|
case 'ObjectTypeAnnotation':
|
|
61
61
|
case 'StringEnumTypeAnnotation':
|
|
62
62
|
case 'Int32EnumTypeAnnotation':
|
|
63
|
+
case 'MixedTypeAnnotation':
|
|
63
64
|
return j.literal(true);
|
|
64
65
|
case 'ReservedPropTypeAnnotation':
|
|
65
66
|
switch (typeAnnotation.name) {
|
|
@@ -85,6 +85,13 @@ function getImports(component, type) {
|
|
|
85
85
|
if (typeAnnotation.type === 'ObjectTypeAnnotation') {
|
|
86
86
|
imports.add('import com.facebook.react.bridge.ReadableMap;');
|
|
87
87
|
}
|
|
88
|
+
if (typeAnnotation.type === 'MixedTypeAnnotation') {
|
|
89
|
+
if (type === 'delegate') {
|
|
90
|
+
imports.add('import com.facebook.react.bridge.DynamicFromObject;');
|
|
91
|
+
} else {
|
|
92
|
+
imports.add('import com.facebook.react.bridge.Dynamic;');
|
|
93
|
+
}
|
|
94
|
+
}
|
|
88
95
|
});
|
|
89
96
|
return imports;
|
|
90
97
|
}
|
|
@@ -117,6 +117,14 @@ function getImports(
|
|
|
117
117
|
if (typeAnnotation.type === 'ObjectTypeAnnotation') {
|
|
118
118
|
imports.add('import com.facebook.react.bridge.ReadableMap;');
|
|
119
119
|
}
|
|
120
|
+
|
|
121
|
+
if (typeAnnotation.type === 'MixedTypeAnnotation') {
|
|
122
|
+
if (type === 'delegate') {
|
|
123
|
+
imports.add('import com.facebook.react.bridge.DynamicFromObject;');
|
|
124
|
+
} else {
|
|
125
|
+
imports.add('import com.facebook.react.bridge.Dynamic;');
|
|
126
|
+
}
|
|
127
|
+
}
|
|
120
128
|
});
|
|
121
129
|
|
|
122
130
|
return imports;
|
|
@@ -1102,6 +1102,34 @@ const INT32_ENUM_PROP = {
|
|
|
1102
1102
|
},
|
|
1103
1103
|
},
|
|
1104
1104
|
};
|
|
1105
|
+
const MIXED_PROP = {
|
|
1106
|
+
modules: {
|
|
1107
|
+
CustomView: {
|
|
1108
|
+
type: 'Component',
|
|
1109
|
+
components: {
|
|
1110
|
+
MixedPropNativeComponent: {
|
|
1111
|
+
extendsProps: [
|
|
1112
|
+
{
|
|
1113
|
+
type: 'ReactNativeBuiltInType',
|
|
1114
|
+
knownTypeName: 'ReactNativeCoreViewProps',
|
|
1115
|
+
},
|
|
1116
|
+
],
|
|
1117
|
+
events: [],
|
|
1118
|
+
props: [
|
|
1119
|
+
{
|
|
1120
|
+
name: 'mixedProp',
|
|
1121
|
+
optional: false,
|
|
1122
|
+
typeAnnotation: {
|
|
1123
|
+
type: 'MixedTypeAnnotation',
|
|
1124
|
+
},
|
|
1125
|
+
},
|
|
1126
|
+
],
|
|
1127
|
+
commands: [],
|
|
1128
|
+
},
|
|
1129
|
+
},
|
|
1130
|
+
},
|
|
1131
|
+
},
|
|
1132
|
+
};
|
|
1105
1133
|
const EVENT_PROPS = {
|
|
1106
1134
|
modules: {
|
|
1107
1135
|
Switch: {
|
|
@@ -1669,6 +1697,7 @@ module.exports = {
|
|
|
1669
1697
|
MULTI_NATIVE_PROP,
|
|
1670
1698
|
STRING_ENUM_PROP,
|
|
1671
1699
|
INT32_ENUM_PROP,
|
|
1700
|
+
MIXED_PROP,
|
|
1672
1701
|
EVENT_PROPS,
|
|
1673
1702
|
EVENTS_WITH_PAPER_NAME,
|
|
1674
1703
|
EVENT_NESTED_OBJECT_PROPS,
|
|
@@ -1123,6 +1123,35 @@ const INT32_ENUM_PROP: SchemaType = {
|
|
|
1123
1123
|
},
|
|
1124
1124
|
};
|
|
1125
1125
|
|
|
1126
|
+
const MIXED_PROP: SchemaType = {
|
|
1127
|
+
modules: {
|
|
1128
|
+
CustomView: {
|
|
1129
|
+
type: 'Component',
|
|
1130
|
+
components: {
|
|
1131
|
+
MixedPropNativeComponent: {
|
|
1132
|
+
extendsProps: [
|
|
1133
|
+
{
|
|
1134
|
+
type: 'ReactNativeBuiltInType',
|
|
1135
|
+
knownTypeName: 'ReactNativeCoreViewProps',
|
|
1136
|
+
},
|
|
1137
|
+
],
|
|
1138
|
+
events: [],
|
|
1139
|
+
props: [
|
|
1140
|
+
{
|
|
1141
|
+
name: 'mixedProp',
|
|
1142
|
+
optional: false,
|
|
1143
|
+
typeAnnotation: {
|
|
1144
|
+
type: 'MixedTypeAnnotation',
|
|
1145
|
+
},
|
|
1146
|
+
},
|
|
1147
|
+
],
|
|
1148
|
+
commands: [],
|
|
1149
|
+
},
|
|
1150
|
+
},
|
|
1151
|
+
},
|
|
1152
|
+
},
|
|
1153
|
+
};
|
|
1154
|
+
|
|
1126
1155
|
const EVENT_PROPS: SchemaType = {
|
|
1127
1156
|
modules: {
|
|
1128
1157
|
Switch: {
|
|
@@ -1701,6 +1730,7 @@ module.exports = {
|
|
|
1701
1730
|
MULTI_NATIVE_PROP,
|
|
1702
1731
|
STRING_ENUM_PROP,
|
|
1703
1732
|
INT32_ENUM_PROP,
|
|
1733
|
+
MIXED_PROP,
|
|
1704
1734
|
EVENT_PROPS,
|
|
1705
1735
|
EVENTS_WITH_PAPER_NAME,
|
|
1706
1736
|
EVENT_NESTED_OBJECT_PROPS,
|
|
@@ -91,8 +91,8 @@ const HostFunctionTemplate = ({
|
|
|
91
91
|
}) => {
|
|
92
92
|
const isNullable = returnTypeAnnotation.type === 'NullableTypeAnnotation';
|
|
93
93
|
const isVoid = returnTypeAnnotation.type === 'VoidTypeAnnotation';
|
|
94
|
-
const methodCallArgs = ['rt', ...args].join('
|
|
95
|
-
const methodCall = `static_cast<${hasteModuleName}CxxSpecJSI *>(&turboModule)->${methodName}(${methodCallArgs})`;
|
|
94
|
+
const methodCallArgs = [' rt', ...args].join(',\n ');
|
|
95
|
+
const methodCall = `static_cast<${hasteModuleName}CxxSpecJSI *>(&turboModule)->${methodName}(\n${methodCallArgs}\n )`;
|
|
96
96
|
return `static jsi::Value __hostFunction_${hasteModuleName}CxxSpecJSI_${methodName}(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) {${
|
|
97
97
|
isVoid
|
|
98
98
|
? `\n ${methodCall};`
|
|
@@ -168,7 +168,7 @@ function serializeArg(moduleName, arg, index, resolveAlias, enumMap) {
|
|
|
168
168
|
} else {
|
|
169
169
|
let condition = `${val}.isNull() || ${val}.isUndefined()`;
|
|
170
170
|
if (optional) {
|
|
171
|
-
condition = `count
|
|
171
|
+
condition = `count <= ${index} || ${condition}`;
|
|
172
172
|
}
|
|
173
173
|
return `${condition} ? std::nullopt : std::make_optional(${expression})`;
|
|
174
174
|
}
|
|
@@ -40,8 +40,8 @@ const HostFunctionTemplate = ({
|
|
|
40
40
|
}>) => {
|
|
41
41
|
const isNullable = returnTypeAnnotation.type === 'NullableTypeAnnotation';
|
|
42
42
|
const isVoid = returnTypeAnnotation.type === 'VoidTypeAnnotation';
|
|
43
|
-
const methodCallArgs = ['rt', ...args].join('
|
|
44
|
-
const methodCall = `static_cast<${hasteModuleName}CxxSpecJSI *>(&turboModule)->${methodName}(${methodCallArgs})`;
|
|
43
|
+
const methodCallArgs = [' rt', ...args].join(',\n ');
|
|
44
|
+
const methodCall = `static_cast<${hasteModuleName}CxxSpecJSI *>(&turboModule)->${methodName}(\n${methodCallArgs}\n )`;
|
|
45
45
|
|
|
46
46
|
return `static jsi::Value __hostFunction_${hasteModuleName}CxxSpecJSI_${methodName}(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) {${
|
|
47
47
|
isVoid
|
|
@@ -139,7 +139,7 @@ function serializeArg(
|
|
|
139
139
|
} else {
|
|
140
140
|
let condition = `${val}.isNull() || ${val}.isUndefined()`;
|
|
141
141
|
if (optional) {
|
|
142
|
-
condition = `count
|
|
142
|
+
condition = `count <= ${index} || ${condition}`;
|
|
143
143
|
}
|
|
144
144
|
return `${condition} ? std::nullopt : std::make_optional(${expression})`;
|
|
145
145
|
}
|
|
@@ -105,7 +105,7 @@ package ${packageName};
|
|
|
105
105
|
|
|
106
106
|
${imports}
|
|
107
107
|
|
|
108
|
-
public abstract class ${className} extends ReactContextBaseJavaModule implements
|
|
108
|
+
public abstract class ${className} extends ReactContextBaseJavaModule implements TurboModule {
|
|
109
109
|
public static final String NAME = "${jsName}";
|
|
110
110
|
|
|
111
111
|
public ${className}(ReactApplicationContext reactContext) {
|
|
@@ -488,7 +488,6 @@ module.exports = {
|
|
|
488
488
|
'com.facebook.react.bridge.ReactApplicationContext',
|
|
489
489
|
'com.facebook.react.bridge.ReactContextBaseJavaModule',
|
|
490
490
|
'com.facebook.react.bridge.ReactMethod',
|
|
491
|
-
'com.facebook.react.bridge.ReactModuleWithSpec',
|
|
492
491
|
'com.facebook.react.turbomodule.core.interfaces.TurboModule',
|
|
493
492
|
'com.facebook.proguard.annotations.DoNotStrip',
|
|
494
493
|
'javax.annotation.Nonnull',
|
|
@@ -52,7 +52,7 @@ package ${packageName};
|
|
|
52
52
|
|
|
53
53
|
${imports}
|
|
54
54
|
|
|
55
|
-
public abstract class ${className} extends ReactContextBaseJavaModule implements
|
|
55
|
+
public abstract class ${className} extends ReactContextBaseJavaModule implements TurboModule {
|
|
56
56
|
public static final String NAME = "${jsName}";
|
|
57
57
|
|
|
58
58
|
public ${className}(ReactApplicationContext reactContext) {
|
|
@@ -463,7 +463,6 @@ module.exports = {
|
|
|
463
463
|
'com.facebook.react.bridge.ReactApplicationContext',
|
|
464
464
|
'com.facebook.react.bridge.ReactContextBaseJavaModule',
|
|
465
465
|
'com.facebook.react.bridge.ReactMethod',
|
|
466
|
-
'com.facebook.react.bridge.ReactModuleWithSpec',
|
|
467
466
|
'com.facebook.react.turbomodule.core.interfaces.TurboModule',
|
|
468
467
|
'com.facebook.proguard.annotations.DoNotStrip',
|
|
469
468
|
'javax.annotation.Nonnull',
|
|
@@ -157,27 +157,15 @@ function throwIfModuleTypeIsUnsupported(
|
|
|
157
157
|
propertyValue,
|
|
158
158
|
propertyName,
|
|
159
159
|
propertyValueType,
|
|
160
|
-
|
|
160
|
+
parser,
|
|
161
161
|
) {
|
|
162
|
-
if (
|
|
163
|
-
throw new UnsupportedModulePropertyParserError(
|
|
164
|
-
nativeModuleName,
|
|
165
|
-
propertyValue,
|
|
166
|
-
propertyName,
|
|
167
|
-
propertyValueType,
|
|
168
|
-
language,
|
|
169
|
-
);
|
|
170
|
-
} else if (
|
|
171
|
-
language === 'TypeScript' &&
|
|
172
|
-
propertyValueType !== 'TSFunctionType' &&
|
|
173
|
-
propertyValueType !== 'TSMethodSignature'
|
|
174
|
-
) {
|
|
162
|
+
if (!parser.functionTypeAnnotation(propertyValueType)) {
|
|
175
163
|
throw new UnsupportedModulePropertyParserError(
|
|
176
164
|
nativeModuleName,
|
|
177
165
|
propertyValue,
|
|
178
166
|
propertyName,
|
|
179
167
|
propertyValueType,
|
|
180
|
-
language,
|
|
168
|
+
parser.language(),
|
|
181
169
|
);
|
|
182
170
|
}
|
|
183
171
|
}
|
|
@@ -287,6 +275,11 @@ function throwIfPartialWithMoreParameter(typeAnnotation) {
|
|
|
287
275
|
throw new Error('Partials only support annotating exactly one parameter.');
|
|
288
276
|
}
|
|
289
277
|
}
|
|
278
|
+
function throwIfMoreThanOneCodegenNativecommands(commandsTypeNames) {
|
|
279
|
+
if (commandsTypeNames.length > 1) {
|
|
280
|
+
throw new Error('codegenNativeCommands may only be called once in a file');
|
|
281
|
+
}
|
|
282
|
+
}
|
|
290
283
|
module.exports = {
|
|
291
284
|
throwIfModuleInterfaceIsMisnamed,
|
|
292
285
|
throwIfUnsupportedFunctionReturnTypeAnnotationParserError,
|
|
@@ -304,4 +297,5 @@ module.exports = {
|
|
|
304
297
|
throwIfIncorrectModuleRegistryCallArgument,
|
|
305
298
|
throwIfPartialNotAnnotatingTypeParameter,
|
|
306
299
|
throwIfPartialWithMoreParameter,
|
|
300
|
+
throwIfMoreThanOneCodegenNativecommands,
|
|
307
301
|
};
|
|
@@ -160,27 +160,15 @@ function throwIfModuleTypeIsUnsupported(
|
|
|
160
160
|
propertyValue: $FlowFixMe,
|
|
161
161
|
propertyName: string,
|
|
162
162
|
propertyValueType: string,
|
|
163
|
-
|
|
163
|
+
parser: Parser,
|
|
164
164
|
) {
|
|
165
|
-
if (
|
|
166
|
-
throw new UnsupportedModulePropertyParserError(
|
|
167
|
-
nativeModuleName,
|
|
168
|
-
propertyValue,
|
|
169
|
-
propertyName,
|
|
170
|
-
propertyValueType,
|
|
171
|
-
language,
|
|
172
|
-
);
|
|
173
|
-
} else if (
|
|
174
|
-
language === 'TypeScript' &&
|
|
175
|
-
propertyValueType !== 'TSFunctionType' &&
|
|
176
|
-
propertyValueType !== 'TSMethodSignature'
|
|
177
|
-
) {
|
|
165
|
+
if (!parser.functionTypeAnnotation(propertyValueType)) {
|
|
178
166
|
throw new UnsupportedModulePropertyParserError(
|
|
179
167
|
nativeModuleName,
|
|
180
168
|
propertyValue,
|
|
181
169
|
propertyName,
|
|
182
170
|
propertyValueType,
|
|
183
|
-
language,
|
|
171
|
+
parser.language(),
|
|
184
172
|
);
|
|
185
173
|
}
|
|
186
174
|
}
|
|
@@ -302,6 +290,14 @@ function throwIfPartialWithMoreParameter(typeAnnotation: $FlowFixMe) {
|
|
|
302
290
|
}
|
|
303
291
|
}
|
|
304
292
|
|
|
293
|
+
function throwIfMoreThanOneCodegenNativecommands(
|
|
294
|
+
commandsTypeNames: $ReadOnlyArray<$FlowFixMe>,
|
|
295
|
+
) {
|
|
296
|
+
if (commandsTypeNames.length > 1) {
|
|
297
|
+
throw new Error('codegenNativeCommands may only be called once in a file');
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
|
|
305
301
|
module.exports = {
|
|
306
302
|
throwIfModuleInterfaceIsMisnamed,
|
|
307
303
|
throwIfUnsupportedFunctionReturnTypeAnnotationParserError,
|
|
@@ -319,4 +315,5 @@ module.exports = {
|
|
|
319
315
|
throwIfIncorrectModuleRegistryCallArgument,
|
|
320
316
|
throwIfPartialNotAnnotatingTypeParameter,
|
|
321
317
|
throwIfPartialWithMoreParameter,
|
|
318
|
+
throwIfMoreThanOneCodegenNativecommands,
|
|
322
319
|
};
|
|
@@ -205,7 +205,7 @@ const ALL_PROP_TYPES_NO_EVENTS = `
|
|
|
205
205
|
|
|
206
206
|
const codegenNativeComponent = require('codegenNativeComponent');
|
|
207
207
|
|
|
208
|
-
import type {Int32, Double, Float, WithDefault} from 'CodegenTypes';
|
|
208
|
+
import type {Int32, Double, Float, WithDefault, UnsafeMixed} from 'CodegenTypes';
|
|
209
209
|
import type {ImageSource} from 'ImageSource';
|
|
210
210
|
import type {ColorValue, ColorArrayValue, PointValue, EdgeInsetsValue, DimensionValue} from 'StyleSheetTypes';
|
|
211
211
|
import type {ViewProps} from 'ViewPropTypes';
|
|
@@ -313,6 +313,10 @@ type ModuleProps = $ReadOnly<{|
|
|
|
313
313
|
dimension_optional_key?: DimensionValue,
|
|
314
314
|
dimension_optional_value: ?DimensionValue,
|
|
315
315
|
dimension_optional_both?: ?DimensionValue,
|
|
316
|
+
|
|
317
|
+
// Mixed props
|
|
318
|
+
mixed_required: UnsafeMixed,
|
|
319
|
+
mixed_optional_key?: UnsafeMixed,
|
|
316
320
|
|}>;
|
|
317
321
|
|
|
318
322
|
export default (codegenNativeComponent<ModuleProps, Options>(
|
|
@@ -209,7 +209,7 @@ const ALL_PROP_TYPES_NO_EVENTS = `
|
|
|
209
209
|
|
|
210
210
|
const codegenNativeComponent = require('codegenNativeComponent');
|
|
211
211
|
|
|
212
|
-
import type {Int32, Double, Float, WithDefault} from 'CodegenTypes';
|
|
212
|
+
import type {Int32, Double, Float, WithDefault, UnsafeMixed} from 'CodegenTypes';
|
|
213
213
|
import type {ImageSource} from 'ImageSource';
|
|
214
214
|
import type {ColorValue, ColorArrayValue, PointValue, EdgeInsetsValue, DimensionValue} from 'StyleSheetTypes';
|
|
215
215
|
import type {ViewProps} from 'ViewPropTypes';
|
|
@@ -317,6 +317,10 @@ type ModuleProps = $ReadOnly<{|
|
|
|
317
317
|
dimension_optional_key?: DimensionValue,
|
|
318
318
|
dimension_optional_value: ?DimensionValue,
|
|
319
319
|
dimension_optional_both?: ?DimensionValue,
|
|
320
|
+
|
|
321
|
+
// Mixed props
|
|
322
|
+
mixed_required: UnsafeMixed,
|
|
323
|
+
mixed_optional_key?: UnsafeMixed,
|
|
320
324
|
|}>;
|
|
321
325
|
|
|
322
326
|
export default (codegenNativeComponent<ModuleProps, Options>(
|
|
@@ -364,6 +364,10 @@ function getTypeAnnotation(
|
|
|
364
364
|
throw new Error(
|
|
365
365
|
`Cannot use "${type}" type annotation for "${name}": must use a specific numeric type like Int32, Double, or Float`,
|
|
366
366
|
);
|
|
367
|
+
case 'UnsafeMixed':
|
|
368
|
+
return {
|
|
369
|
+
type: 'MixedTypeAnnotation',
|
|
370
|
+
};
|
|
367
371
|
default:
|
|
368
372
|
type;
|
|
369
373
|
throw new Error(
|
|
@@ -391,6 +391,10 @@ function getTypeAnnotation<+T>(
|
|
|
391
391
|
throw new Error(
|
|
392
392
|
`Cannot use "${type}" type annotation for "${name}": must use a specific numeric type like Int32, Double, or Float`,
|
|
393
393
|
);
|
|
394
|
+
case 'UnsafeMixed':
|
|
395
|
+
return {
|
|
396
|
+
type: 'MixedTypeAnnotation',
|
|
397
|
+
};
|
|
394
398
|
default:
|
|
395
399
|
(type: empty);
|
|
396
400
|
throw new Error(
|