Skip to content

Reject negative fractional enum values in TypeScript Codegen - #59466

Open
Marve10s wants to merge 1 commit into
react:mainfrom
Marve10s:fix/codegen-negative-fractional-enums
Open

Marve10s wants to merge 1 commit into
react:mainfrom
Marve10s:fix/codegen-negative-fractional-enums

Conversation

@Marve10s

Copy link
Copy Markdown
Contributor

Summary:

TypeScript Codegen rejects positive fractional enum values but accepts negative ones. For example, enum Message { ZERO = 0, VALUE = -1.5 } passes parsing on 0.88.0 and main. Its generated C++ declaration omits the fractional initializer while the bridging code still compares and returns -1.5.

The existing integer check only examines NumericLiteral nodes. Babel represents a negative numeric initializer as a UnaryExpression, which bypasses that check. Inspect its numeric argument before applying the same integer validation.

This brings negative fractions into line with positive fractions and the Flow parser. Integer-only enums are an existing restriction established in #44326; negative integer support from #47452 is preserved.

Before: parsing the spec succeeds and emits enum class NativeFractionMessage { ZERO = 0, VALUE };.

After: parsing throws the existing UnsupportedEnumDeclarationParserError.

Changelog:

[GENERAL] [FIXED] - Reject negative fractional enum initializers in TypeScript Codegen, matching the existing integer-only enum restriction.

Test Plan:

./node_modules/.bin/jest --runInBand --watchman=false --verbose=false packages/react-native-codegen/src/parsers

All 1,974 parser tests and 188 snapshots pass across 13 suites. The four new regressions fail against the original implementation because it does not throw. They cover a fractional first member, a later member, scientific notation, and parentheses. Existing negative integer cases continue to pass.

./node_modules/.bin/eslint --max-warnings 0 packages/react-native-codegen/src/parsers/typescript/modules/index.js packages/react-native-codegen/src/parsers/typescript/modules/__tests__/typescript-module-parser-e2e-test.js
./node_modules/.bin/prettier --check packages/react-native-codegen/src/parsers/typescript/modules/index.js packages/react-native-codegen/src/parsers/typescript/modules/__tests__/typescript-module-parser-e2e-test.js
npx --yes --package=flow-bin@0.337.0 flow focus-check --max-workers 2 packages/react-native-codegen/src/parsers/typescript/modules/index.js packages/react-native-codegen/src/parsers/typescript/modules/__tests__/typescript-module-parser-e2e-test.js

ESLint, formatting, and focused Flow checking pass. node scripts/build.js from packages/react-native-codegen also passes. A probe of the rebuilt package rejects positive and negative fractions while accepting ordinary, negative, hexadecimal, and scientific-notation integers.

Native builds and full-repository checks were not run; the defect and regressions reproduce entirely within the parser.

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Oct 25, 2026
@facebook-github-tools facebook-github-tools Bot added the Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team. label Oct 25, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant