[fix] consistently import from react

Instead of a combination of `react` and `React`, consistently use `react` which 
is the preferred name to import.
This commit is contained in:
Jan Kassens
2022-10-25 11:00:27 -04:00
parent 34e02dab32
commit eb13f84b2d
2 changed files with 41 additions and 54 deletions
+41 -47
View File
@@ -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) {
-7
View File
@@ -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;
}
}