Skip to content

Commit a497882

Browse files
siddarthkayfacebook-github-bot
authored andcommitted
Add function emitMixedProp to parser-primitives (#37608)
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
1 parent 663a018 commit a497882

File tree

3 files changed

+18
-14
lines changed

3 files changed

+18
-14
lines changed

packages/react-native-codegen/src/parsers/flow/components/events.js

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ const {
2727
emitBoolProp,
2828
emitDoubleProp,
2929
emitFloatProp,
30+
emitMixedProp,
3031
emitStringProp,
3132
emitInt32Prop,
3233
} = require('../../parsers-primitives');
@@ -80,13 +81,7 @@ function getPropertyType(
8081
},
8182
};
8283
case 'UnsafeMixed':
83-
return {
84-
name,
85-
optional,
86-
typeAnnotation: {
87-
type: 'MixedTypeAnnotation',
88-
},
89-
};
84+
return emitMixedProp(name, optional);
9085
case 'ArrayTypeAnnotation':
9186
case '$ReadOnlyArray':
9287
return {

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -644,6 +644,19 @@ function emitBoolProp(
644644
};
645645
}
646646

647+
function emitMixedProp(
648+
name: string,
649+
optional: boolean,
650+
): NamedShape<EventTypeAnnotation> {
651+
return {
652+
name,
653+
optional,
654+
typeAnnotation: {
655+
type: 'MixedTypeAnnotation',
656+
},
657+
};
658+
}
659+
647660
module.exports = {
648661
emitArrayType,
649662
emitBoolean,
@@ -655,6 +668,7 @@ module.exports = {
655668
emitFunction,
656669
emitInt32,
657670
emitInt32Prop,
671+
emitMixedProp,
658672
emitNumber,
659673
emitGenericObject,
660674
emitDictionary,

packages/react-native-codegen/src/parsers/typescript/components/events.js

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ const {
2929
emitBoolProp,
3030
emitDoubleProp,
3131
emitFloatProp,
32+
emitMixedProp,
3233
emitStringProp,
3334
emitInt32Prop,
3435
} = require('../../parsers-primitives');
@@ -82,13 +83,7 @@ function getPropertyType(
8283
},
8384
};
8485
case 'UnsafeMixed':
85-
return {
86-
name,
87-
optional,
88-
typeAnnotation: {
89-
type: 'MixedTypeAnnotation',
90-
},
91-
};
86+
return emitMixedProp(name, optional);
9287
case 'TSArrayType':
9388
return {
9489
name,

0 commit comments

Comments
 (0)