add getPaperTopLevelNameDeprecated to parsers (#38683)

Summary:
[Codegen 135] This PR introduces `getPaperTopLevelNameDeprecated` to parser base class and abstracts the logic out of typescript and parser events as requested on https://github.com/facebook/react-native/issues/34872

## Changelog:

[Internal] [Changed] - Add `getPaperTopLevelNameDeprecated` to parser base class and update usages.

Pull Request resolved: https://github.com/facebook/react-native/pull/38683

Test Plan:
Run `yarn jest react-native-codegen` locally and ensure CI is green

## Screenshot of test passing locally:
<img width="1060" alt="Screenshot 2023-07-30 at 10 04 24 AM" src="https://github.com/facebook/react-native/assets/64726664/3f61377b-9f44-45e8-bece-d4fd6bcc4567">

Reviewed By: cipolleschi

Differential Revision: D47902816

Pulled By: rshest

fbshipit-source-id: 6fab53e02cfc3f0aaa3ffd795c3fe1d2f723e060
This commit is contained in:
Siddarth Kumar
2023-07-31 07:52:19 -07:00
committed by Facebook GitHub Bot
parent 1ba7bc0eb1
commit 8bcfc493ea
6 changed files with 27 additions and 6 deletions
@@ -193,9 +193,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
@@ -547,6 +547,12 @@ class FlowParser implements Parser {
getLiteralValue(option: $FlowFixMe): $FlowFixMe {
return option.value;
}
getPaperTopLevelNameDeprecated(typeAnnotation: $FlowFixMe): $FlowFixMe {
return typeAnnotation.typeParameters.params.length > 1
? typeAnnotation.typeParameters.params[1].value
: null;
}
}
module.exports = {
+7
View File
@@ -421,4 +421,11 @@ export interface Parser {
* @returns: the literal value of an union represented.
*/
getLiteralValue(option: $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;
}
@@ -486,4 +486,10 @@ export class MockedParser implements Parser {
getLiteralValue(option: $FlowFixMe): $FlowFixMe {
return option.value;
}
getPaperTopLevelNameDeprecated(typeAnnotation: $FlowFixMe): $FlowFixMe {
return typeAnnotation.typeParameters.params.length > 1
? typeAnnotation.typeParameters.params[1].value
: null;
}
}
@@ -202,9 +202,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:
@@ -561,6 +561,12 @@ class TypeScriptParser implements Parser {
getLiteralValue(option: $FlowFixMe): $FlowFixMe {
return option.literal.value;
}
getPaperTopLevelNameDeprecated(typeAnnotation: $FlowFixMe): $FlowFixMe {
return typeAnnotation.typeParameters.params.length > 1
? typeAnnotation.typeParameters.params[1].literal.value
: null;
}
}
module.exports = {