react-native/packages
Oskar Kwaśniewski 177bf4d043 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: https://github.com/facebook/react-native/pull/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
2024-11-13 12:20:16 -08:00
..
assets
babel-plugin-codegen
community-cli-plugin
core-cli-utils
debugger-frontend Update debugger-frontend from ff343d8...b61aae3 (#47593) 2024-11-13 11:27:38 -08:00
dev-middleware
eslint-config-react-native
eslint-plugin-react-native
eslint-plugin-specs
gradle-plugin
helloworld
hermes-inspector-msggen
metro-config
normalize-color
polyfills
react-native validate input before calling setSelection to restore selection range (#47577) 2024-11-13 11:38:02 -08:00
react-native-babel-preset
react-native-babel-transformer
react-native-bots
react-native-codegen feat: handle negative values in enums (#47452) 2024-11-13 12:20:16 -08:00
react-native-codegen-typescript-test
react-native-info
react-native-popup-menu-android
react-native-test-library
react-native-test-renderer
rn-tester
typescript-config
virtualized-lists