mv emitMixedTypeAnnotation fn > parsers-primitives.js (#35185)

Summary:
This PR is a task of https://github.com/facebook/react-native/issues/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: https://github.com/facebook/react-native/pull/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
This commit is contained in:
Pranav Yadav
2022-11-04 05:11:39 -07:00
committed by Facebook GitHub Bot
parent 35ebb57afa
commit 95e685a44d
6 changed files with 40 additions and 39 deletions
@@ -16,7 +16,6 @@ import type {ParserType} from '../errors';
const {
wrapNullable,
unwrapNullable,
emitMixedTypeAnnotation,
emitUnionTypeAnnotation,
} = require('../parsers-commons.js');
const {UnsupportedUnionTypeAnnotationParserError} = require('../errors');
@@ -250,32 +249,6 @@ describe('assertGenericTypeAnnotationHasExactlyOneTypeParameter', () => {
});
});
describe('emitMixedTypeAnnotation', () => {
describe('when nullable is true', () => {
it('returns nullable type annotation', () => {
const result = emitMixedTypeAnnotation(true);
const expected = {
type: 'NullableTypeAnnotation',
typeAnnotation: {
type: 'MixedTypeAnnotation',
},
};
expect(result).toEqual(expected);
});
});
describe('when nullable is false', () => {
it('returns non nullable type annotation', () => {
const result = emitMixedTypeAnnotation(false);
const expected = {
type: 'MixedTypeAnnotation',
};
expect(result).toEqual(expected);
});
});
});
describe('emitUnionTypeAnnotation', () => {
const hasteModuleName = 'SampleTurboModule';
@@ -23,6 +23,7 @@ const {
emitVoid,
emitString,
emitStringish,
emitMixedTypeAnnotation,
typeAliasResolution,
} = require('../parsers-primitives.js');
@@ -452,3 +453,29 @@ describe('emitObject', () => {
});
});
});
describe('emitMixedTypeAnnotation', () => {
describe('when nullable is true', () => {
it('returns nullable type annotation', () => {
const result = emitMixedTypeAnnotation(true);
const expected = {
type: 'NullableTypeAnnotation',
typeAnnotation: {
type: 'MixedTypeAnnotation',
},
};
expect(result).toEqual(expected);
});
});
describe('when nullable is false', () => {
it('returns non nullable type annotation', () => {
const result = emitMixedTypeAnnotation(false);
const expected = {
type: 'MixedTypeAnnotation',
};
expect(result).toEqual(expected);
});
});
});
@@ -33,7 +33,6 @@ const {
unwrapNullable,
wrapNullable,
assertGenericTypeAnnotationHasExactlyOneTypeParameter,
emitMixedTypeAnnotation,
emitUnionTypeAnnotation,
translateDefault,
} = require('../../parsers-commons');
@@ -50,6 +49,7 @@ const {
emitVoid,
emitString,
emitStringish,
emitMixedTypeAnnotation,
typeAliasResolution,
} = require('../../parsers-primitives');
@@ -15,7 +15,6 @@ import type {
NativeModuleSchema,
NativeModuleTypeAnnotation,
Nullable,
NativeModuleMixedTypeAnnotation,
UnionTypeAnnotationMemberType,
NativeModuleUnionTypeAnnotation,
} from '../CodegenSchema.js';
@@ -107,14 +106,6 @@ function assertGenericTypeAnnotationHasExactlyOneTypeParameter(
}
}
function emitMixedTypeAnnotation(
nullable: boolean,
): Nullable<NativeModuleMixedTypeAnnotation> {
return wrapNullable(nullable, {
type: 'MixedTypeAnnotation',
});
}
function remapUnionTypeAnnotationMemberNames(
types: $FlowFixMe,
language: ParserType,
@@ -233,7 +224,6 @@ module.exports = {
unwrapNullable,
wrapNullable,
assertGenericTypeAnnotationHasExactlyOneTypeParameter,
emitMixedTypeAnnotation,
emitUnionTypeAnnotation,
getKeyName,
translateDefault,
@@ -17,6 +17,7 @@ import type {
NativeModuleFunctionTypeAnnotation,
NativeModuleTypeAliasTypeAnnotation,
NativeModuleNumberTypeAnnotation,
NativeModuleMixedTypeAnnotation,
BooleanTypeAnnotation,
DoubleTypeAnnotation,
Int32TypeAnnotation,
@@ -80,6 +81,7 @@ function emitStringish(nullable: boolean): Nullable<StringTypeAnnotation> {
type: 'StringTypeAnnotation',
});
}
function emitFunction(
nullable: boolean,
translateFunctionTypeAnnotationValue: NativeModuleFunctionTypeAnnotation,
@@ -87,6 +89,14 @@ function emitFunction(
return wrapNullable(nullable, translateFunctionTypeAnnotationValue);
}
function emitMixedTypeAnnotation(
nullable: boolean,
): Nullable<NativeModuleMixedTypeAnnotation> {
return wrapNullable(nullable, {
type: 'MixedTypeAnnotation',
});
}
function emitString(nullable: boolean): Nullable<StringTypeAnnotation> {
return wrapNullable(nullable, {
type: 'StringTypeAnnotation',
@@ -193,5 +203,6 @@ module.exports = {
emitVoid,
emitString,
emitStringish,
emitMixedTypeAnnotation,
typeAliasResolution,
};
@@ -36,7 +36,6 @@ const {
unwrapNullable,
wrapNullable,
assertGenericTypeAnnotationHasExactlyOneTypeParameter,
emitMixedTypeAnnotation,
emitUnionTypeAnnotation,
translateDefault,
} = require('../../parsers-commons');
@@ -53,6 +52,7 @@ const {
emitVoid,
emitString,
emitStringish,
emitMixedTypeAnnotation,
typeAliasResolution,
} = require('../../parsers-primitives');
const {