Skip to content

Commit 95e685a

Browse files
Pranav-yadavfacebook-github-bot
authored andcommitted
mv emitMixedTypeAnnotation fn > parsers-primitives.js (facebook#35185)
Summary: This PR is a task of facebook#34872 - Moved the [emitMixedTypeAnnotation](https://github.com/facebook/react-native/blob/main/packages/react-native-codegen/src/parsers/parsers-commons.js#L102) function to the [`parser-primitives.js` file](https://github.com/facebook/react-native/blob/main/packages/react-native-codegen/src/parsers/parsers-primitives.js). - Moved tests for the same respectively - Fixed/Updated imports and exports for the same respectively ## 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] - Moved the `emitMixedTypeAnnotation` function to the `parser-primitives.js` file. Pull Request resolved: facebook#35185 Test Plan: `yarn test-ci` ![image](https://user-images.githubusercontent.com/55224033/199693475-60c034bf-cd5c-4cb8-bfe8-e7c7ccbc4300.png) Reviewed By: cipolleschi Differential Revision: D40993027 Pulled By: rshest fbshipit-source-id: 5e025804f4ef6723396accf2f859483f76cb6cd6
1 parent 35ebb57 commit 95e685a

File tree

6 files changed

+40
-39
lines changed

6 files changed

+40
-39
lines changed

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

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import type {ParserType} from '../errors';
1616
const {
1717
wrapNullable,
1818
unwrapNullable,
19-
emitMixedTypeAnnotation,
2019
emitUnionTypeAnnotation,
2120
} = require('../parsers-commons.js');
2221
const {UnsupportedUnionTypeAnnotationParserError} = require('../errors');
@@ -250,32 +249,6 @@ describe('assertGenericTypeAnnotationHasExactlyOneTypeParameter', () => {
250249
});
251250
});
252251

253-
describe('emitMixedTypeAnnotation', () => {
254-
describe('when nullable is true', () => {
255-
it('returns nullable type annotation', () => {
256-
const result = emitMixedTypeAnnotation(true);
257-
const expected = {
258-
type: 'NullableTypeAnnotation',
259-
typeAnnotation: {
260-
type: 'MixedTypeAnnotation',
261-
},
262-
};
263-
264-
expect(result).toEqual(expected);
265-
});
266-
});
267-
describe('when nullable is false', () => {
268-
it('returns non nullable type annotation', () => {
269-
const result = emitMixedTypeAnnotation(false);
270-
const expected = {
271-
type: 'MixedTypeAnnotation',
272-
};
273-
274-
expect(result).toEqual(expected);
275-
});
276-
});
277-
});
278-
279252
describe('emitUnionTypeAnnotation', () => {
280253
const hasteModuleName = 'SampleTurboModule';
281254

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

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ const {
2323
emitVoid,
2424
emitString,
2525
emitStringish,
26+
emitMixedTypeAnnotation,
2627
typeAliasResolution,
2728
} = require('../parsers-primitives.js');
2829

@@ -452,3 +453,29 @@ describe('emitObject', () => {
452453
});
453454
});
454455
});
456+
457+
describe('emitMixedTypeAnnotation', () => {
458+
describe('when nullable is true', () => {
459+
it('returns nullable type annotation', () => {
460+
const result = emitMixedTypeAnnotation(true);
461+
const expected = {
462+
type: 'NullableTypeAnnotation',
463+
typeAnnotation: {
464+
type: 'MixedTypeAnnotation',
465+
},
466+
};
467+
468+
expect(result).toEqual(expected);
469+
});
470+
});
471+
describe('when nullable is false', () => {
472+
it('returns non nullable type annotation', () => {
473+
const result = emitMixedTypeAnnotation(false);
474+
const expected = {
475+
type: 'MixedTypeAnnotation',
476+
};
477+
478+
expect(result).toEqual(expected);
479+
});
480+
});
481+
});

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ const {
3333
unwrapNullable,
3434
wrapNullable,
3535
assertGenericTypeAnnotationHasExactlyOneTypeParameter,
36-
emitMixedTypeAnnotation,
3736
emitUnionTypeAnnotation,
3837
translateDefault,
3938
} = require('../../parsers-commons');
@@ -50,6 +49,7 @@ const {
5049
emitVoid,
5150
emitString,
5251
emitStringish,
52+
emitMixedTypeAnnotation,
5353
typeAliasResolution,
5454
} = require('../../parsers-primitives');
5555

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

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import type {
1515
NativeModuleSchema,
1616
NativeModuleTypeAnnotation,
1717
Nullable,
18-
NativeModuleMixedTypeAnnotation,
1918
UnionTypeAnnotationMemberType,
2019
NativeModuleUnionTypeAnnotation,
2120
} from '../CodegenSchema.js';
@@ -107,14 +106,6 @@ function assertGenericTypeAnnotationHasExactlyOneTypeParameter(
107106
}
108107
}
109108

110-
function emitMixedTypeAnnotation(
111-
nullable: boolean,
112-
): Nullable<NativeModuleMixedTypeAnnotation> {
113-
return wrapNullable(nullable, {
114-
type: 'MixedTypeAnnotation',
115-
});
116-
}
117-
118109
function remapUnionTypeAnnotationMemberNames(
119110
types: $FlowFixMe,
120111
language: ParserType,
@@ -233,7 +224,6 @@ module.exports = {
233224
unwrapNullable,
234225
wrapNullable,
235226
assertGenericTypeAnnotationHasExactlyOneTypeParameter,
236-
emitMixedTypeAnnotation,
237227
emitUnionTypeAnnotation,
238228
getKeyName,
239229
translateDefault,

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import type {
1717
NativeModuleFunctionTypeAnnotation,
1818
NativeModuleTypeAliasTypeAnnotation,
1919
NativeModuleNumberTypeAnnotation,
20+
NativeModuleMixedTypeAnnotation,
2021
BooleanTypeAnnotation,
2122
DoubleTypeAnnotation,
2223
Int32TypeAnnotation,
@@ -80,13 +81,22 @@ function emitStringish(nullable: boolean): Nullable<StringTypeAnnotation> {
8081
type: 'StringTypeAnnotation',
8182
});
8283
}
84+
8385
function emitFunction(
8486
nullable: boolean,
8587
translateFunctionTypeAnnotationValue: NativeModuleFunctionTypeAnnotation,
8688
): Nullable<NativeModuleFunctionTypeAnnotation> {
8789
return wrapNullable(nullable, translateFunctionTypeAnnotationValue);
8890
}
8991

92+
function emitMixedTypeAnnotation(
93+
nullable: boolean,
94+
): Nullable<NativeModuleMixedTypeAnnotation> {
95+
return wrapNullable(nullable, {
96+
type: 'MixedTypeAnnotation',
97+
});
98+
}
99+
90100
function emitString(nullable: boolean): Nullable<StringTypeAnnotation> {
91101
return wrapNullable(nullable, {
92102
type: 'StringTypeAnnotation',
@@ -193,5 +203,6 @@ module.exports = {
193203
emitVoid,
194204
emitString,
195205
emitStringish,
206+
emitMixedTypeAnnotation,
196207
typeAliasResolution,
197208
};

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ const {
3636
unwrapNullable,
3737
wrapNullable,
3838
assertGenericTypeAnnotationHasExactlyOneTypeParameter,
39-
emitMixedTypeAnnotation,
4039
emitUnionTypeAnnotation,
4140
translateDefault,
4241
} = require('../../parsers-commons');
@@ -53,6 +52,7 @@ const {
5352
emitVoid,
5453
emitString,
5554
emitStringish,
55+
emitMixedTypeAnnotation,
5656
typeAliasResolution,
5757
} = require('../../parsers-primitives');
5858
const {

0 commit comments

Comments
 (0)