SIGN IN SIGN UP
facebook / react-native UNCLAIMED

A framework for building native applications using React

0 0 155 C++

Parse string unions as StringLiteralUnionTypeAnnotation (#46845)

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

Previously, the parser was throwing away the values of a string union when storing it in the schema. It would only store the union as

```
{
  type: 'UnionTypeAnnotation',
  memberType: 'StringTypeAnnotation'
}
```

We now track the string literals through the parser and store them in the schema:

```
{
  type: 'StringLiteralUnionTypeAnnotation',
  types: [
    {
      type: 'StringLiteralTypeAnnotation'
      value: 'light'
    },
    {
      type: 'StringLiteralTypeAnnotation'
      value: 'dark'
    },
  ],
}
```

We aren't changing the generators, those still just output "string". They could eventually be made smarter.

The value of this is that the compat checker can now error when the union changes.

Changelog: [Internal]

Reviewed By: yungsters

Differential Revision: D63917685

fbshipit-source-id: 34a10e1f1910d2935837a3659f66049fd4473134
E
Eli White committed
a669de1dd2d86e0780dcb115d5d236e74a2bfbfa
Parent: 1ffef56
Committed by Facebook GitHub Bot <facebook-github-bot@users.noreply.github.com> on 10/7/2024, 11:56:04 PM