Skip to content

Commit 8ca085c

Browse files
rota-rossifacebook-github-bot
authored andcommitted
Create a function emitDoubleProp (#37515)
Summary: > Create a function emitDoubleProp(name: string, optional: boolean) in parser-primitives.js. Factor out the code from [Flow](https://github.com/facebook/react-native/blob/d8ced6f8953cd896471983714e722caf50783960/packages/react-native-codegen/src/parsers/flow/components/events.js#L61-L67) and [TypeScript](https://github.com/facebook/react-native/blob/d8ced6f8953cd896471983714e722caf50783960/packages/react-native-codegen/src/parsers/typescript/components/events.js#L71-L77) into that function. Use that function in the original call site. bypass-github-export-checks ## Changelog: [INTERNAL][ADDED] - emitDoubleProp in parser primitves Pull Request resolved: #37515 Test Plan: yarn jest packages/react-native-codegen Reviewed By: cortinico Differential Revision: D46149450 Pulled By: cipolleschi fbshipit-source-id: 78381214a79c33d975dff490599d510e8001254e
1 parent 7062398 commit 8ca085c

File tree

4 files changed

+61
-18
lines changed

4 files changed

+61
-18
lines changed

packages/react-native-codegen/src/parsers/__tests__/parsers-primitives-test.js

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,18 @@
1111

1212
'use-strict';
1313

14-
import type {UnionTypeAnnotationMemberType} from '../../CodegenSchema';
14+
import type {
15+
DoubleTypeAnnotation,
16+
NamedShape,
17+
UnionTypeAnnotationMemberType,
18+
} from '../../CodegenSchema';
1519

1620
const {
1721
emitArrayType,
1822
emitBoolean,
1923
emitBoolProp,
2024
emitDouble,
25+
emitDoubleProp,
2126
emitFloat,
2227
emitNumber,
2328
emitInt32,
@@ -262,6 +267,35 @@ describe('emitDouble', () => {
262267
});
263268
});
264269

270+
describe('emitDoubleProp', () => {
271+
describe('when optional is true', () => {
272+
it('returns optional type annotation', () => {
273+
const result = emitDoubleProp('Foo', true);
274+
const expected: NamedShape<DoubleTypeAnnotation> = {
275+
name: 'Foo',
276+
optional: true,
277+
typeAnnotation: {
278+
type: 'DoubleTypeAnnotation',
279+
},
280+
};
281+
expect(result).toEqual(expected);
282+
});
283+
});
284+
describe('when optional is false', () => {
285+
it('returns required type annotation', () => {
286+
const result = emitDoubleProp('Foo', false);
287+
const expected: NamedShape<DoubleTypeAnnotation> = {
288+
name: 'Foo',
289+
optional: false,
290+
typeAnnotation: {
291+
type: 'DoubleTypeAnnotation',
292+
},
293+
};
294+
expect(result).toEqual(expected);
295+
});
296+
});
297+
});
298+
265299
describe('emitVoid', () => {
266300
describe('when nullable is true', () => {
267301
it('returns nullable type annotation', () => {

packages/react-native-codegen/src/parsers/flow/components/events.js

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,11 @@ const {
2323
throwIfArgumentPropsAreNull,
2424
} = require('../../error-utils');
2525
const {getEventArgument} = require('../../parsers-commons');
26-
const {emitBoolProp, emitStringProp} = require('../../parsers-primitives');
26+
const {
27+
emitBoolProp,
28+
emitDoubleProp,
29+
emitStringProp,
30+
} = require('../../parsers-primitives');
2731

2832
function getPropertyType(
2933
/* $FlowFixMe[missing-local-annot] The type annotation(s) required by Flow's
@@ -49,13 +53,7 @@ function getPropertyType(
4953
},
5054
};
5155
case 'Double':
52-
return {
53-
name,
54-
optional,
55-
typeAnnotation: {
56-
type: 'DoubleTypeAnnotation',
57-
},
58-
};
56+
return emitDoubleProp(name, optional);
5957
case 'Float':
6058
return {
6159
name,

packages/react-native-codegen/src/parsers/parsers-primitives.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,19 @@ function emitDouble(nullable: boolean): Nullable<DoubleTypeAnnotation> {
9797
});
9898
}
9999

100+
function emitDoubleProp(
101+
name: string,
102+
optional: boolean,
103+
): NamedShape<DoubleTypeAnnotation> {
104+
return {
105+
name,
106+
optional,
107+
typeAnnotation: {
108+
type: 'DoubleTypeAnnotation',
109+
},
110+
};
111+
}
112+
100113
function emitVoid(nullable: boolean): Nullable<VoidTypeAnnotation> {
101114
return wrapNullable(nullable, {
102115
type: 'VoidTypeAnnotation',
@@ -610,6 +623,7 @@ module.exports = {
610623
emitBoolean,
611624
emitBoolProp,
612625
emitDouble,
626+
emitDoubleProp,
613627
emitFloat,
614628
emitFunction,
615629
emitInt32,

packages/react-native-codegen/src/parsers/typescript/components/events.js

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,11 @@ const {
2525
throwIfArgumentPropsAreNull,
2626
} = require('../../error-utils');
2727
const {getEventArgument} = require('../../parsers-commons');
28-
const {emitBoolProp, emitStringProp} = require('../../parsers-primitives');
29-
28+
const {
29+
emitBoolProp,
30+
emitDoubleProp,
31+
emitStringProp,
32+
} = require('../../parsers-primitives');
3033
function getPropertyType(
3134
/* $FlowFixMe[missing-local-annot] The type annotation(s) required by Flow's
3235
* LTI update could not be added via codemod */
@@ -59,13 +62,7 @@ function getPropertyType(
5962
},
6063
};
6164
case 'Double':
62-
return {
63-
name,
64-
optional,
65-
typeAnnotation: {
66-
type: 'DoubleTypeAnnotation',
67-
},
68-
};
65+
return emitDoubleProp(name, optional);
6966
case 'Float':
7067
return {
7168
name,

0 commit comments

Comments
 (0)