Skip to content

[compiler] support numeric object keys#54

Open
everettbu wants to merge 1 commit into
mainfrom
pr30680
Open

[compiler] support numeric object keys#54
everettbu wants to merge 1 commit into
mainfrom
pr30680

Conversation

@everettbu

@everettbu everettbu commented Dec 12, 2025

Copy link
Copy Markdown

Mirror of facebook/react#30680
Original author: kassens


This feels a bit like a hack since I'm just converting the number into a string, but that's just reflecting what happens at runtime. The downside here is that if we converted these identifiers anywhere outside of object keys back to code, we would need to watch out for that.

For example, we might convert an object destructure into a property access which would need to use obj[2] instead of obj.bar, but I that should also be the case of property access with string keys that are not valid identifiers

This feels a *bit* like a hack since I'm just converting the number into a string, but that's just reflecting what happens at runtime. The downside here is that if we converted these identifiers anywhere outside of object keys back to code, we would need to watch out for that.

For example, we might convert an object destructure into a property access which would need to use `obj[2]` instead of obj.bar, but I that should also be the case of property access with string keys that are not valid identifiers
@everettbu everettbu added CLA Signed React Core Team Opened by a member of the React Core Team labels Dec 12, 2025
@greptile-apps

greptile-apps Bot commented Dec 12, 2025

Copy link
Copy Markdown

Greptile Overview

Greptile Summary

Added support for numeric object keys in the React compiler by converting NumericLiteral values to strings in lowerObjectPropertyKey, matching JavaScript's runtime behavior where numeric keys are automatically coerced to strings.

  • Converted numeric literals to identifier keys using String(key.node.value) in BuildHIR.ts:1442-1446
  • Added comprehensive test with hexadecimal notation (0x10) demonstrating both object literal creation and destructuring
  • Test correctly validates that 0x10 is normalized to 16 in compiled output

Confidence Score: 5/5

  • This PR is safe to merge with minimal risk
  • The change is a straightforward addition that handles a previously unsupported case (numeric object keys) by converting them to strings, which accurately reflects JavaScript's runtime behavior. The implementation follows existing patterns in the codebase (similar to how string literals are handled), includes a proper test case with expected output, and the test demonstrates correct behavior including hexadecimal notation conversion.
  • No files require special attention

Important Files Changed

File Analysis

Filename Score Overview
compiler/packages/babel-plugin-react-compiler/src/HIR/BuildHIR.ts 5/5 Added numeric literal support in object keys by converting to string, matching JavaScript runtime behavior
compiler/packages/babel-plugin-react-compiler/src/tests/fixtures/compiler/object-numeric-index.js 5/5 Test fixture demonstrating hexadecimal numeric key 0x10 in object literal and destructuring
compiler/packages/babel-plugin-react-compiler/src/tests/fixtures/compiler/object-numeric-index.expect.md 5/5 Expected compiler output showing numeric key 0x10 correctly converted to 16 with proper memoization

@greptile-apps greptile-apps Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

3 files reviewed, no comments

Edit Code Review Agent Settings | Greptile

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

Labels

CLA Signed React Core Team Opened by a member of the React Core Team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants