-
Notifications
You must be signed in to change notification settings - Fork 46.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Summary: Builds support for macros that are invoked as methods rather than just function calls or jsx. We now record macros as a schema that represents arbitrary member expressions including wildcards (so we can support, e.g., myMacro.*.foo.bar). When examining PropertyLoads in the macro memoization stage, we build up a map of partially-satisfied macro patterns until we determine that the pattern has been fully satisfied, at which point we treat the result of the PropertyLoad as a macro value. ghstack-source-id: d78d9ba7041968c861ffa110fb7882b339a0e257 Pull Request resolved: #30589
- Loading branch information
Showing
8 changed files
with
378 additions
and
17 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
122 changes: 122 additions & 0 deletions
122
...iler/src/__tests__/fixtures/compiler/idx-method-no-outlining-wildcard.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,122 @@ | ||
|
||
## Input | ||
|
||
```javascript | ||
// @customMacros(idx.*.b) | ||
|
||
function Component(props) { | ||
// outlined | ||
const groupName1 = idx(props, _ => _.group.label); | ||
// outlined | ||
const groupName2 = idx.a(props, _ => _.group.label); | ||
// not outlined | ||
const groupName3 = idx.a.b(props, _ => _.group.label); | ||
// not outlined | ||
const groupName4 = idx.hello_world.b(props, _ => _.group.label); | ||
// outlined | ||
const groupName5 = idx.hello_world.b.c(props, _ => _.group.label); | ||
return ( | ||
<div> | ||
{groupName1} | ||
{groupName2} | ||
{groupName3} | ||
{groupName4} | ||
{groupName5} | ||
</div> | ||
); | ||
} | ||
|
||
``` | ||
|
||
## Code | ||
|
||
```javascript | ||
import { c as _c } from "react/compiler-runtime"; // @customMacros(idx.*.b) | ||
|
||
function Component(props) { | ||
const $ = _c(16); | ||
let t0; | ||
if ($[0] !== props) { | ||
t0 = idx(props, _temp); | ||
$[0] = props; | ||
$[1] = t0; | ||
} else { | ||
t0 = $[1]; | ||
} | ||
const groupName1 = t0; | ||
let t1; | ||
if ($[2] !== props) { | ||
t1 = idx.a(props, _temp2); | ||
$[2] = props; | ||
$[3] = t1; | ||
} else { | ||
t1 = $[3]; | ||
} | ||
const groupName2 = t1; | ||
let t2; | ||
if ($[4] !== props) { | ||
t2 = idx.a.b(props, (__1) => __1.group.label); | ||
$[4] = props; | ||
$[5] = t2; | ||
} else { | ||
t2 = $[5]; | ||
} | ||
const groupName3 = t2; | ||
let t3; | ||
if ($[6] !== props) { | ||
t3 = idx.hello_world.b(props, (__2) => __2.group.label); | ||
$[6] = props; | ||
$[7] = t3; | ||
} else { | ||
t3 = $[7]; | ||
} | ||
const groupName4 = t3; | ||
let t4; | ||
if ($[8] !== props) { | ||
t4 = idx.hello_world.b.c(props, _temp3); | ||
$[8] = props; | ||
$[9] = t4; | ||
} else { | ||
t4 = $[9]; | ||
} | ||
const groupName5 = t4; | ||
let t5; | ||
if ( | ||
$[10] !== groupName1 || | ||
$[11] !== groupName2 || | ||
$[12] !== groupName3 || | ||
$[13] !== groupName4 || | ||
$[14] !== groupName5 | ||
) { | ||
t5 = ( | ||
<div> | ||
{groupName1} | ||
{groupName2} | ||
{groupName3} | ||
{groupName4} | ||
{groupName5} | ||
</div> | ||
); | ||
$[10] = groupName1; | ||
$[11] = groupName2; | ||
$[12] = groupName3; | ||
$[13] = groupName4; | ||
$[14] = groupName5; | ||
$[15] = t5; | ||
} else { | ||
t5 = $[15]; | ||
} | ||
return t5; | ||
} | ||
function _temp3(__3) { | ||
return __3.group.label; | ||
} | ||
function _temp2(__0) { | ||
return __0.group.label; | ||
} | ||
function _temp(_) { | ||
return _.group.label; | ||
} | ||
|
||
``` | ||
23 changes: 23 additions & 0 deletions
23
...plugin-react-compiler/src/__tests__/fixtures/compiler/idx-method-no-outlining-wildcard.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,23 @@ | ||
// @customMacros(idx.*.b) | ||
|
||
function Component(props) { | ||
// outlined | ||
const groupName1 = idx(props, _ => _.group.label); | ||
// outlined | ||
const groupName2 = idx.a(props, _ => _.group.label); | ||
// not outlined | ||
const groupName3 = idx.a.b(props, _ => _.group.label); | ||
// not outlined | ||
const groupName4 = idx.hello_world.b(props, _ => _.group.label); | ||
// outlined | ||
const groupName5 = idx.hello_world.b.c(props, _ => _.group.label); | ||
return ( | ||
<div> | ||
{groupName1} | ||
{groupName2} | ||
{groupName3} | ||
{groupName4} | ||
{groupName5} | ||
</div> | ||
); | ||
} |
Oops, something went wrong.