@react-native/codegen 0.73.0-nightly-20230731-b0a8d45e2 → 0.73.0-nightly-20230807-f9a63ec00
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/errors.js +3 -9
- package/lib/parsers/errors.js.flow +3 -9
- package/lib/parsers/flow/components/componentsUtils.js +5 -7
- package/lib/parsers/flow/components/componentsUtils.js.flow +5 -7
- package/lib/parsers/flow/components/events.js +13 -16
- package/lib/parsers/flow/components/events.js.flow +16 -15
- package/lib/parsers/flow/modules/index.js +1 -1
- package/lib/parsers/flow/modules/index.js.flow +1 -1
- package/lib/parsers/flow/parser.js +2 -2
- package/lib/parsers/flow/parser.js.flow +2 -2
- package/lib/parsers/parser.js.flow +2 -2
- package/lib/parsers/parserMock.js +8 -2
- package/lib/parsers/parserMock.js.flow +2 -2
- package/lib/parsers/parsers-commons.js +2 -2
- package/lib/parsers/parsers-commons.js.flow +2 -2
- package/lib/parsers/parsers-primitives.js +14 -1
- package/lib/parsers/parsers-primitives.js.flow +20 -1
- package/lib/parsers/typescript/components/componentsUtils.js +3 -4
- package/lib/parsers/typescript/components/componentsUtils.js.flow +3 -4
- package/lib/parsers/typescript/components/events.js +14 -14
- package/lib/parsers/typescript/components/events.js.flow +17 -13
- package/lib/parsers/typescript/modules/index.js +1 -1
- package/lib/parsers/typescript/modules/index.js.flow +1 -1
- package/lib/parsers/typescript/parser.js +4 -4
- package/lib/parsers/typescript/parser.js.flow +4 -4
- package/package.json +1 -1
package/lib/parsers/errors.js
CHANGED
|
@@ -84,9 +84,7 @@ class UnsupportedTypeAnnotationParserError extends ParserError {
|
|
|
84
84
|
class UnsupportedGenericParserError extends ParserError {
|
|
85
85
|
// +genericName: string;
|
|
86
86
|
constructor(nativeModuleName, genericTypeAnnotation, parser) {
|
|
87
|
-
const genericName = parser.
|
|
88
|
-
genericTypeAnnotation,
|
|
89
|
-
);
|
|
87
|
+
const genericName = parser.getTypeAnnotationName(genericTypeAnnotation);
|
|
90
88
|
super(
|
|
91
89
|
nativeModuleName,
|
|
92
90
|
genericTypeAnnotation,
|
|
@@ -99,9 +97,7 @@ class UnsupportedGenericParserError extends ParserError {
|
|
|
99
97
|
|
|
100
98
|
class MissingTypeParameterGenericParserError extends ParserError {
|
|
101
99
|
constructor(nativeModuleName, genericTypeAnnotation, parser) {
|
|
102
|
-
const genericName = parser.
|
|
103
|
-
genericTypeAnnotation,
|
|
104
|
-
);
|
|
100
|
+
const genericName = parser.getTypeAnnotationName(genericTypeAnnotation);
|
|
105
101
|
super(
|
|
106
102
|
nativeModuleName,
|
|
107
103
|
genericTypeAnnotation,
|
|
@@ -111,9 +107,7 @@ class MissingTypeParameterGenericParserError extends ParserError {
|
|
|
111
107
|
}
|
|
112
108
|
class MoreThanOneTypeParameterGenericParserError extends ParserError {
|
|
113
109
|
constructor(nativeModuleName, genericTypeAnnotation, parser) {
|
|
114
|
-
const genericName = parser.
|
|
115
|
-
genericTypeAnnotation,
|
|
116
|
-
);
|
|
110
|
+
const genericName = parser.getTypeAnnotationName(genericTypeAnnotation);
|
|
117
111
|
super(
|
|
118
112
|
nativeModuleName,
|
|
119
113
|
genericTypeAnnotation,
|
|
@@ -117,9 +117,7 @@ class UnsupportedGenericParserError extends ParserError {
|
|
|
117
117
|
genericTypeAnnotation: $FlowFixMe,
|
|
118
118
|
parser: Parser,
|
|
119
119
|
) {
|
|
120
|
-
const genericName = parser.
|
|
121
|
-
genericTypeAnnotation,
|
|
122
|
-
);
|
|
120
|
+
const genericName = parser.getTypeAnnotationName(genericTypeAnnotation);
|
|
123
121
|
super(
|
|
124
122
|
nativeModuleName,
|
|
125
123
|
genericTypeAnnotation,
|
|
@@ -136,9 +134,7 @@ class MissingTypeParameterGenericParserError extends ParserError {
|
|
|
136
134
|
genericTypeAnnotation: $FlowFixMe,
|
|
137
135
|
parser: Parser,
|
|
138
136
|
) {
|
|
139
|
-
const genericName = parser.
|
|
140
|
-
genericTypeAnnotation,
|
|
141
|
-
);
|
|
137
|
+
const genericName = parser.getTypeAnnotationName(genericTypeAnnotation);
|
|
142
138
|
|
|
143
139
|
super(
|
|
144
140
|
nativeModuleName,
|
|
@@ -154,9 +150,7 @@ class MoreThanOneTypeParameterGenericParserError extends ParserError {
|
|
|
154
150
|
genericTypeAnnotation: $FlowFixMe,
|
|
155
151
|
parser: Parser,
|
|
156
152
|
) {
|
|
157
|
-
const genericName = parser.
|
|
158
|
-
genericTypeAnnotation,
|
|
159
|
-
);
|
|
153
|
+
const genericName = parser.getTypeAnnotationName(genericTypeAnnotation);
|
|
160
154
|
|
|
161
155
|
super(
|
|
162
156
|
nativeModuleName,
|
|
@@ -30,7 +30,7 @@ function getTypeAnnotationForArray(
|
|
|
30
30
|
}
|
|
31
31
|
if (
|
|
32
32
|
extractedTypeAnnotation.type === 'GenericTypeAnnotation' &&
|
|
33
|
-
extractedTypeAnnotation
|
|
33
|
+
parser.getTypeAnnotationName(extractedTypeAnnotation) === 'WithDefault'
|
|
34
34
|
) {
|
|
35
35
|
throw new Error(
|
|
36
36
|
'Nested defaults such as "$ReadOnlyArray<WithDefault<boolean, false>>" are not supported, please declare defaults at the top level of value definitions as in "WithDefault<$ReadOnlyArray<boolean>, false>"',
|
|
@@ -75,7 +75,7 @@ function getTypeAnnotationForArray(
|
|
|
75
75
|
}
|
|
76
76
|
const type =
|
|
77
77
|
extractedTypeAnnotation.type === 'GenericTypeAnnotation'
|
|
78
|
-
? extractedTypeAnnotation
|
|
78
|
+
? parser.getTypeAnnotationName(extractedTypeAnnotation)
|
|
79
79
|
: extractedTypeAnnotation.type;
|
|
80
80
|
switch (type) {
|
|
81
81
|
case 'ImageSource':
|
|
@@ -160,7 +160,6 @@ function getTypeAnnotationForArray(
|
|
|
160
160
|
);
|
|
161
161
|
}
|
|
162
162
|
default:
|
|
163
|
-
type;
|
|
164
163
|
throw new Error(`Unknown property type for "${name}": ${type}`);
|
|
165
164
|
}
|
|
166
165
|
}
|
|
@@ -203,7 +202,7 @@ function getTypeAnnotation(
|
|
|
203
202
|
const typeAnnotation = getValueFromTypes(annotation, types);
|
|
204
203
|
if (
|
|
205
204
|
typeAnnotation.type === 'GenericTypeAnnotation' &&
|
|
206
|
-
typeAnnotation
|
|
205
|
+
parser.getTypeAnnotationName(typeAnnotation) === '$ReadOnlyArray'
|
|
207
206
|
) {
|
|
208
207
|
return {
|
|
209
208
|
type: 'ArrayTypeAnnotation',
|
|
@@ -219,7 +218,7 @@ function getTypeAnnotation(
|
|
|
219
218
|
}
|
|
220
219
|
if (
|
|
221
220
|
typeAnnotation.type === 'GenericTypeAnnotation' &&
|
|
222
|
-
typeAnnotation
|
|
221
|
+
parser.getTypeAnnotationName(typeAnnotation) === '$ReadOnly'
|
|
223
222
|
) {
|
|
224
223
|
return {
|
|
225
224
|
type: 'ObjectTypeAnnotation',
|
|
@@ -234,7 +233,7 @@ function getTypeAnnotation(
|
|
|
234
233
|
}
|
|
235
234
|
const type =
|
|
236
235
|
typeAnnotation.type === 'GenericTypeAnnotation'
|
|
237
|
-
? typeAnnotation
|
|
236
|
+
? parser.getTypeAnnotationName(typeAnnotation)
|
|
238
237
|
: typeAnnotation.type;
|
|
239
238
|
switch (type) {
|
|
240
239
|
case 'ImageSource':
|
|
@@ -361,7 +360,6 @@ function getTypeAnnotation(
|
|
|
361
360
|
type: 'MixedTypeAnnotation',
|
|
362
361
|
};
|
|
363
362
|
default:
|
|
364
|
-
type;
|
|
365
363
|
throw new Error(
|
|
366
364
|
`Unknown property type for "${name}": "${type}" in the State`,
|
|
367
365
|
);
|
|
@@ -32,7 +32,7 @@ function getTypeAnnotationForArray<+T>(
|
|
|
32
32
|
|
|
33
33
|
if (
|
|
34
34
|
extractedTypeAnnotation.type === 'GenericTypeAnnotation' &&
|
|
35
|
-
extractedTypeAnnotation
|
|
35
|
+
parser.getTypeAnnotationName(extractedTypeAnnotation) === 'WithDefault'
|
|
36
36
|
) {
|
|
37
37
|
throw new Error(
|
|
38
38
|
'Nested defaults such as "$ReadOnlyArray<WithDefault<boolean, false>>" are not supported, please declare defaults at the top level of value definitions as in "WithDefault<$ReadOnlyArray<boolean>, false>"',
|
|
@@ -82,7 +82,7 @@ function getTypeAnnotationForArray<+T>(
|
|
|
82
82
|
|
|
83
83
|
const type =
|
|
84
84
|
extractedTypeAnnotation.type === 'GenericTypeAnnotation'
|
|
85
|
-
? extractedTypeAnnotation
|
|
85
|
+
? parser.getTypeAnnotationName(extractedTypeAnnotation)
|
|
86
86
|
: extractedTypeAnnotation.type;
|
|
87
87
|
|
|
88
88
|
switch (type) {
|
|
@@ -170,7 +170,6 @@ function getTypeAnnotationForArray<+T>(
|
|
|
170
170
|
);
|
|
171
171
|
}
|
|
172
172
|
default:
|
|
173
|
-
(type: empty);
|
|
174
173
|
throw new Error(`Unknown property type for "${name}": ${type}`);
|
|
175
174
|
}
|
|
176
175
|
}
|
|
@@ -220,7 +219,7 @@ function getTypeAnnotation<+T>(
|
|
|
220
219
|
|
|
221
220
|
if (
|
|
222
221
|
typeAnnotation.type === 'GenericTypeAnnotation' &&
|
|
223
|
-
typeAnnotation
|
|
222
|
+
parser.getTypeAnnotationName(typeAnnotation) === '$ReadOnlyArray'
|
|
224
223
|
) {
|
|
225
224
|
return {
|
|
226
225
|
type: 'ArrayTypeAnnotation',
|
|
@@ -237,7 +236,7 @@ function getTypeAnnotation<+T>(
|
|
|
237
236
|
|
|
238
237
|
if (
|
|
239
238
|
typeAnnotation.type === 'GenericTypeAnnotation' &&
|
|
240
|
-
typeAnnotation
|
|
239
|
+
parser.getTypeAnnotationName(typeAnnotation) === '$ReadOnly'
|
|
241
240
|
) {
|
|
242
241
|
return {
|
|
243
242
|
type: 'ObjectTypeAnnotation',
|
|
@@ -253,7 +252,7 @@ function getTypeAnnotation<+T>(
|
|
|
253
252
|
|
|
254
253
|
const type =
|
|
255
254
|
typeAnnotation.type === 'GenericTypeAnnotation'
|
|
256
|
-
? typeAnnotation
|
|
255
|
+
? parser.getTypeAnnotationName(typeAnnotation)
|
|
257
256
|
: typeAnnotation.type;
|
|
258
257
|
|
|
259
258
|
switch (type) {
|
|
@@ -379,7 +378,6 @@ function getTypeAnnotation<+T>(
|
|
|
379
378
|
type: 'MixedTypeAnnotation',
|
|
380
379
|
};
|
|
381
380
|
default:
|
|
382
|
-
(type: empty);
|
|
383
381
|
throw new Error(
|
|
384
382
|
`Unknown property type for "${name}": "${type}" in the State`,
|
|
385
383
|
);
|
|
@@ -24,7 +24,8 @@ const _require3 = require('../../parsers-primitives'),
|
|
|
24
24
|
emitMixedProp = _require3.emitMixedProp,
|
|
25
25
|
emitStringProp = _require3.emitStringProp,
|
|
26
26
|
emitInt32Prop = _require3.emitInt32Prop,
|
|
27
|
-
emitObjectProp = _require3.emitObjectProp
|
|
27
|
+
emitObjectProp = _require3.emitObjectProp,
|
|
28
|
+
emitUnionProp = _require3.emitUnionProp;
|
|
28
29
|
function getPropertyType(
|
|
29
30
|
/* $FlowFixMe[missing-local-annot] The type annotation(s) required by Flow's
|
|
30
31
|
* LTI update could not be added via codemod */
|
|
@@ -33,7 +34,7 @@ function getPropertyType(
|
|
|
33
34
|
typeAnnotation,
|
|
34
35
|
parser,
|
|
35
36
|
) {
|
|
36
|
-
const type =
|
|
37
|
+
const type = extractTypeFromTypeAnnotation(typeAnnotation, parser);
|
|
37
38
|
switch (type) {
|
|
38
39
|
case 'BooleanTypeAnnotation':
|
|
39
40
|
return emitBoolProp(name, optional);
|
|
@@ -61,16 +62,7 @@ function getPropertyType(
|
|
|
61
62
|
extractArrayElementType,
|
|
62
63
|
);
|
|
63
64
|
case 'UnionTypeAnnotation':
|
|
64
|
-
return
|
|
65
|
-
name,
|
|
66
|
-
optional,
|
|
67
|
-
typeAnnotation: {
|
|
68
|
-
type: 'StringEnumTypeAnnotation',
|
|
69
|
-
options: typeAnnotation.types.map(option =>
|
|
70
|
-
parser.getLiteralValue(option),
|
|
71
|
-
),
|
|
72
|
-
},
|
|
73
|
-
};
|
|
65
|
+
return emitUnionProp(name, optional, parser, typeAnnotation);
|
|
74
66
|
case 'UnsafeMixed':
|
|
75
67
|
return emitMixedProp(name, optional);
|
|
76
68
|
case 'ArrayTypeAnnotation':
|
|
@@ -85,7 +77,7 @@ function getPropertyType(
|
|
|
85
77
|
}
|
|
86
78
|
}
|
|
87
79
|
function extractArrayElementType(typeAnnotation, name, parser) {
|
|
88
|
-
const type =
|
|
80
|
+
const type = extractTypeFromTypeAnnotation(typeAnnotation, parser);
|
|
89
81
|
switch (type) {
|
|
90
82
|
case 'BooleanTypeAnnotation':
|
|
91
83
|
return {
|
|
@@ -161,6 +153,11 @@ function extractArrayElementType(typeAnnotation, name, parser) {
|
|
|
161
153
|
function prettify(jsonObject) {
|
|
162
154
|
return JSON.stringify(jsonObject, null, 2);
|
|
163
155
|
}
|
|
156
|
+
function extractTypeFromTypeAnnotation(typeAnnotation, parser) {
|
|
157
|
+
return typeAnnotation.type === 'GenericTypeAnnotation'
|
|
158
|
+
? parser.getTypeAnnotationName(typeAnnotation)
|
|
159
|
+
: typeAnnotation.type;
|
|
160
|
+
}
|
|
164
161
|
function findEventArgumentsAndType(
|
|
165
162
|
parser,
|
|
166
163
|
typeAnnotation,
|
|
@@ -169,7 +166,7 @@ function findEventArgumentsAndType(
|
|
|
169
166
|
paperName,
|
|
170
167
|
) {
|
|
171
168
|
throwIfEventHasNoName(typeAnnotation, parser);
|
|
172
|
-
const name = typeAnnotation
|
|
169
|
+
const name = parser.getTypeAnnotationName(typeAnnotation);
|
|
173
170
|
if (name === '$ReadOnly') {
|
|
174
171
|
return {
|
|
175
172
|
argumentProps: typeAnnotation.typeParameters.params[0].properties,
|
|
@@ -223,8 +220,8 @@ function buildEventSchema(types, property, parser) {
|
|
|
223
220
|
: property.value;
|
|
224
221
|
if (
|
|
225
222
|
typeAnnotation.type !== 'GenericTypeAnnotation' ||
|
|
226
|
-
(typeAnnotation
|
|
227
|
-
typeAnnotation
|
|
223
|
+
(parser.getTypeAnnotationName(typeAnnotation) !== 'BubblingEventHandler' &&
|
|
224
|
+
parser.getTypeAnnotationName(typeAnnotation) !== 'DirectEventHandler')
|
|
228
225
|
) {
|
|
229
226
|
return null;
|
|
230
227
|
}
|
|
@@ -34,6 +34,7 @@ const {
|
|
|
34
34
|
emitStringProp,
|
|
35
35
|
emitInt32Prop,
|
|
36
36
|
emitObjectProp,
|
|
37
|
+
emitUnionProp,
|
|
37
38
|
} = require('../../parsers-primitives');
|
|
38
39
|
|
|
39
40
|
function getPropertyType(
|
|
@@ -44,7 +45,7 @@ function getPropertyType(
|
|
|
44
45
|
typeAnnotation: $FlowFixMe,
|
|
45
46
|
parser: Parser,
|
|
46
47
|
): NamedShape<EventTypeAnnotation> {
|
|
47
|
-
const type =
|
|
48
|
+
const type = extractTypeFromTypeAnnotation(typeAnnotation, parser);
|
|
48
49
|
|
|
49
50
|
switch (type) {
|
|
50
51
|
case 'BooleanTypeAnnotation':
|
|
@@ -73,16 +74,7 @@ function getPropertyType(
|
|
|
73
74
|
extractArrayElementType,
|
|
74
75
|
);
|
|
75
76
|
case 'UnionTypeAnnotation':
|
|
76
|
-
return
|
|
77
|
-
name,
|
|
78
|
-
optional,
|
|
79
|
-
typeAnnotation: {
|
|
80
|
-
type: 'StringEnumTypeAnnotation',
|
|
81
|
-
options: typeAnnotation.types.map(option =>
|
|
82
|
-
parser.getLiteralValue(option),
|
|
83
|
-
),
|
|
84
|
-
},
|
|
85
|
-
};
|
|
77
|
+
return emitUnionProp(name, optional, parser, typeAnnotation);
|
|
86
78
|
case 'UnsafeMixed':
|
|
87
79
|
return emitMixedProp(name, optional);
|
|
88
80
|
case 'ArrayTypeAnnotation':
|
|
@@ -102,7 +94,7 @@ function extractArrayElementType(
|
|
|
102
94
|
name: string,
|
|
103
95
|
parser: Parser,
|
|
104
96
|
): EventTypeAnnotation {
|
|
105
|
-
const type =
|
|
97
|
+
const type = extractTypeFromTypeAnnotation(typeAnnotation, parser);
|
|
106
98
|
|
|
107
99
|
switch (type) {
|
|
108
100
|
case 'BooleanTypeAnnotation':
|
|
@@ -171,6 +163,15 @@ function prettify(jsonObject: $FlowFixMe): string {
|
|
|
171
163
|
return JSON.stringify(jsonObject, null, 2);
|
|
172
164
|
}
|
|
173
165
|
|
|
166
|
+
function extractTypeFromTypeAnnotation(
|
|
167
|
+
typeAnnotation: $FlowFixMe,
|
|
168
|
+
parser: Parser,
|
|
169
|
+
): string {
|
|
170
|
+
return typeAnnotation.type === 'GenericTypeAnnotation'
|
|
171
|
+
? parser.getTypeAnnotationName(typeAnnotation)
|
|
172
|
+
: typeAnnotation.type;
|
|
173
|
+
}
|
|
174
|
+
|
|
174
175
|
function findEventArgumentsAndType(
|
|
175
176
|
parser: Parser,
|
|
176
177
|
typeAnnotation: $FlowFixMe,
|
|
@@ -183,7 +184,7 @@ function findEventArgumentsAndType(
|
|
|
183
184
|
paperTopLevelNameDeprecated: ?$FlowFixMe,
|
|
184
185
|
} {
|
|
185
186
|
throwIfEventHasNoName(typeAnnotation, parser);
|
|
186
|
-
const name = typeAnnotation
|
|
187
|
+
const name = parser.getTypeAnnotationName(typeAnnotation);
|
|
187
188
|
if (name === '$ReadOnly') {
|
|
188
189
|
return {
|
|
189
190
|
argumentProps: typeAnnotation.typeParameters.params[0].properties,
|
|
@@ -244,8 +245,8 @@ function buildEventSchema(
|
|
|
244
245
|
|
|
245
246
|
if (
|
|
246
247
|
typeAnnotation.type !== 'GenericTypeAnnotation' ||
|
|
247
|
-
(typeAnnotation
|
|
248
|
-
typeAnnotation
|
|
248
|
+
(parser.getTypeAnnotationName(typeAnnotation) !== 'BubblingEventHandler' &&
|
|
249
|
+
parser.getTypeAnnotationName(typeAnnotation) !== 'DirectEventHandler')
|
|
249
250
|
) {
|
|
250
251
|
return null;
|
|
251
252
|
}
|
|
@@ -122,7 +122,7 @@ function translateTypeAnnotation(
|
|
|
122
122
|
typeResolutionStatus = _resolveTypeAnnotatio.typeResolutionStatus;
|
|
123
123
|
switch (typeAnnotation.type) {
|
|
124
124
|
case 'GenericTypeAnnotation': {
|
|
125
|
-
switch (typeAnnotation
|
|
125
|
+
switch (parser.getTypeAnnotationName(typeAnnotation)) {
|
|
126
126
|
case 'RootTag': {
|
|
127
127
|
return emitRootTag(nullable);
|
|
128
128
|
}
|
|
@@ -64,7 +64,7 @@ function translateTypeAnnotation(
|
|
|
64
64
|
|
|
65
65
|
switch (typeAnnotation.type) {
|
|
66
66
|
case 'GenericTypeAnnotation': {
|
|
67
|
-
switch (typeAnnotation
|
|
67
|
+
switch (parser.getTypeAnnotationName(typeAnnotation)) {
|
|
68
68
|
case 'RootTag': {
|
|
69
69
|
return emitRootTag(nullable);
|
|
70
70
|
}
|
|
@@ -101,7 +101,7 @@ class FlowParser {
|
|
|
101
101
|
language() {
|
|
102
102
|
return 'Flow';
|
|
103
103
|
}
|
|
104
|
-
|
|
104
|
+
getTypeAnnotationName(typeAnnotation) {
|
|
105
105
|
var _typeAnnotation$id;
|
|
106
106
|
return typeAnnotation === null || typeAnnotation === void 0
|
|
107
107
|
? void 0
|
|
@@ -372,7 +372,7 @@ class FlowParser {
|
|
|
372
372
|
if (node.type !== 'GenericTypeAnnotation') {
|
|
373
373
|
break;
|
|
374
374
|
}
|
|
375
|
-
const typeAnnotationName = this.
|
|
375
|
+
const typeAnnotationName = this.getTypeAnnotationName(node);
|
|
376
376
|
const resolvedTypeAnnotation = types[typeAnnotationName];
|
|
377
377
|
if (resolvedTypeAnnotation == null) {
|
|
378
378
|
break;
|
|
@@ -99,7 +99,7 @@ class FlowParser implements Parser {
|
|
|
99
99
|
return 'Flow';
|
|
100
100
|
}
|
|
101
101
|
|
|
102
|
-
|
|
102
|
+
getTypeAnnotationName(typeAnnotation: $FlowFixMe): string {
|
|
103
103
|
return typeAnnotation?.id?.name;
|
|
104
104
|
}
|
|
105
105
|
|
|
@@ -421,7 +421,7 @@ class FlowParser implements Parser {
|
|
|
421
421
|
break;
|
|
422
422
|
}
|
|
423
423
|
|
|
424
|
-
const typeAnnotationName = this.
|
|
424
|
+
const typeAnnotationName = this.getTypeAnnotationName(node);
|
|
425
425
|
const resolvedTypeAnnotation = types[typeAnnotationName];
|
|
426
426
|
if (resolvedTypeAnnotation == null) {
|
|
427
427
|
break;
|
|
@@ -127,11 +127,11 @@ export interface Parser {
|
|
|
127
127
|
*/
|
|
128
128
|
language(): ParserType;
|
|
129
129
|
/**
|
|
130
|
-
* Given a type annotation
|
|
130
|
+
* Given a type annotation, it returns the type name.
|
|
131
131
|
* @parameter typeAnnotation: the annotation for a type in the AST.
|
|
132
132
|
* @returns: the name of the type.
|
|
133
133
|
*/
|
|
134
|
-
|
|
134
|
+
getTypeAnnotationName(typeAnnotation: $FlowFixMe): string;
|
|
135
135
|
/**
|
|
136
136
|
* Given a type arguments, it returns a boolean specifying if the Module is Invalid.
|
|
137
137
|
* @parameter typeArguments: the type arguments.
|
|
@@ -102,8 +102,14 @@ export class MockedParser {
|
|
|
102
102
|
language() {
|
|
103
103
|
return 'Flow';
|
|
104
104
|
}
|
|
105
|
-
|
|
106
|
-
|
|
105
|
+
getTypeAnnotationName(typeAnnotation) {
|
|
106
|
+
var _typeAnnotation$id;
|
|
107
|
+
return typeAnnotation === null || typeAnnotation === void 0
|
|
108
|
+
? void 0
|
|
109
|
+
: (_typeAnnotation$id = typeAnnotation.id) === null ||
|
|
110
|
+
_typeAnnotation$id === void 0
|
|
111
|
+
? void 0
|
|
112
|
+
: _typeAnnotation$id.name;
|
|
107
113
|
}
|
|
108
114
|
checkIfInvalidModule(typeArguments) {
|
|
109
115
|
return false;
|
|
@@ -96,8 +96,8 @@ export class MockedParser implements Parser {
|
|
|
96
96
|
return 'Flow';
|
|
97
97
|
}
|
|
98
98
|
|
|
99
|
-
|
|
100
|
-
return typeAnnotation
|
|
99
|
+
getTypeAnnotationName(typeAnnotation: $FlowFixMe): string {
|
|
100
|
+
return typeAnnotation?.id?.name;
|
|
101
101
|
}
|
|
102
102
|
|
|
103
103
|
checkIfInvalidModule(typeArguments: $FlowFixMe): boolean {
|
|
@@ -811,7 +811,7 @@ function getCommandTypeNameAndOptionsExpression(namedExport, parser) {
|
|
|
811
811
|
);
|
|
812
812
|
}
|
|
813
813
|
return {
|
|
814
|
-
commandTypeName: parser.
|
|
814
|
+
commandTypeName: parser.getTypeAnnotationName(typeArgumentParam),
|
|
815
815
|
commandOptionsExpression: callExpression.arguments[0],
|
|
816
816
|
};
|
|
817
817
|
}
|
|
@@ -944,7 +944,7 @@ function getTypeResolutionStatus(type, typeAnnotation, parser) {
|
|
|
944
944
|
return {
|
|
945
945
|
successful: true,
|
|
946
946
|
type,
|
|
947
|
-
name: parser.
|
|
947
|
+
name: parser.getTypeAnnotationName(typeAnnotation),
|
|
948
948
|
};
|
|
949
949
|
}
|
|
950
950
|
function handleGenericTypeAnnotation(
|
|
@@ -818,7 +818,7 @@ function getCommandTypeNameAndOptionsExpression(
|
|
|
818
818
|
}
|
|
819
819
|
|
|
820
820
|
return {
|
|
821
|
-
commandTypeName: parser.
|
|
821
|
+
commandTypeName: parser.getTypeAnnotationName(typeArgumentParam),
|
|
822
822
|
commandOptionsExpression: callExpression.arguments[0],
|
|
823
823
|
};
|
|
824
824
|
}
|
|
@@ -998,7 +998,7 @@ function getTypeResolutionStatus(
|
|
|
998
998
|
return {
|
|
999
999
|
successful: true,
|
|
1000
1000
|
type,
|
|
1001
|
-
name: parser.
|
|
1001
|
+
name: parser.getTypeAnnotationName(typeAnnotation),
|
|
1002
1002
|
};
|
|
1003
1003
|
}
|
|
1004
1004
|
|
|
@@ -567,7 +567,7 @@ function emitCommonTypes(
|
|
|
567
567
|
return simpleEmitter(nullable);
|
|
568
568
|
}
|
|
569
569
|
const genericTypeAnnotationName =
|
|
570
|
-
parser.
|
|
570
|
+
parser.getTypeAnnotationName(typeAnnotation);
|
|
571
571
|
const emitter = typeMap[genericTypeAnnotationName];
|
|
572
572
|
if (!emitter) {
|
|
573
573
|
return null;
|
|
@@ -615,6 +615,18 @@ function emitObjectProp(
|
|
|
615
615
|
typeAnnotation: extractArrayElementType(typeAnnotation, name, parser),
|
|
616
616
|
};
|
|
617
617
|
}
|
|
618
|
+
function emitUnionProp(name, optional, parser, typeAnnotation) {
|
|
619
|
+
return {
|
|
620
|
+
name,
|
|
621
|
+
optional,
|
|
622
|
+
typeAnnotation: {
|
|
623
|
+
type: 'StringEnumTypeAnnotation',
|
|
624
|
+
options: typeAnnotation.types.map(option =>
|
|
625
|
+
parser.getLiteralValue(option),
|
|
626
|
+
),
|
|
627
|
+
},
|
|
628
|
+
};
|
|
629
|
+
}
|
|
618
630
|
module.exports = {
|
|
619
631
|
emitArrayType,
|
|
620
632
|
emitBoolean,
|
|
@@ -646,4 +658,5 @@ module.exports = {
|
|
|
646
658
|
translateArrayTypeAnnotation,
|
|
647
659
|
Visitor,
|
|
648
660
|
emitObjectProp,
|
|
661
|
+
emitUnionProp,
|
|
649
662
|
};
|
|
@@ -611,7 +611,7 @@ function emitCommonTypes(
|
|
|
611
611
|
}
|
|
612
612
|
|
|
613
613
|
const genericTypeAnnotationName =
|
|
614
|
-
parser.
|
|
614
|
+
parser.getTypeAnnotationName(typeAnnotation);
|
|
615
615
|
|
|
616
616
|
const emitter = typeMap[genericTypeAnnotationName];
|
|
617
617
|
if (!emitter) {
|
|
@@ -675,6 +675,24 @@ function emitObjectProp(
|
|
|
675
675
|
};
|
|
676
676
|
}
|
|
677
677
|
|
|
678
|
+
function emitUnionProp(
|
|
679
|
+
name: string,
|
|
680
|
+
optional: boolean,
|
|
681
|
+
parser: Parser,
|
|
682
|
+
typeAnnotation: $FlowFixMe,
|
|
683
|
+
): NamedShape<EventTypeAnnotation> {
|
|
684
|
+
return {
|
|
685
|
+
name,
|
|
686
|
+
optional,
|
|
687
|
+
typeAnnotation: {
|
|
688
|
+
type: 'StringEnumTypeAnnotation',
|
|
689
|
+
options: typeAnnotation.types.map(option =>
|
|
690
|
+
parser.getLiteralValue(option),
|
|
691
|
+
),
|
|
692
|
+
},
|
|
693
|
+
};
|
|
694
|
+
}
|
|
695
|
+
|
|
678
696
|
module.exports = {
|
|
679
697
|
emitArrayType,
|
|
680
698
|
emitBoolean,
|
|
@@ -706,4 +724,5 @@ module.exports = {
|
|
|
706
724
|
translateArrayTypeAnnotation,
|
|
707
725
|
Visitor,
|
|
708
726
|
emitObjectProp,
|
|
727
|
+
emitUnionProp,
|
|
709
728
|
};
|
|
@@ -120,8 +120,8 @@ function detectArrayType(
|
|
|
120
120
|
// Covers: Array<T> and ReadonlyArray<T>
|
|
121
121
|
if (
|
|
122
122
|
typeAnnotation.type === 'TSTypeReference' &&
|
|
123
|
-
(typeAnnotation
|
|
124
|
-
typeAnnotation
|
|
123
|
+
(parser.getTypeAnnotationName(typeAnnotation) === 'ReadonlyArray' ||
|
|
124
|
+
parser.getTypeAnnotationName(typeAnnotation) === 'Array')
|
|
125
125
|
) {
|
|
126
126
|
return {
|
|
127
127
|
type: 'ArrayTypeAnnotation',
|
|
@@ -360,7 +360,7 @@ function getTypeAnnotation(
|
|
|
360
360
|
const type =
|
|
361
361
|
typeAnnotation.type === 'TSTypeReference' ||
|
|
362
362
|
typeAnnotation.type === 'TSTypeAliasDeclaration'
|
|
363
|
-
? typeAnnotation
|
|
363
|
+
? parser.getTypeAnnotationName(typeAnnotation)
|
|
364
364
|
: typeAnnotation.type;
|
|
365
365
|
const common = getCommonTypeAnnotation(
|
|
366
366
|
name,
|
|
@@ -394,7 +394,6 @@ function getTypeAnnotation(
|
|
|
394
394
|
`Cannot use "${type}" type annotation for "${name}": must use a specific function type like BubblingEventHandler, or DirectEventHandler`,
|
|
395
395
|
);
|
|
396
396
|
default:
|
|
397
|
-
type;
|
|
398
397
|
throw new Error(`Unknown prop type for "${name}": "${type}"`);
|
|
399
398
|
}
|
|
400
399
|
}
|
|
@@ -121,8 +121,8 @@ function detectArrayType<T>(
|
|
|
121
121
|
// Covers: Array<T> and ReadonlyArray<T>
|
|
122
122
|
if (
|
|
123
123
|
typeAnnotation.type === 'TSTypeReference' &&
|
|
124
|
-
(typeAnnotation
|
|
125
|
-
typeAnnotation
|
|
124
|
+
(parser.getTypeAnnotationName(typeAnnotation) === 'ReadonlyArray' ||
|
|
125
|
+
parser.getTypeAnnotationName(typeAnnotation) === 'Array')
|
|
126
126
|
) {
|
|
127
127
|
return {
|
|
128
128
|
type: 'ArrayTypeAnnotation',
|
|
@@ -378,7 +378,7 @@ function getTypeAnnotation<T>(
|
|
|
378
378
|
const type =
|
|
379
379
|
typeAnnotation.type === 'TSTypeReference' ||
|
|
380
380
|
typeAnnotation.type === 'TSTypeAliasDeclaration'
|
|
381
|
-
? typeAnnotation
|
|
381
|
+
? parser.getTypeAnnotationName(typeAnnotation)
|
|
382
382
|
: typeAnnotation.type;
|
|
383
383
|
|
|
384
384
|
const common = getCommonTypeAnnotation(
|
|
@@ -414,7 +414,6 @@ function getTypeAnnotation<T>(
|
|
|
414
414
|
`Cannot use "${type}" type annotation for "${name}": must use a specific function type like BubblingEventHandler, or DirectEventHandler`,
|
|
415
415
|
);
|
|
416
416
|
default:
|
|
417
|
-
(type: empty);
|
|
418
417
|
throw new Error(`Unknown prop type for "${name}": "${type}"`);
|
|
419
418
|
}
|
|
420
419
|
}
|
|
@@ -28,7 +28,8 @@ const _require5 = require('../../parsers-primitives'),
|
|
|
28
28
|
emitMixedProp = _require5.emitMixedProp,
|
|
29
29
|
emitStringProp = _require5.emitStringProp,
|
|
30
30
|
emitInt32Prop = _require5.emitInt32Prop,
|
|
31
|
-
emitObjectProp = _require5.emitObjectProp
|
|
31
|
+
emitObjectProp = _require5.emitObjectProp,
|
|
32
|
+
emitUnionProp = _require5.emitUnionProp;
|
|
32
33
|
function getPropertyType(
|
|
33
34
|
/* $FlowFixMe[missing-local-annot] The type annotation(s) required by Flow's
|
|
34
35
|
* LTI update could not be added via codemod */
|
|
@@ -42,7 +43,10 @@ function getPropertyType(
|
|
|
42
43
|
const topLevelType = parseTopLevelType(annotation);
|
|
43
44
|
const typeAnnotation = topLevelType.type;
|
|
44
45
|
const optional = optionalProperty || topLevelType.optional;
|
|
45
|
-
const type =
|
|
46
|
+
const type =
|
|
47
|
+
typeAnnotation.type === 'TSTypeReference'
|
|
48
|
+
? parser.getTypeAnnotationName(typeAnnotation)
|
|
49
|
+
: typeAnnotation.type;
|
|
46
50
|
switch (type) {
|
|
47
51
|
case 'TSBooleanKeyword':
|
|
48
52
|
return emitBoolProp(name, optional);
|
|
@@ -63,16 +67,7 @@ function getPropertyType(
|
|
|
63
67
|
extractArrayElementType,
|
|
64
68
|
);
|
|
65
69
|
case 'TSUnionType':
|
|
66
|
-
return
|
|
67
|
-
name,
|
|
68
|
-
optional,
|
|
69
|
-
typeAnnotation: {
|
|
70
|
-
type: 'StringEnumTypeAnnotation',
|
|
71
|
-
options: typeAnnotation.types.map(option =>
|
|
72
|
-
parser.getLiteralValue(option),
|
|
73
|
-
),
|
|
74
|
-
},
|
|
75
|
-
};
|
|
70
|
+
return emitUnionProp(name, optional, parser, typeAnnotation);
|
|
76
71
|
case 'UnsafeMixed':
|
|
77
72
|
return emitMixedProp(name, optional);
|
|
78
73
|
case 'TSArrayType':
|
|
@@ -86,7 +81,7 @@ function getPropertyType(
|
|
|
86
81
|
}
|
|
87
82
|
}
|
|
88
83
|
function extractArrayElementType(typeAnnotation, name, parser) {
|
|
89
|
-
const type =
|
|
84
|
+
const type = extractTypeFromTypeAnnotation(typeAnnotation, parser);
|
|
90
85
|
switch (type) {
|
|
91
86
|
case 'TSParenthesizedType':
|
|
92
87
|
return extractArrayElementType(
|
|
@@ -150,6 +145,11 @@ function extractArrayElementType(typeAnnotation, name, parser) {
|
|
|
150
145
|
);
|
|
151
146
|
}
|
|
152
147
|
}
|
|
148
|
+
function extractTypeFromTypeAnnotation(typeAnnotation, parser) {
|
|
149
|
+
return typeAnnotation.type === 'TSTypeReference'
|
|
150
|
+
? parser.getTypeAnnotationName(typeAnnotation)
|
|
151
|
+
: typeAnnotation.type;
|
|
152
|
+
}
|
|
153
153
|
function findEventArgumentsAndType(
|
|
154
154
|
parser,
|
|
155
155
|
typeAnnotation,
|
|
@@ -172,7 +172,7 @@ function findEventArgumentsAndType(
|
|
|
172
172
|
};
|
|
173
173
|
}
|
|
174
174
|
throwIfEventHasNoName(typeAnnotation, parser);
|
|
175
|
-
const name = typeAnnotation
|
|
175
|
+
const name = parser.getTypeAnnotationName(typeAnnotation);
|
|
176
176
|
if (name === 'Readonly') {
|
|
177
177
|
return findEventArgumentsAndType(
|
|
178
178
|
parser,
|
|
@@ -36,6 +36,7 @@ const {
|
|
|
36
36
|
emitStringProp,
|
|
37
37
|
emitInt32Prop,
|
|
38
38
|
emitObjectProp,
|
|
39
|
+
emitUnionProp,
|
|
39
40
|
} = require('../../parsers-primitives');
|
|
40
41
|
function getPropertyType(
|
|
41
42
|
/* $FlowFixMe[missing-local-annot] The type annotation(s) required by Flow's
|
|
@@ -50,7 +51,10 @@ function getPropertyType(
|
|
|
50
51
|
const topLevelType = parseTopLevelType(annotation);
|
|
51
52
|
const typeAnnotation = topLevelType.type;
|
|
52
53
|
const optional = optionalProperty || topLevelType.optional;
|
|
53
|
-
const type =
|
|
54
|
+
const type =
|
|
55
|
+
typeAnnotation.type === 'TSTypeReference'
|
|
56
|
+
? parser.getTypeAnnotationName(typeAnnotation)
|
|
57
|
+
: typeAnnotation.type;
|
|
54
58
|
|
|
55
59
|
switch (type) {
|
|
56
60
|
case 'TSBooleanKeyword':
|
|
@@ -72,16 +76,7 @@ function getPropertyType(
|
|
|
72
76
|
extractArrayElementType,
|
|
73
77
|
);
|
|
74
78
|
case 'TSUnionType':
|
|
75
|
-
return
|
|
76
|
-
name,
|
|
77
|
-
optional,
|
|
78
|
-
typeAnnotation: {
|
|
79
|
-
type: 'StringEnumTypeAnnotation',
|
|
80
|
-
options: typeAnnotation.types.map(option =>
|
|
81
|
-
parser.getLiteralValue(option),
|
|
82
|
-
),
|
|
83
|
-
},
|
|
84
|
-
};
|
|
79
|
+
return emitUnionProp(name, optional, parser, typeAnnotation);
|
|
85
80
|
case 'UnsafeMixed':
|
|
86
81
|
return emitMixedProp(name, optional);
|
|
87
82
|
case 'TSArrayType':
|
|
@@ -100,7 +95,7 @@ function extractArrayElementType(
|
|
|
100
95
|
name: string,
|
|
101
96
|
parser: Parser,
|
|
102
97
|
): EventTypeAnnotation {
|
|
103
|
-
const type =
|
|
98
|
+
const type = extractTypeFromTypeAnnotation(typeAnnotation, parser);
|
|
104
99
|
|
|
105
100
|
switch (type) {
|
|
106
101
|
case 'TSParenthesizedType':
|
|
@@ -162,6 +157,15 @@ function extractArrayElementType(
|
|
|
162
157
|
}
|
|
163
158
|
}
|
|
164
159
|
|
|
160
|
+
function extractTypeFromTypeAnnotation(
|
|
161
|
+
typeAnnotation: $FlowFixMe,
|
|
162
|
+
parser: Parser,
|
|
163
|
+
): string {
|
|
164
|
+
return typeAnnotation.type === 'TSTypeReference'
|
|
165
|
+
? parser.getTypeAnnotationName(typeAnnotation)
|
|
166
|
+
: typeAnnotation.type;
|
|
167
|
+
}
|
|
168
|
+
|
|
165
169
|
function findEventArgumentsAndType(
|
|
166
170
|
parser: Parser,
|
|
167
171
|
typeAnnotation: $FlowFixMe,
|
|
@@ -190,7 +194,7 @@ function findEventArgumentsAndType(
|
|
|
190
194
|
}
|
|
191
195
|
|
|
192
196
|
throwIfEventHasNoName(typeAnnotation, parser);
|
|
193
|
-
const name = typeAnnotation
|
|
197
|
+
const name = parser.getTypeAnnotationName(typeAnnotation);
|
|
194
198
|
if (name === 'Readonly') {
|
|
195
199
|
return findEventArgumentsAndType(
|
|
196
200
|
parser,
|
|
@@ -218,7 +218,7 @@ function translateTypeAnnotation(
|
|
|
218
218
|
}
|
|
219
219
|
case 'TSTypeReference': {
|
|
220
220
|
return translateTypeReferenceAnnotation(
|
|
221
|
-
typeAnnotation
|
|
221
|
+
parser.getTypeAnnotationName(typeAnnotation),
|
|
222
222
|
nullable,
|
|
223
223
|
typeAnnotation,
|
|
224
224
|
hasteModuleName,
|
|
@@ -234,7 +234,7 @@ function translateTypeAnnotation(
|
|
|
234
234
|
}
|
|
235
235
|
case 'TSTypeReference': {
|
|
236
236
|
return translateTypeReferenceAnnotation(
|
|
237
|
-
typeAnnotation
|
|
237
|
+
parser.getTypeAnnotationName(typeAnnotation),
|
|
238
238
|
nullable,
|
|
239
239
|
typeAnnotation,
|
|
240
240
|
hasteModuleName,
|
|
@@ -101,7 +101,7 @@ class TypeScriptParser {
|
|
|
101
101
|
language() {
|
|
102
102
|
return 'TypeScript';
|
|
103
103
|
}
|
|
104
|
-
|
|
104
|
+
getTypeAnnotationName(typeAnnotation) {
|
|
105
105
|
var _typeAnnotation$typeN;
|
|
106
106
|
return typeAnnotation === null || typeAnnotation === void 0
|
|
107
107
|
? void 0
|
|
@@ -391,7 +391,7 @@ class TypeScriptParser {
|
|
|
391
391
|
if (node.type !== 'TSTypeReference') {
|
|
392
392
|
break;
|
|
393
393
|
}
|
|
394
|
-
const typeAnnotationName = this.
|
|
394
|
+
const typeAnnotationName = this.getTypeAnnotationName(node);
|
|
395
395
|
const resolvedTypeAnnotation = types[typeAnnotationName];
|
|
396
396
|
if (resolvedTypeAnnotation == null) {
|
|
397
397
|
break;
|
|
@@ -422,7 +422,7 @@ class TypeScriptParser {
|
|
|
422
422
|
return false;
|
|
423
423
|
}
|
|
424
424
|
const eventNames = new Set(['BubblingEventHandler', 'DirectEventHandler']);
|
|
425
|
-
return eventNames.has(typeAnnotation
|
|
425
|
+
return eventNames.has(this.getTypeAnnotationName(typeAnnotation));
|
|
426
426
|
}
|
|
427
427
|
isProp(name, typeAnnotation) {
|
|
428
428
|
if (typeAnnotation.type !== 'TSTypeReference') {
|
|
@@ -431,7 +431,7 @@ class TypeScriptParser {
|
|
|
431
431
|
const isStyle =
|
|
432
432
|
name === 'style' &&
|
|
433
433
|
typeAnnotation.type === 'GenericTypeAnnotation' &&
|
|
434
|
-
typeAnnotation
|
|
434
|
+
this.getTypeAnnotationName(typeAnnotation) === 'ViewStyleProp';
|
|
435
435
|
return !isStyle;
|
|
436
436
|
}
|
|
437
437
|
getProps(typeDefinition, types) {
|
|
@@ -94,7 +94,7 @@ class TypeScriptParser implements Parser {
|
|
|
94
94
|
return 'TypeScript';
|
|
95
95
|
}
|
|
96
96
|
|
|
97
|
-
|
|
97
|
+
getTypeAnnotationName(typeAnnotation: $FlowFixMe): string {
|
|
98
98
|
return typeAnnotation?.typeName?.name;
|
|
99
99
|
}
|
|
100
100
|
|
|
@@ -413,7 +413,7 @@ class TypeScriptParser implements Parser {
|
|
|
413
413
|
break;
|
|
414
414
|
}
|
|
415
415
|
|
|
416
|
-
const typeAnnotationName = this.
|
|
416
|
+
const typeAnnotationName = this.getTypeAnnotationName(node);
|
|
417
417
|
const resolvedTypeAnnotation = types[typeAnnotationName];
|
|
418
418
|
if (resolvedTypeAnnotation == null) {
|
|
419
419
|
break;
|
|
@@ -447,7 +447,7 @@ class TypeScriptParser implements Parser {
|
|
|
447
447
|
return false;
|
|
448
448
|
}
|
|
449
449
|
const eventNames = new Set(['BubblingEventHandler', 'DirectEventHandler']);
|
|
450
|
-
return eventNames.has(typeAnnotation
|
|
450
|
+
return eventNames.has(this.getTypeAnnotationName(typeAnnotation));
|
|
451
451
|
}
|
|
452
452
|
|
|
453
453
|
isProp(name: string, typeAnnotation: $FlowFixMe): boolean {
|
|
@@ -457,7 +457,7 @@ class TypeScriptParser implements Parser {
|
|
|
457
457
|
const isStyle =
|
|
458
458
|
name === 'style' &&
|
|
459
459
|
typeAnnotation.type === 'GenericTypeAnnotation' &&
|
|
460
|
-
typeAnnotation
|
|
460
|
+
this.getTypeAnnotationName(typeAnnotation) === 'ViewStyleProp';
|
|
461
461
|
return !isStyle;
|
|
462
462
|
}
|
|
463
463
|
|