Repository navigation
Conversation
This branch has not been deployed
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
NumericLiteralnodes. Babel represents a negative numeric initializer as aUnaryExpression, 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:
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.
ESLint, formatting, and focused Flow checking pass.
node scripts/build.jsfrompackages/react-native-codegenalso 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.