Skip to content

Commit

Permalink
add getAnnotatedElementProperties fn to parser
Browse files Browse the repository at this point in the history
  • Loading branch information
Pranav-yadav committed Mar 16, 2023
1 parent 4360da4 commit 7464edc
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 4 deletions.
4 changes: 4 additions & 0 deletions packages/react-native-codegen/src/parsers/flow/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,10 @@ class FlowParser implements Parser {
functionTypeAnnotation(propertyValueType: string): boolean {
return propertyValueType === 'FunctionTypeAnnotation';
}

getAnnotatedElementProperties(annotatedElement: $FlowFixMe): $FlowFixMe {
return annotatedElement.right.properties;
}
}

module.exports = {
Expand Down
7 changes: 7 additions & 0 deletions packages/react-native-codegen/src/parsers/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -211,4 +211,11 @@ export interface Parser {
* @returns: a boolean specifying if the property is a function type annotation.
*/
functionTypeAnnotation(propertyValueType: string): boolean;

/**
* Given a annotatedElement, it returns the properties of annotated element.
* @parameter annotatedElement: the annotated element.
* @returns: the properties of annotated element.
*/
getAnnotatedElementProperties(annotatedElement: $FlowFixMe): $FlowFixMe;
}
4 changes: 4 additions & 0 deletions packages/react-native-codegen/src/parsers/parserMock.js
Original file line number Diff line number Diff line change
Expand Up @@ -213,4 +213,8 @@ export class MockedParser implements Parser {
functionTypeAnnotation(propertyValueType: string): boolean {
return propertyValueType === 'FunctionTypeAnnotation';
}

getAnnotatedElementProperties(annotatedElement: $FlowFixMe): $FlowFixMe {
return annotatedElement.right.properties;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,8 @@ function emitPartial(
typeAnnotation,
types,
);
const annotatedElementProperties = annotatedElement.right.properties;
const annotatedElementProperties =
parser.getAnnotatedElementProperties(annotatedElement);

const partialProperties = parser.computePartialProperties(
annotatedElementProperties,
Expand All @@ -520,10 +521,10 @@ function emitCommonTypes(
nullable: boolean,
parser: Parser,
): $FlowFixMe {
const typeAnnotationType =
const typeAnnotationType = parser.nameForGenericTypeAnnotation()
const genericTypeAnnotationName =
parser.nameForGenericTypeAnnotation(typeAnnotation);

switch (typeAnnotationType) {
switch (genericTypeAnnotationName) {
case 'Stringish': {
return emitStringish(nullable);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,10 @@ class TypeScriptParser implements Parser {
propertyValueType === 'TSMethodSignature'
);
}

getAnnotatedElementProperties(annotatedElement: $FlowFixMe): $FlowFixMe {
return annotatedElement.typeAnnotation.members;
}
}

module.exports = {
Expand Down

0 comments on commit 7464edc

Please sign in to comment.