Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2104,7 +2104,7 @@ function codegenInstructionValue(
key,
fn.params,
fn.body,
false,
property.key.kind === 'computed',
);
babelNode.async = fn.async;
babelNode.generator = fn.generator;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@

## Input

```javascript
const computedPropKey = 'foobar';

function Component(props) {
const obj = {
[computedPropKey]() {
return props.value;
},
};
return obj[computedPropKey]();
}

export const FIXTURE_ENTRYPOINT = {
fn: Component,
params: [{value: 42}],
};

```

## Code

```javascript
import { c as _c } from "react/compiler-runtime";
const computedPropKey = "foobar";

function Component(props) {
const $ = _c(2);
let t0;
if ($[0] !== props) {
const obj = {
[computedPropKey]() {
return props.value;
},
};
t0 = obj[computedPropKey]();
$[0] = props;
$[1] = t0;
} else {
t0 = $[1];
}
return t0;
}

export const FIXTURE_ENTRYPOINT = {
fn: Component,
params: [{ value: 42 }],
};

```

### Eval output
(kind: ok) 42
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
const computedPropKey = 'foobar';

function Component(props) {
const obj = {
[computedPropKey]() {
return props.value;
},
};
return obj[computedPropKey]();
}

export const FIXTURE_ENTRYPOINT = {
fn: Component,
params: [{value: 42}],
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
const computedPropKey = 'foobar';

function Bar({obj}: {obj: any}) {
return <div>{obj[computedPropKey]()}</div>;
}

function Component() {
return (
<div>
<Bar
obj={{
[computedPropKey]() {
return 'Hello';
},
}}
/>
</div>
);
}

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