@samitouri / QOS-React / commits / eb13f84b2d

[fix] consistently import from `react`

Instead of a combination of `react` and `React`, consistently use `react` which is the preferred name to import.

Jan Kassens committed Oct 25, 2022 at 11:00 UTC eb13f84b2df59dec1d413c5f0347d0b69a82d968
2 files changed +41 -54
compiler/forget/src/BackEnd/JSGen.ts
+41 -47
@@ -28,63 +28,57 @@ export default {
28 };
29
30 export function run(lirProg: LIR.Prog, context: CompilerContext) {
31 - if (lirProg.importUseMemoCache()) {
32 - const prog = lirProg.ir.ast;
31 + if (lirProg.funcs.size === 0) {
32 + return;
33 + }
34 +
35 + const prog = lirProg.ir.ast;
36 + const utils = ["$empty"];
37 + if (context.opts.flags.guardHooks) {
38 + utils.push("$startLazy", "$endLazy");
39 + }
40 + if (context.opts.flags.guardReads) {
41 + utils.push("$read");
42 + }
43 + if (context.opts.flags.addFreeze) {
44 + utils.push("$makeReadOnly");
45 + }
46 + if (utils.length > 0) {
47 + prog.unshiftContainer(
48 + "body",
49 + t.variableDeclaration("const", [
50 + t.variableDeclarator(
51 + t.objectPattern(
52 + utils.map((util) =>
53 + t.objectProperty(
54 + t.identifier(util),
55 + t.identifier(util),
56 + false,
57 + true,
58 + null
59 + )
60 + )
61 + ),
62 + t.identifier("$ForgetRuntime")
63 + ),
64 + ])
65 + );
66 prog.unshiftContainer(
67 "body",
68 t.importDeclaration(
36 - /*specifier*/ [
69 + [
70 t.importSpecifier(
71 t.identifier("useMemoCache"),
72 t.identifier("unstable_useMemoCache")
73 ),
74 + t.importSpecifier(
75 + t.identifier("$ForgetRuntime"),
76 + t.identifier("unstable_ForgetRuntime")
77 + ),
78 ],
42 - /*source*/ t.stringLiteral("react")
79 + t.stringLiteral("react")
80 )
81 );
45 - const utils = ["$empty"];
46 - if (context.opts.flags.guardHooks) {
47 - utils.push("$startLazy", "$endLazy");
48 - }
49 - if (context.opts.flags.guardReads) {
50 - utils.push("$read");
51 - }
52 - if (context.opts.flags.addFreeze) {
53 - utils.push("$makeReadOnly");
54 - }
55 - if (utils.length > 0) {
56 - prog.unshiftContainer(
57 - "body",
58 - t.variableDeclaration("const", [
59 - t.variableDeclarator(
60 - t.objectPattern(
61 - utils.map((util) =>
62 - t.objectProperty(
63 - t.identifier(util),
64 - t.identifier(util),
65 - false,
66 - true,
67 - null
68 - )
69 - )
70 - ),
71 - t.identifier("$ForgetRuntime")
72 - ),
73 - ])
74 - );
75 - prog.unshiftContainer(
76 - "body",
77 - t.importDeclaration(
78 - [
79 - t.importSpecifier(
80 - t.identifier("$ForgetRuntime"),
81 - t.identifier("unstable_ForgetRuntime")
82 - ),
83 - ],
84 - t.stringLiteral("React")
85 - )
86 - );
87 - }
82 }
83
84 for (const [irFunc, lirFunc] of lirProg.funcs) {
compiler/forget/src/LIR/Prog.ts
-7
@@ -16,11 +16,4 @@ export class Prog {
16 constructor(ir: IR.Prog) {
17 this.ir = ir;
18 }
19 -
20 - /**
21 - * @return whether or not this prog needs to import useMemoCache.
22 - */
23 - importUseMemoCache(): boolean {
24 - return this.funcs.size > 0;
25 - }
19 }