[compiler] Handle TSInstantiationExpression in lowerExpression (#32302)
Fix #31745
inottn committed
Feb 4, 2025 at 00:41 UTC
10a4c88f58233074f293ab387b73e96b67192538
3 files changed
+58
compiler/packages/babel-plugin-react-compiler/src/HIR/BuildHIR.ts
+1
@@ -2528,6 +2528,7 @@ function lowerExpression(
2528
loc: expr.node.loc ?? GeneratedSource,
2529
};
2530
}
2531
+ case 'TSInstantiationExpression':
2532
case 'TSNonNullExpression': {
2533
let expr = exprPath as NodePath<t.TSNonNullExpression>;
2534
return lowerExpression(builder, expr.get('expression'));
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/ts-instantiation-expression.expect.md
new
+46
@@ -0,0 +1,46 @@
1
+
2
+## Input
3
+
4
+```javascript
5
+import {identity, invoke} from 'shared-runtime';
6
+
7
+function Test() {
8
+ const str = invoke(identity<string>, 'test');
9
+ return str;
10
+}
11
+
12
+export const FIXTURE_ENTRYPOINT = {
13
+ fn: Test,
14
+ params: [],
15
+};
16
+
17
+```
18
+
19
+## Code
20
+
21
+```javascript
22
+import { c as _c } from "react/compiler-runtime";
23
+import { identity, invoke } from "shared-runtime";
24
+
25
+function Test() {
26
+ const $ = _c(1);
27
+ let t0;
28
+ if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
29
+ t0 = invoke(identity, "test");
30
+ $[0] = t0;
31
+ } else {
32
+ t0 = $[0];
33
+ }
34
+ const str = t0;
35
+ return str;
36
+}
37
+
38
+export const FIXTURE_ENTRYPOINT = {
39
+ fn: Test,
40
+ params: [],
41
+};
42
+
43
+```
44
+
45
+### Eval output
46
+(kind: ok) "test"
\ No newline at end of file
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/ts-instantiation-expression.tsx
new
+11
@@ -0,0 +1,11 @@
1
+import {identity, invoke} from 'shared-runtime';
2
+
3
+function Test() {
4
+ const str = invoke(identity<string>, 'test');
5
+ return str;
6
+}
7
+
8
+export const FIXTURE_ENTRYPOINT = {
9
+ fn: Test,
10
+ params: [],
11
+};