-
Notifications
You must be signed in to change notification settings - Fork 48.8k
fix(react-compiler): implement NumericLiteral as ObjectPropertyKey #31791
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
Changes from all commits
b308f0a
59f2dd1
52249bc
cad3a8b
9e8d664
89226f8
fe5eef5
d8c069b
6928ae4
ca6a0b2
5fb9684
fcc2cba
5499ae1
1fb22ae
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
|
||
## Input | ||
|
||
```javascript | ||
function Test() { | ||
const obj = { | ||
21: 'dimaMachina', | ||
}; | ||
// Destructuring assignment | ||
const {21: myVar} = obj; | ||
return ( | ||
<div> | ||
{obj[21]} | ||
{myVar} | ||
</div> | ||
); | ||
} | ||
|
||
export const FIXTURE_ENTRYPOINT = { | ||
fn: Test, | ||
params: [{}], | ||
}; | ||
|
||
``` | ||
|
||
## Code | ||
|
||
```javascript | ||
import { c as _c } from "react/compiler-runtime"; | ||
function Test() { | ||
const $ = _c(2); | ||
let t0; | ||
if ($[0] === Symbol.for("react.memo_cache_sentinel")) { | ||
t0 = { 21: "dimaMachina" }; | ||
$[0] = t0; | ||
} else { | ||
t0 = $[0]; | ||
} | ||
const obj = t0; | ||
|
||
const { 21: myVar } = obj; | ||
let t1; | ||
if ($[1] === Symbol.for("react.memo_cache_sentinel")) { | ||
t1 = ( | ||
<div> | ||
{obj[21]} | ||
{myVar} | ||
</div> | ||
); | ||
$[1] = t1; | ||
} else { | ||
t1 = $[1]; | ||
} | ||
return t1; | ||
} | ||
|
||
export const FIXTURE_ENTRYPOINT = { | ||
fn: Test, | ||
params: [{}], | ||
}; | ||
|
||
``` | ||
|
||
### Eval output | ||
(kind: ok) <div>dimaMachinadimaMachina</div> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
function Test() { | ||
const obj = { | ||
21: 'dimaMachina', | ||
}; | ||
// Destructuring assignment | ||
const {21: myVar} = obj; | ||
return ( | ||
<div> | ||
{obj[21]} | ||
{myVar} | ||
</div> | ||
); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. also be sure to update fixtures after this There was a problem hiding this comment. Choose a reason for hiding this commentThe 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: [{}], | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's also avoid converting numeric literals to babel identifiers. Could you
t.numericLiteral
Let's also add a test case for destructuring assignment, which also uses ObjectExpressions
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mofeiZ thanks for your review, done in 5499ae1
Should I move
destructuring assignment
test to a separate file?Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome, thanks for the quick fix! Just started a test run and will merge once everything passes
This should be fine.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great, updated snapshot in 1fb22ae