Skip to content

Commit a108dcb

Browse files
branaustfacebook-github-bot
authored andcommitted
Move verifyProprsNotAlreadyDefined Function To parsers-commons.js (#37963)
Summary: Move the `verifyProprsNotAlreadyDefined` functions [from Flow](https://github.com/facebook/react-native/blob/d8ced6f8953cd896471983714e722caf50783960/packages/react-native-codegen/src/parsers/flow/components/componentsUtils.js#L220-L229) and [from TypeScript](https://github.com/facebook/react-native/blob/d8ced6f8953cd896471983714e722caf50783960/packages/react-native-codegen/src/parsers/typescript/components/componentsUtils.js#LL486-L495) to the parsers-commons.js file. Use the new function in place of the others. ## Changelog: [Internal] [Changed] - Moved `verifyProprsNotAlreadyDefined` to `parsers-commons.js` Pull Request resolved: #37963 Reviewed By: cipolleschi Differential Revision: D46841711 Pulled By: rshest fbshipit-source-id: 4c7e85d8e184126d16c520b0e56b4c291babff06
1 parent 02771ec commit a108dcb

File tree

3 files changed

+14
-22
lines changed

3 files changed

+14
-22
lines changed

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

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
'use strict';
1212

1313
const {getValueFromTypes} = require('../utils.js');
14+
const {verifyPropNotAlreadyDefined} = require('../../parsers-commons');
1415
import type {TypeDeclarationMap, PropAST, ASTNode} from '../../utils';
1516
import type {BuildSchemaFN, Parser} from '../../parser';
1617

@@ -206,17 +207,6 @@ function flattenProperties(
206207
.filter(Boolean);
207208
}
208209

209-
function verifyPropNotAlreadyDefined(
210-
props: $ReadOnlyArray<PropAST>,
211-
needleProp: PropAST,
212-
) {
213-
const propName = needleProp.key.name;
214-
const foundProp = props.some(prop => prop.key.name === propName);
215-
if (foundProp) {
216-
throw new Error(`A prop was already defined with the name ${propName}`);
217-
}
218-
}
219-
220210
function getTypeAnnotation<+T>(
221211
name: string,
222212
annotation: $FlowFixMe | ASTNode,

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1072,6 +1072,17 @@ function buildPropertiesForEvent(
10721072
return getPropertyType(name, optional, typeAnnotation, parser);
10731073
}
10741074

1075+
function verifyPropNotAlreadyDefined(
1076+
props: $ReadOnlyArray<PropAST>,
1077+
needleProp: PropAST,
1078+
) {
1079+
const propName = needleProp.key.name;
1080+
const foundProp = props.some(prop => prop.key.name === propName);
1081+
if (foundProp) {
1082+
throw new Error(`A prop was already defined with the name ${propName}`);
1083+
}
1084+
}
1085+
10751086
module.exports = {
10761087
wrapModuleSchema,
10771088
unwrapNullable,
@@ -1099,4 +1110,5 @@ module.exports = {
10991110
handleGenericTypeAnnotation,
11001111
getTypeResolutionStatus,
11011112
buildPropertiesForEvent,
1113+
verifyPropNotAlreadyDefined,
11021114
};

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

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ const {
1313
parseTopLevelType,
1414
flattenIntersectionType,
1515
} = require('../parseTopLevelType');
16+
const {verifyPropNotAlreadyDefined} = require('../../parsers-commons');
1617
import type {TypeDeclarationMap, PropAST, ASTNode} from '../../utils';
1718
import type {BuildSchemaFN, Parser} from '../../parser';
1819

@@ -453,17 +454,6 @@ function getSchemaInfo(
453454
};
454455
}
455456

456-
function verifyPropNotAlreadyDefined(
457-
props: $ReadOnlyArray<PropAST>,
458-
needleProp: PropAST,
459-
) {
460-
const propName = needleProp.key.name;
461-
const foundProp = props.some(prop => prop.key.name === propName);
462-
if (foundProp) {
463-
throw new Error(`A prop was already defined with the name ${propName}`);
464-
}
465-
}
466-
467457
function flattenProperties(
468458
typeDefinition: $ReadOnlyArray<PropAST>,
469459
types: TypeDeclarationMap,

0 commit comments

Comments
 (0)