From eb13f84b2df59dec1d413c5f0347d0b69a82d968 Mon Sep 17 00:00:00 2001 From: Jan Kassens Date: Tue, 25 Oct 2022 11:00:27 -0400 Subject: [PATCH] [fix] consistently import from `react` Instead of a combination of `react` and `React`, consistently use `react` which is the preferred name to import. --- compiler/forget/src/BackEnd/JSGen.ts | 88 +++++++++++++--------------- compiler/forget/src/LIR/Prog.ts | 7 --- 2 files changed, 41 insertions(+), 54 deletions(-) diff --git a/compiler/forget/src/BackEnd/JSGen.ts b/compiler/forget/src/BackEnd/JSGen.ts index a5e2937bb6..98adc902d7 100644 --- a/compiler/forget/src/BackEnd/JSGen.ts +++ b/compiler/forget/src/BackEnd/JSGen.ts @@ -28,63 +28,57 @@ export default { }; export function run(lirProg: LIR.Prog, context: CompilerContext) { - if (lirProg.importUseMemoCache()) { - const prog = lirProg.ir.ast; + if (lirProg.funcs.size === 0) { + return; + } + + const prog = lirProg.ir.ast; + const utils = ["$empty"]; + if (context.opts.flags.guardHooks) { + utils.push("$startLazy", "$endLazy"); + } + if (context.opts.flags.guardReads) { + utils.push("$read"); + } + if (context.opts.flags.addFreeze) { + utils.push("$makeReadOnly"); + } + if (utils.length > 0) { + prog.unshiftContainer( + "body", + t.variableDeclaration("const", [ + t.variableDeclarator( + t.objectPattern( + utils.map((util) => + t.objectProperty( + t.identifier(util), + t.identifier(util), + false, + true, + null + ) + ) + ), + t.identifier("$ForgetRuntime") + ), + ]) + ); prog.unshiftContainer( "body", t.importDeclaration( - /*specifier*/ [ + [ t.importSpecifier( t.identifier("useMemoCache"), t.identifier("unstable_useMemoCache") ), + t.importSpecifier( + t.identifier("$ForgetRuntime"), + t.identifier("unstable_ForgetRuntime") + ), ], - /*source*/ t.stringLiteral("react") + t.stringLiteral("react") ) ); - const utils = ["$empty"]; - if (context.opts.flags.guardHooks) { - utils.push("$startLazy", "$endLazy"); - } - if (context.opts.flags.guardReads) { - utils.push("$read"); - } - if (context.opts.flags.addFreeze) { - utils.push("$makeReadOnly"); - } - if (utils.length > 0) { - prog.unshiftContainer( - "body", - t.variableDeclaration("const", [ - t.variableDeclarator( - t.objectPattern( - utils.map((util) => - t.objectProperty( - t.identifier(util), - t.identifier(util), - false, - true, - null - ) - ) - ), - t.identifier("$ForgetRuntime") - ), - ]) - ); - prog.unshiftContainer( - "body", - t.importDeclaration( - [ - t.importSpecifier( - t.identifier("$ForgetRuntime"), - t.identifier("unstable_ForgetRuntime") - ), - ], - t.stringLiteral("React") - ) - ); - } } for (const [irFunc, lirFunc] of lirProg.funcs) { diff --git a/compiler/forget/src/LIR/Prog.ts b/compiler/forget/src/LIR/Prog.ts index d5850c3bf6..f1f2fe585c 100644 --- a/compiler/forget/src/LIR/Prog.ts +++ b/compiler/forget/src/LIR/Prog.ts @@ -16,11 +16,4 @@ export class Prog { constructor(ir: IR.Prog) { this.ir = ir; } - - /** - * @return whether or not this prog needs to import useMemoCache. - */ - importUseMemoCache(): boolean { - return this.funcs.size > 0; - } }