forked from facebook/react-native
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce TypeUtils (facebook#42122)
Summary: This diff introduces the `TypeUtils` directory where we can put platform-specific, context-independent type transformations. Changelog: [Internal] Differential Revision: D52291837
- Loading branch information
1 parent
b81a081
commit 7497df7
Showing
9 changed files
with
187 additions
and
135 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
18 changes: 18 additions & 0 deletions
18
packages/react-native-codegen/src/generators/TypeUtils/Cxx/index.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,18 @@ | ||
/** | ||
* 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 | ||
* @oncall react_native | ||
*/ | ||
|
||
function wrapOptional(type: string, isRequired: boolean): string { | ||
return isRequired ? type : `std::optional<${type}>`; | ||
} | ||
|
||
module.exports = { | ||
wrapOptional, | ||
}; |
27 changes: 27 additions & 0 deletions
27
packages/react-native-codegen/src/generators/TypeUtils/Java/index.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,27 @@ | ||
/** | ||
* 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 | ||
* @oncall react_native | ||
*/ | ||
|
||
const objectTypeForPrimitiveType = { | ||
boolean: 'Boolean', | ||
double: 'Double', | ||
float: 'Float', | ||
int: 'Integer', | ||
}; | ||
|
||
function wrapOptional(type: string, isRequired: boolean): string { | ||
return isRequired | ||
? type | ||
: `@Nullable ${objectTypeForPrimitiveType[type] ?? type}`; | ||
} | ||
|
||
module.exports = { | ||
wrapOptional, | ||
}; |
18 changes: 18 additions & 0 deletions
18
packages/react-native-codegen/src/generators/TypeUtils/Objective-C/index.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,18 @@ | ||
/** | ||
* 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 | ||
* @oncall react_native | ||
*/ | ||
|
||
function wrapOptional(type: string, isRequired: boolean): string { | ||
return isRequired ? type : `${type} _Nullable`; | ||
} | ||
|
||
module.exports = { | ||
wrapOptional, | ||
}; |
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
Oops, something went wrong.