Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(react-compiler): implement NumericLiteral as ObjectPropertyKey #31791

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -1455,6 +1455,11 @@ function lowerObjectPropertyKey(
kind: 'identifier',
name: key.node.name,
};
} else if (key.isNumericLiteral()) {
return {
kind: 'identifier',
name: String(key.node.value),
};
}

builder.errors.push({
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@

## Input

```javascript
function Test() {
const obj = {
21: 'dimaMachina'
}
return <div>{obj[21]}</div>
}

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 = <div>{obj[21]}</div>;
$[0] = t0;
} else {
t0 = $[0];
}
return t0;
}

export const FIXTURE_ENTRYPOINT = {
fn: Test,
params: [{}],
};

```

### Eval output
(kind: ok) <div>dimaMachina</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
function Test() {
const obj = {
21: 'dimaMachina',
};
return <div>{obj[21]}</div>;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

please add a fixture here so that we can test evaluation with/without compilation:

export const FIXTURE_ENTRYPOINT = {
  fn: Test,
  params: [{}],
};

Copy link
Contributor

Choose a reason for hiding this comment

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

also be sure to update fixtures after this

Copy link
Author

Choose a reason for hiding this comment

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

Thank you! Updated! Could you also review my other contribution to the react compiler? #31792

I just pushed there similar change 🙂


export const FIXTURE_ENTRYPOINT = {
fn: Test,
params: [{}],
};
Loading