Skip to content

Commit

Permalink
add getPaperTopLevelNameDeprecated to parsers
Browse files Browse the repository at this point in the history
  • Loading branch information
siddarthkay committed Jul 30, 2023
1 parent 265f72f commit 3fb22e7
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -189,9 +189,7 @@ function findEventArgumentsAndType(
} else if (name === 'BubblingEventHandler' || name === 'DirectEventHandler') {
const eventType = name === 'BubblingEventHandler' ? 'bubble' : 'direct';
const paperTopLevelNameDeprecated =
typeAnnotation.typeParameters.params.length > 1
? typeAnnotation.typeParameters.params[1].value
: null;
parser.getPaperTopLevelNameDeprecated(typeAnnotation);
if (
typeAnnotation.typeParameters.params[0].type ===
parser.nullLiteralTypeAnnotation
Expand Down
6 changes: 6 additions & 0 deletions packages/react-native-codegen/src/parsers/flow/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -543,6 +543,12 @@ class FlowParser implements Parser {
getObjectProperties(typeAnnotation: $FlowFixMe): $FlowFixMe {
return typeAnnotation.properties;
}

getPaperTopLevelNameDeprecated(typeAnnotation: $FlowFixMe): $FlowFixMe {
return typeAnnotation.typeParameters.params.length > 1
? typeAnnotation.typeParameters.params[1].value
: null;
}
}

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 @@ -414,4 +414,11 @@ export interface Parser {
* @returns: the properties of an object represented by a type annotation.
*/
getObjectProperties(typeAnnotation: $FlowFixMe): $FlowFixMe;

/**
* Given a type annotation, it returns top level name in the AST if it exists else returns null.
* @parameter typeAnnotation: the annotation for a type in the AST.
* @returns: the top level name properties in the AST if it exists else null.
*/
getPaperTopLevelNameDeprecated(typeAnnotation: $FlowFixMe): $FlowFixMe;
}
6 changes: 6 additions & 0 deletions packages/react-native-codegen/src/parsers/parserMock.js
Original file line number Diff line number Diff line change
Expand Up @@ -482,4 +482,10 @@ export class MockedParser implements Parser {
getObjectProperties(typeAnnotation: $FlowFixMe): $FlowFixMe {
return typeAnnotation.properties;
}

getPaperTopLevelNameDeprecated(typeAnnotation: $FlowFixMe): $FlowFixMe {
return typeAnnotation.typeParameters.params.length > 1
? typeAnnotation.typeParameters.params[1].value
: null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -198,9 +198,7 @@ function findEventArgumentsAndType(
} else if (name === 'BubblingEventHandler' || name === 'DirectEventHandler') {
const eventType = name === 'BubblingEventHandler' ? 'bubble' : 'direct';
const paperTopLevelNameDeprecated =
typeAnnotation.typeParameters.params.length > 1
? typeAnnotation.typeParameters.params[1].literal.value
: null;
parser.getPaperTopLevelNameDeprecated(typeAnnotation);
switch (typeAnnotation.typeParameters.params[0].type) {
case parser.nullLiteralTypeAnnotation:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -557,6 +557,12 @@ class TypeScriptParser implements Parser {
getObjectProperties(typeAnnotation: $FlowFixMe): $FlowFixMe {
return typeAnnotation.members;
}

getPaperTopLevelNameDeprecated(typeAnnotation: $FlowFixMe): $FlowFixMe {
return typeAnnotation.typeParameters.params.length > 1
? typeAnnotation.typeParameters.params[1].literal.value
: null;
}
}

module.exports = {
Expand Down

0 comments on commit 3fb22e7

Please sign in to comment.