Skip to content

Commit 5499ae1

Browse files
committed
apply more review fixes
1 parent fcc2cba commit 5499ae1

File tree

5 files changed

+45
-8
lines changed

5 files changed

+45
-8
lines changed

compiler/packages/babel-plugin-react-compiler/src/HIR/HIR.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -703,6 +703,10 @@ export type ObjectPropertyKey =
703703
| {
704704
kind: 'computed';
705705
name: Place;
706+
}
707+
| {
708+
kind: 'number';
709+
name: number;
706710
};
707711

708712
export type ObjectProperty = {

compiler/packages/babel-plugin-react-compiler/src/HIR/PrintHIR.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,9 @@ function printObjectPropertyKey(key: ObjectPropertyKey): string {
330330
case 'computed': {
331331
return `[${printPlace(key.name)}]`;
332332
}
333+
case 'number': {
334+
return String(key.name);
335+
}
333336
}
334337
}
335338

compiler/packages/babel-plugin-react-compiler/src/ReactiveScopes/CodegenReactiveFunction.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2429,6 +2429,9 @@ function codegenObjectPropertyKey(
24292429
});
24302430
return expr;
24312431
}
2432+
case 'number': {
2433+
return t.numericLiteral(key.name);
2434+
}
24322435
}
24332436
}
24342437

compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/numeric-literal-as-object-property-key.expect.md

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,14 @@ function Test() {
66
const obj = {
77
21: 'dimaMachina',
88
};
9-
return <div>{obj[21]}</div>;
9+
// Destructuring assignment
10+
const {21: myVar} = obj;
11+
return (
12+
<div>
13+
{obj[21]}
14+
{myVar}
15+
</div>
16+
);
1017
}
1118

1219
export const FIXTURE_ENTRYPOINT = {
@@ -21,17 +28,30 @@ export const FIXTURE_ENTRYPOINT = {
2128
```javascript
2229
import { c as _c } from "react/compiler-runtime";
2330
function Test() {
24-
const $ = _c(1);
31+
const $ = _c(2);
2532
let t0;
2633
if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
27-
const obj = { 21: "dimaMachina" };
28-
29-
t0 = <div>{obj[21]}</div>;
34+
t0 = { 21: "dimaMachina" };
3035
$[0] = t0;
3136
} else {
3237
t0 = $[0];
3338
}
34-
return t0;
39+
const obj = t0;
40+
41+
const { 21: myVar } = obj;
42+
let t1;
43+
if ($[1] === Symbol.for("react.memo_cache_sentinel")) {
44+
t1 = (
45+
<div>
46+
{obj[21]}
47+
{myVar}
48+
</div>
49+
);
50+
$[1] = t1;
51+
} else {
52+
t1 = $[1];
53+
}
54+
return t1;
3555
}
3656

3757
export const FIXTURE_ENTRYPOINT = {
@@ -42,4 +62,4 @@ export const FIXTURE_ENTRYPOINT = {
4262
```
4363
4464
### Eval output
45-
(kind: ok) <div>dimaMachina</div>
65+
(kind: ok) <div>dimaMachinadimaMachina</div>

compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/numeric-literal-as-object-property-key.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,14 @@ function Test() {
22
const obj = {
33
21: 'dimaMachina',
44
};
5-
return <div>{obj[21]}</div>;
5+
// Destructuring assignment
6+
const {21: myVar} = obj;
7+
return (
8+
<div>
9+
{obj[21]}
10+
{myVar}
11+
</div>
12+
);
613
}
714

815
export const FIXTURE_ENTRYPOINT = {

0 commit comments

Comments
 (0)