-
Notifications
You must be signed in to change notification settings - Fork 47.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[rfc] Desugar FunctionDeclaration to a FunctionExpression
- Loading branch information
Showing
12 changed files
with
237 additions
and
10 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
38 changes: 38 additions & 0 deletions
38
compiler/forget/src/__tests__/fixtures/compiler/capturing-function-decl.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,38 @@ | ||
|
||
## Input | ||
|
||
```javascript | ||
function component(a) { | ||
let t = { a }; | ||
function x() { | ||
t.foo(); | ||
} | ||
x(t); | ||
return t; | ||
} | ||
|
||
``` | ||
|
||
## Code | ||
|
||
```javascript | ||
function component(a) { | ||
const $ = React.unstable_useMemoCache(2); | ||
const c_0 = $[0] !== a; | ||
let t; | ||
if (c_0) { | ||
t = { a }; | ||
const x = function x() { | ||
t.foo(); | ||
}; | ||
x(t); | ||
$[0] = a; | ||
$[1] = t; | ||
} else { | ||
t = $[1]; | ||
} | ||
return t; | ||
} | ||
|
||
``` | ||
8 changes: 8 additions & 0 deletions
8
compiler/forget/src/__tests__/fixtures/compiler/capturing-function-decl.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,8 @@ | ||
function component(a) { | ||
let t = { a }; | ||
function x() { | ||
t.foo(); | ||
} | ||
x(t); | ||
return t; | ||
} |
23 changes: 23 additions & 0 deletions
23
...et/src/__tests__/fixtures/compiler/error.hoisted-function-declaration.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,23 @@ | ||
|
||
## Input | ||
|
||
```javascript | ||
function component(a) { | ||
let t = { a }; | ||
x(t); // hoisted call | ||
function x(p) { | ||
p.foo(); | ||
} | ||
return t; | ||
} | ||
|
||
``` | ||
|
||
|
||
## Error | ||
|
||
``` | ||
[ReactForget] Invariant: identifier x$6 should have been defined before use (4:4) | ||
``` | ||
8 changes: 8 additions & 0 deletions
8
compiler/forget/src/__tests__/fixtures/compiler/error.hoisted-function-declaration.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,8 @@ | ||
function component(a) { | ||
let t = { a }; | ||
x(t); // hoisted call | ||
function x(p) { | ||
p.foo(); | ||
} | ||
return t; | ||
} |
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
32 changes: 32 additions & 0 deletions
32
.../forget/src/__tests__/fixtures/compiler/function-declaration-reassign.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,32 @@ | ||
|
||
## Input | ||
|
||
```javascript | ||
function component() { | ||
function x(a) { | ||
a.foo(); | ||
} | ||
x = {}; | ||
return x; | ||
} | ||
|
||
``` | ||
|
||
## Code | ||
|
||
```javascript | ||
function component() { | ||
const $ = React.unstable_useMemoCache(1); | ||
let t0; | ||
if ($[0] === Symbol.for("react.memo_cache_sentinel")) { | ||
t0 = {}; | ||
$[0] = t0; | ||
} else { | ||
t0 = $[0]; | ||
} | ||
const x = t0; | ||
return x; | ||
} | ||
|
||
``` | ||
7 changes: 7 additions & 0 deletions
7
compiler/forget/src/__tests__/fixtures/compiler/function-declaration-reassign.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,7 @@ | ||
function component() { | ||
function x(a) { | ||
a.foo(); | ||
} | ||
x = {}; | ||
return x; | ||
} |
32 changes: 32 additions & 0 deletions
32
...forget/src/__tests__/fixtures/compiler/function-declaration-redeclare.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,32 @@ | ||
|
||
## Input | ||
|
||
```javascript | ||
function component() { | ||
function x(a) { | ||
a.foo(); | ||
} | ||
function x() {} | ||
return x; | ||
} | ||
|
||
``` | ||
|
||
## Code | ||
|
||
```javascript | ||
function component() { | ||
const $ = React.unstable_useMemoCache(1); | ||
let t0; | ||
if ($[0] === Symbol.for("react.memo_cache_sentinel")) { | ||
t0 = function x() {}; | ||
$[0] = t0; | ||
} else { | ||
t0 = $[0]; | ||
} | ||
const x = t0; | ||
return x; | ||
} | ||
|
||
``` | ||
7 changes: 7 additions & 0 deletions
7
compiler/forget/src/__tests__/fixtures/compiler/function-declaration-redeclare.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,7 @@ | ||
function component() { | ||
function x(a) { | ||
a.foo(); | ||
} | ||
function x() {} | ||
return x; | ||
} |
38 changes: 38 additions & 0 deletions
38
...er/forget/src/__tests__/fixtures/compiler/function-declaration-simple.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,38 @@ | ||
|
||
## Input | ||
|
||
```javascript | ||
function component(a) { | ||
let t = { a }; | ||
function x(p) { | ||
p.foo(); | ||
} | ||
x(t); | ||
return t; | ||
} | ||
|
||
``` | ||
|
||
## Code | ||
|
||
```javascript | ||
function component(a) { | ||
const $ = React.unstable_useMemoCache(2); | ||
const c_0 = $[0] !== a; | ||
let t; | ||
if (c_0) { | ||
t = { a }; | ||
const x = function x(p) { | ||
p.foo(); | ||
}; | ||
x(t); | ||
$[0] = a; | ||
$[1] = t; | ||
} else { | ||
t = $[1]; | ||
} | ||
return t; | ||
} | ||
|
||
``` | ||
8 changes: 8 additions & 0 deletions
8
compiler/forget/src/__tests__/fixtures/compiler/function-declaration-simple.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,8 @@ | ||
function component(a) { | ||
let t = { a }; | ||
function x(p) { | ||
p.foo(); | ||
} | ||
x(t); | ||
return t; | ||
} |