Skip to content

Commit

Permalink
Add function emitMixedProp to parser-primitives (#37608)
Browse files Browse the repository at this point in the history
Summary:
[Codegen 132] This PR introduces `emitMixedProp` to parser-primitives and abstracts the logic out of typescript and parser events as requested on #34872

## Changelog:

[Internal] [Changed] - Add emitMixedProp  to parser-primitives and update usages.

Pull Request resolved: #37608

Test Plan:
Run yarn jest react-native-codegen and ensure CI is green

## Screenshot of tests passing locally:

<img width="1182" alt="Screenshot 2023-05-28 at 12 46 49 PM" src="https://github.com/facebook/react-native/assets/64726664/dbea4daf-d954-4c7f-b121-c6aad1fb318e">

Reviewed By: dmytrorykun

Differential Revision: D46275638

Pulled By: cipolleschi

fbshipit-source-id: 803d82055c7925e49aca1f408b5c7a50c687349a
  • Loading branch information
siddarthkay authored and facebook-github-bot committed Jun 6, 2023
1 parent 663a018 commit a497882
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const {
emitBoolProp,
emitDoubleProp,
emitFloatProp,
emitMixedProp,
emitStringProp,
emitInt32Prop,
} = require('../../parsers-primitives');
Expand Down Expand Up @@ -80,13 +81,7 @@ function getPropertyType(
},
};
case 'UnsafeMixed':
return {
name,
optional,
typeAnnotation: {
type: 'MixedTypeAnnotation',
},
};
return emitMixedProp(name, optional);
case 'ArrayTypeAnnotation':
case '$ReadOnlyArray':
return {
Expand Down
14 changes: 14 additions & 0 deletions packages/react-native-codegen/src/parsers/parsers-primitives.js
Original file line number Diff line number Diff line change
Expand Up @@ -644,6 +644,19 @@ function emitBoolProp(
};
}

function emitMixedProp(
name: string,
optional: boolean,
): NamedShape<EventTypeAnnotation> {
return {
name,
optional,
typeAnnotation: {
type: 'MixedTypeAnnotation',
},
};
}

module.exports = {
emitArrayType,
emitBoolean,
Expand All @@ -655,6 +668,7 @@ module.exports = {
emitFunction,
emitInt32,
emitInt32Prop,
emitMixedProp,
emitNumber,
emitGenericObject,
emitDictionary,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const {
emitBoolProp,
emitDoubleProp,
emitFloatProp,
emitMixedProp,
emitStringProp,
emitInt32Prop,
} = require('../../parsers-primitives');
Expand Down Expand Up @@ -82,13 +83,7 @@ function getPropertyType(
},
};
case 'UnsafeMixed':
return {
name,
optional,
typeAnnotation: {
type: 'MixedTypeAnnotation',
},
};
return emitMixedProp(name, optional);
case 'TSArrayType':
return {
name,
Expand Down

0 comments on commit a497882

Please sign in to comment.