Skip to content

Commit 3ab7ef2

Browse files
Antoine Doubovetzkyfacebook-github-bot
authored andcommitted
extract emitDouble from parsers modules to shared parsers-primitives (#34913)
Summary: Part of #34872 This PR extracts the content of the case 'Double' ([Flow](https://github.com/facebook/react-native/blob/b444f0e44e0d8670139acea5f14c2de32c5e2ddc/packages/react-native-codegen/src/parsers/flow/modules/index.js#L202-L204), [TypeScript](https://github.com/facebook/react-native/blob/00b795642a6562fb52d6df12e367b84674994623/packages/react-native-codegen/src/parsers/typescript/modules/index.js#L1235-L237)) into a single emitDouble function in the parsers-primitives.js file. Use the new function in the parsers. ## Changelog <!-- Help reviewers and the release process by writing your own changelog entry. For an example, see: https://reactnative.dev/contributing/changelogs-in-pull-requests --> [Internal] [Changed] - Extract contents of the case 'Double' into a single emitDouble function inside parsers-primitives Pull Request resolved: #34913 Test Plan: I tested using jest and flow commands. Reviewed By: cipolleschi Differential Revision: D40216018 Pulled By: cipolleschi fbshipit-source-id: bc2aaa7636fbd2f6c861e4d87e394d0e4875a4a5
1 parent 5f05b07 commit 3ab7ef2

File tree

4 files changed

+40
-7
lines changed

4 files changed

+40
-7
lines changed

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

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,11 @@
1313

1414
const {
1515
emitBoolean,
16+
emitDouble,
1617
emitNumber,
1718
emitInt32,
1819
emitRootTag,
19-
} = require('../parsers-primitives');
20+
} = require('../parsers-primitives.js');
2021

2122
describe('emitBoolean', () => {
2223
describe('when nullable is true', () => {
@@ -121,3 +122,29 @@ describe('emitRootTag', () => {
121122
});
122123
});
123124
});
125+
126+
describe('emitDouble', () => {
127+
describe('when nullable is true', () => {
128+
it('returns nullable type annotation', () => {
129+
const result = emitDouble(true);
130+
const expected = {
131+
type: 'NullableTypeAnnotation',
132+
typeAnnotation: {
133+
type: 'DoubleTypeAnnotation',
134+
},
135+
};
136+
137+
expect(result).toEqual(expected);
138+
});
139+
});
140+
describe('when nullable is false', () => {
141+
it('returns non nullable type annotation', () => {
142+
const result = emitDouble(false);
143+
const expected = {
144+
type: 'DoubleTypeAnnotation',
145+
};
146+
147+
expect(result).toEqual(expected);
148+
});
149+
});
150+
});

packages/react-native-codegen/src/parsers/flow/modules/index.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ const {
3535
const {unwrapNullable, wrapNullable} = require('../../parsers-commons');
3636
const {
3737
emitBoolean,
38+
emitDouble,
3839
emitNumber,
3940
emitInt32,
4041
emitRootTag,
@@ -204,9 +205,7 @@ function translateTypeAnnotation(
204205
return emitInt32(nullable);
205206
}
206207
case 'Double': {
207-
return wrapNullable(nullable, {
208-
type: 'DoubleTypeAnnotation',
209-
});
208+
return emitDouble(nullable);
210209
}
211210
case 'Float': {
212211
return wrapNullable(nullable, {

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
import type {
1414
BooleanTypeAnnotation,
15+
DoubleTypeAnnotation,
1516
Int32TypeAnnotation,
1617
NativeModuleNumberTypeAnnotation,
1718
Nullable,
@@ -47,8 +48,15 @@ function emitRootTag(nullable: boolean): Nullable<ReservedTypeAnnotation> {
4748
});
4849
}
4950

51+
function emitDouble(nullable: boolean): Nullable<DoubleTypeAnnotation> {
52+
return wrapNullable(nullable, {
53+
type: 'DoubleTypeAnnotation',
54+
});
55+
}
56+
5057
module.exports = {
5158
emitBoolean,
59+
emitDouble,
5260
emitInt32,
5361
emitNumber,
5462
emitRootTag,

packages/react-native-codegen/src/parsers/typescript/modules/index.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ const {
3535
const {unwrapNullable, wrapNullable} = require('../../parsers-commons');
3636
const {
3737
emitBoolean,
38+
emitDouble,
3839
emitNumber,
3940
emitInt32,
4041
emitRootTag,
@@ -238,9 +239,7 @@ function translateTypeAnnotation(
238239
return emitInt32(nullable);
239240
}
240241
case 'Double': {
241-
return wrapNullable(nullable, {
242-
type: 'DoubleTypeAnnotation',
243-
});
242+
return emitDouble(nullable);
244243
}
245244
case 'Float': {
246245
return wrapNullable(nullable, {

0 commit comments

Comments
 (0)