-
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.
feat: handle negative values in enums (#47452)
Summary: This PR adds support for negative values in enums. Currently when we try to use an enum with negative value: ```ts enum MyEnum { ZERO = 0, POSITIVE = 1, NEGATIVE = -1, } export interface Spec extends TurboModule { useArg(arg: MyEnum): void; } export default TurboModuleRegistry.get<Spec>('Foo'); ``` It will fail: ``` Enum values can not be mixed. They all must be either blank, number, or string values. ``` This is because negative values are parsed as `UnaryExpressions` which have `-` operator in front and value as argument. With the new approach codegen properly generates enums with negative values. ## Changelog: [GENERAL] [ADDED] - Codegen: Support negative values in enums Pull Request resolved: #47452 Test Plan: I've added tests to see if everything is working properly Reviewed By: vzaidman Differential Revision: D65887888 Pulled By: elicwhite fbshipit-source-id: edb25f663dc58afa68c69cb84a47cfc67fc1f7e7
- Loading branch information
1 parent
0875912
commit 177bf4d
Showing
8 changed files
with
169 additions
and
13 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -782,6 +782,7 @@ export enum Quality { | |
} | ||
export enum Resolution { | ||
Corrupted = -1, | ||
Low = 720, | ||
High = 1080, | ||
} | ||
|
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 |
---|---|---|
|
@@ -866,6 +866,7 @@ export enum Quality { | |
} | ||
export enum Resolution { | ||
Corrupted = -1, | ||
Low = 720, | ||
High = 1080, | ||
} | ||
|
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