Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
'use strict';

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

Expand Down Expand Up @@ -206,17 +207,6 @@ function flattenProperties(
.filter(Boolean);
}

function verifyPropNotAlreadyDefined(
props: $ReadOnlyArray<PropAST>,
needleProp: PropAST,
) {
const propName = needleProp.key.name;
const foundProp = props.some(prop => prop.key.name === propName);
if (foundProp) {
throw new Error(`A prop was already defined with the name ${propName}`);
}
}

function getTypeAnnotation<+T>(
name: string,
annotation: $FlowFixMe | ASTNode,
Expand Down
12 changes: 12 additions & 0 deletions packages/react-native-codegen/src/parsers/parsers-commons.js
Original file line number Diff line number Diff line change
Expand Up @@ -1072,6 +1072,17 @@ function buildPropertiesForEvent(
return getPropertyType(name, optional, typeAnnotation, parser);
}

function verifyPropNotAlreadyDefined(
props: $ReadOnlyArray<PropAST>,
needleProp: PropAST,
) {
const propName = needleProp.key.name;
const foundProp = props.some(prop => prop.key.name === propName);
if (foundProp) {
throw new Error(`A prop was already defined with the name ${propName}`);
}
}

module.exports = {
wrapModuleSchema,
unwrapNullable,
Expand Down Expand Up @@ -1099,4 +1110,5 @@ module.exports = {
handleGenericTypeAnnotation,
getTypeResolutionStatus,
buildPropertiesForEvent,
verifyPropNotAlreadyDefined,
};
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const {
parseTopLevelType,
flattenIntersectionType,
} = require('../parseTopLevelType');
const {verifyPropNotAlreadyDefined} = require('../../parsers-commons');
import type {TypeDeclarationMap, PropAST, ASTNode} from '../../utils';
import type {BuildSchemaFN, Parser} from '../../parser';

Expand Down Expand Up @@ -453,17 +454,6 @@ function getSchemaInfo(
};
}

function verifyPropNotAlreadyDefined(
props: $ReadOnlyArray<PropAST>,
needleProp: PropAST,
) {
const propName = needleProp.key.name;
const foundProp = props.some(prop => prop.key.name === propName);
if (foundProp) {
throw new Error(`A prop was already defined with the name ${propName}`);
}
}

function flattenProperties(
typeDefinition: $ReadOnlyArray<PropAST>,
types: TypeDeclarationMap,
Expand Down