-
Notifications
You must be signed in to change notification settings - Fork 47k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[compiler] Support for member expression inc/decrement
Test Plan: Builds support for a.x++ and friends. Similar to a.x += y, emits it as an assignment expression. ghstack-source-id: 8f3979913aad561cdba70464c3cc5f0ee95887b5 Pull Request resolved: #30697
- Loading branch information
Showing
4 changed files
with
135 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
...abel-plugin-react-compiler/src/__tests__/fixtures/compiler/member-inc.expect.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
|
||
## Input | ||
|
||
```javascript | ||
//@flow | ||
|
||
component Foo() { | ||
let x = {a: 1}; | ||
x.a++; | ||
x.a--; | ||
console.log(++x.a); | ||
console.log(x.a++); | ||
|
||
console.log(x.a); | ||
let y = x.a++; | ||
console.log(y); | ||
console.log(x.a); | ||
|
||
console.log((++x.a).toString(), (x.a++).toString(), x.a); | ||
} | ||
|
||
export const FIXTURE_ENTRYPOINT = { | ||
fn: Foo, | ||
params: [], | ||
}; | ||
|
||
``` | ||
|
||
## Code | ||
|
||
```javascript | ||
function Foo() { | ||
const x = { a: 1 }; | ||
x.a = x.a + 1; | ||
x.a = x.a - 1; | ||
console.log((x.a = x.a + 1)); | ||
const t0 = x.a; | ||
x.a = t0 + 1; | ||
console.log(t0); | ||
|
||
console.log(x.a); | ||
const t1 = x.a; | ||
x.a = t1 + 1; | ||
const y = t1; | ||
console.log(y); | ||
console.log(x.a); | ||
|
||
const t2 = (x.a = x.a + 1).toString(); | ||
const t3 = x.a; | ||
x.a = t3 + 1; | ||
console.log(t2, t3.toString(), x.a); | ||
} | ||
|
||
export const FIXTURE_ENTRYPOINT = { | ||
fn: Foo, | ||
params: [], | ||
}; | ||
|
||
``` | ||
### Eval output | ||
(kind: ok) | ||
logs: [2,2,3,3,4,'5','5',6] |
21 changes: 21 additions & 0 deletions
21
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/member-inc.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
//@flow | ||
|
||
component Foo() { | ||
let x = {a: 1}; | ||
x.a++; | ||
x.a--; | ||
console.log(++x.a); | ||
console.log(x.a++); | ||
|
||
console.log(x.a); | ||
let y = x.a++; | ||
console.log(y); | ||
console.log(x.a); | ||
|
||
console.log((++x.a).toString(), (x.a++).toString(), x.a); | ||
} | ||
|
||
export const FIXTURE_ENTRYPOINT = { | ||
fn: Foo, | ||
params: [], | ||
}; |