Skip to content

Commit

Permalink
mv emitMixedTypeAnnotation fn > parsers-primitives.js (#35185)
Browse files Browse the repository at this point in the history
Summary:
This PR is a task of #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: #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
  • Loading branch information
Pranav-yadav authored and facebook-github-bot committed Nov 4, 2022
1 parent 35ebb57 commit 95e685a
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import type {ParserType} from '../errors';
const {
wrapNullable,
unwrapNullable,
emitMixedTypeAnnotation,
emitUnionTypeAnnotation,
} = require('../parsers-commons.js');
const {UnsupportedUnionTypeAnnotationParserError} = require('../errors');
Expand Down Expand Up @@ -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';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const {
emitVoid,
emitString,
emitStringish,
emitMixedTypeAnnotation,
typeAliasResolution,
} = require('../parsers-primitives.js');

Expand Down Expand Up @@ -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);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ const {
unwrapNullable,
wrapNullable,
assertGenericTypeAnnotationHasExactlyOneTypeParameter,
emitMixedTypeAnnotation,
emitUnionTypeAnnotation,
translateDefault,
} = require('../../parsers-commons');
Expand All @@ -50,6 +49,7 @@ const {
emitVoid,
emitString,
emitStringish,
emitMixedTypeAnnotation,
typeAliasResolution,
} = require('../../parsers-primitives');

Expand Down
10 changes: 0 additions & 10 deletions packages/react-native-codegen/src/parsers/parsers-commons.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import type {
NativeModuleSchema,
NativeModuleTypeAnnotation,
Nullable,
NativeModuleMixedTypeAnnotation,
UnionTypeAnnotationMemberType,
NativeModuleUnionTypeAnnotation,
} from '../CodegenSchema.js';
Expand Down Expand Up @@ -107,14 +106,6 @@ function assertGenericTypeAnnotationHasExactlyOneTypeParameter(
}
}

function emitMixedTypeAnnotation(
nullable: boolean,
): Nullable<NativeModuleMixedTypeAnnotation> {
return wrapNullable(nullable, {
type: 'MixedTypeAnnotation',
});
}

function remapUnionTypeAnnotationMemberNames(
types: $FlowFixMe,
language: ParserType,
Expand Down Expand Up @@ -233,7 +224,6 @@ module.exports = {
unwrapNullable,
wrapNullable,
assertGenericTypeAnnotationHasExactlyOneTypeParameter,
emitMixedTypeAnnotation,
emitUnionTypeAnnotation,
getKeyName,
translateDefault,
Expand Down
11 changes: 11 additions & 0 deletions packages/react-native-codegen/src/parsers/parsers-primitives.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import type {
NativeModuleFunctionTypeAnnotation,
NativeModuleTypeAliasTypeAnnotation,
NativeModuleNumberTypeAnnotation,
NativeModuleMixedTypeAnnotation,
BooleanTypeAnnotation,
DoubleTypeAnnotation,
Int32TypeAnnotation,
Expand Down Expand Up @@ -80,13 +81,22 @@ function emitStringish(nullable: boolean): Nullable<StringTypeAnnotation> {
type: 'StringTypeAnnotation',
});
}

function emitFunction(
nullable: boolean,
translateFunctionTypeAnnotationValue: NativeModuleFunctionTypeAnnotation,
): Nullable<NativeModuleFunctionTypeAnnotation> {
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',
Expand Down Expand Up @@ -193,5 +203,6 @@ module.exports = {
emitVoid,
emitString,
emitStringish,
emitMixedTypeAnnotation,
typeAliasResolution,
};
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ const {
unwrapNullable,
wrapNullable,
assertGenericTypeAnnotationHasExactlyOneTypeParameter,
emitMixedTypeAnnotation,
emitUnionTypeAnnotation,
translateDefault,
} = require('../../parsers-commons');
Expand All @@ -53,6 +52,7 @@ const {
emitVoid,
emitString,
emitStringish,
emitMixedTypeAnnotation,
typeAliasResolution,
} = require('../../parsers-primitives');
const {
Expand Down

0 comments on commit 95e685a

Please sign in to comment.