react-native/packages/react-native-codegen
Tom Van Laerhoven 13780126d3 Fix generated EventEmitter code for nested objects in arrays. (#47514)
Summary:
This PR fixes the code for generating EventEmitter C++ code in case nested objects in arrays are used.

```typescript
export interface NativeProps extends ViewProps {
  onEvent: DirectEventHandler<
    Readonly<{
      payloadArray: Readonly<
        {
          obj: Readonly<{ str: string }>
        }[]
      >
    }>
  >;
}

export default codegenNativeComponent<NativeProps>('SomeComponent');
```

In this case the generated `EventEmitters.cpp` code would contain:

```c
obj.setProperty(runtime, "str", payloadArrayValue,obj.str);
```

while

```c
obj.setProperty(runtime, "str", payloadArrayValue.obj.str);
```

is expected.

## Changelog:

<!-- Help reviewers and the release process by writing your own changelog entry.

Pick one each for the category and type tags:

[ANDROID|GENERAL|IOS|INTERNAL] [BREAKING|ADDED|CHANGED|DEPRECATED|REMOVED|FIXED|SECURITY] - Message

For more details, see:
https://reactnative.dev/contributing/changelogs-in-pull-requests
-->

[GENERAL] [FIXED] - Codegen: Support nested objects in arrays

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

Test Plan: Tested with the reproduction case above to verify correct output.

Reviewed By: javache

Differential Revision: D65848670

Pulled By: elicwhite

fbshipit-source-id: 0021e87bc7213fff615465cab8554cc1a2159522
2024-11-20 16:25:34 -08:00
..
e2e Fix generated EventEmitter code for nested objects in arrays. (#47514) 2024-11-20 16:25:34 -08:00
scripts chore: replace mkdirp with mkdir fs (#46388) 2024-09-17 07:03:44 -07:00
src Fix generated EventEmitter code for nested objects in arrays. (#47514) 2024-11-20 16:25:34 -08:00
.babelrc fix: deprecated babel plugins issue fixed (#44416) 2024-05-08 12:51:00 -07:00
.prettierrc
package.json Update hermes-parser and related packages in fbsource to 0.24.0 (#46802) 2024-10-03 08:20:16 -07:00
README.md Revert D49370200: Migrate codegen to shared build setup, remove package build pre-step from RNTester 2023-10-23 12:00:54 -07:00

@react-native/codegen

Version

Installation

yarn add --dev @react-native/codegen

Note: We're using yarn to install deps. Feel free to change commands to use npm 3+ and npx if you like

Testing

To run the tests in this package, run the following commands from the React Native root folder:

  1. yarn to install the dependencies. You just need to run this once
  2. yarn jest packages/react-native-codegen.