diff --git a/compiler/packages/babel-plugin-react-compiler/src/HIR/BuildHIR.ts b/compiler/packages/babel-plugin-react-compiler/src/HIR/BuildHIR.ts index 4d9ce6becc17a..487ae7c1b89ae 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/HIR/BuildHIR.ts +++ b/compiler/packages/babel-plugin-react-compiler/src/HIR/BuildHIR.ts @@ -1454,6 +1454,11 @@ function lowerObjectPropertyKey( kind: 'identifier', name: key.node.name, }; + } else if (key.isNumericLiteral()) { + return { + kind: 'identifier', + name: String(key.node.value), + } } builder.errors.push({ diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/numeric-literal-as-object-property-key.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/numeric-literal-as-object-property-key.expect.md new file mode 100644 index 0000000000000..b762ac3204bed --- /dev/null +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/numeric-literal-as-object-property-key.expect.md @@ -0,0 +1,45 @@ + +## Input + +```javascript +function Test() { + const obj = { + 21: 'dimaMachina' + } + return
{obj[21]}
+} + +export const FIXTURE_ENTRYPOINT = { + fn: Test, + params: [{}], +}; + +``` + +## Code + +```javascript +import { c as _c } from "react/compiler-runtime"; +function Test() { + const $ = _c(1); + let t0; + if ($[0] === Symbol.for("react.memo_cache_sentinel")) { + const obj = { 21: "dimaMachina" }; + + t0 =
{obj[21]}
; + $[0] = t0; + } else { + t0 = $[0]; + } + return t0; +} + +export const FIXTURE_ENTRYPOINT = { + fn: Test, + params: [{}], +}; + +``` + +### Eval output +(kind: ok)
dimaMachina
\ No newline at end of file diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/numeric-literal-as-object-property-key.js b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/numeric-literal-as-object-property-key.js new file mode 100644 index 0000000000000..5496e57b27cb6 --- /dev/null +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/numeric-literal-as-object-property-key.js @@ -0,0 +1,11 @@ +function Test() { + const obj = { + 21: 'dimaMachina' + } + return
{obj[21]}
+} + +export const FIXTURE_ENTRYPOINT = { + fn: Test, + params: [{}], +};