-
Notifications
You must be signed in to change notification settings - Fork 24.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create the Parser interface (#35036)
Summary: Pull Request resolved: #35036 This diff is the base to create a polimorphic behavior for TypeScript and Flow parser. This type will allow to share a lot of code between the parsers and also to keep their differences a part. It will be the base diff/PR for further tasks in the Codegen umbrella Issue ## Changelog: [General][Added] - Parser interface to divide parser logic. Reviewed By: cortinico Differential Revision: D40548707 fbshipit-source-id: e632ba52b00b43e50306e3a792a841e72e8c07f4
- Loading branch information
1 parent
c419b4f
commit 5940d25
Showing
6 changed files
with
85 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/** | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
* @flow strict | ||
* @format | ||
*/ | ||
|
||
'use strict'; | ||
|
||
import type {Parser} from '../parser'; | ||
|
||
class FlowParser implements Parser { | ||
nameForGenericTypeAnnotation(typeAnnotation: $FlowFixMe): string { | ||
return typeAnnotation.id.name; | ||
} | ||
} | ||
|
||
module.exports = { | ||
FlowParser, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/** | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
* @flow strict | ||
* @format | ||
*/ | ||
|
||
'use strict'; | ||
|
||
/** | ||
* This is the main interface for Parsers of various languages. | ||
* It exposes all the methods that contain language-specific logic. | ||
*/ | ||
export interface Parser { | ||
/** | ||
* Given a type annotation for a generic type, it returns the type name. | ||
* @parameter typeAnnotation: the annotation for a type in the AST. | ||
* @returns: the name of the type. | ||
*/ | ||
nameForGenericTypeAnnotation(typeAnnotation: $FlowFixMe): string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
packages/react-native-codegen/src/parsers/typescript/parser.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/** | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
* @flow strict | ||
* @format | ||
*/ | ||
|
||
'use strict'; | ||
|
||
import type {Parser} from '../parser'; | ||
|
||
class TypeScriptParser implements Parser { | ||
nameForGenericTypeAnnotation(typeAnnotation: $FlowFixMe): string { | ||
return typeAnnotation.typeName.name; | ||
} | ||
} | ||
module.exports = { | ||
TypeScriptParser, | ||
}; |