7
8
import * as t from "@babel/types";
9
import { createHmac } from "crypto";
10
-import { pruneHoistedContexts, pruneUnusedLValues, pruneUnusedLabels } from ".";
10
+import {
11
+ pruneHoistedContexts,
12
+ pruneUnusedLValues,
13
+ pruneUnusedLabels,
14
+ renameVariables,
15
+} from ".";
16
import { CompilerError, ErrorSeverity } from "../CompilerError";
17
import { Environment, EnvironmentConfig, ExternalFunction } from "../HIR";
18
import {
41
ValidIdentifierName,
42
getHookKind,
43
makeIdentifierName,
44
+ promoteTemporary,
45
} from "../HIR/HIR";
46
import { printIdentifier, printPlace } from "../HIR/PrintHIR";
47
import { eachPatternOperand } from "../HIR/visitors";
51
import { buildReactiveFunction } from "./BuildReactiveFunction";
52
import { SINGLE_CHILD_FBT_TAGS } from "./MemoizeFbtAndMacroOperandsInSameScope";
53
import { ReactiveFunctionVisitor, visitReactiveFunction } from "./visitors";
54
+import { ReactFunctionType } from "../HIR/Environment";
55
+import { logReactiveFunction } from "../Utils/logger";
56
57
export const MEMO_CACHE_SENTINEL = "react.memo_cache_sentinel";
58
export const EARLY_RETURN_SENTINEL = "react.early_return_sentinel";
93
* because they were part of a pruned memo block.
94
*/
95
prunedMemoValues: number;
96
+
97
+ outlined: Array<{
98
+ fn: CodegenFunction;
99
+ type: ReactFunctionType | null;
100
+ }>;
101
};
102
103
export function codegenFunction(
271
compiled.body.body.unshift(test);
272
}
273
274
+ const outlined: CodegenFunction["outlined"] = [];
275
+ for (const { fn: outlinedFunction, type } of cx.env.getOutlinedFunctions()) {
276
+ const reactiveFunction = buildReactiveFunction(outlinedFunction);
277
+ pruneUnusedLabels(reactiveFunction);
278
+ pruneUnusedLValues(reactiveFunction);
279
+ pruneHoistedContexts(reactiveFunction);
280
+
281
+ /*
282
+ * TODO: temporary function params (due to destructuring) should always be
283
+ * promoted so that they can be renamed
284
+ */
285
+ for (const param of reactiveFunction.params) {
286
+ const place = param.kind === "Identifier" ? param : param.place;
287
+ if (place.identifier.name === null) {
288
+ promoteTemporary(place.identifier);
289
+ }
290
+ }
291
+ const identifiers = renameVariables(reactiveFunction);
292
+ logReactiveFunction("Outline", reactiveFunction);
293
+ const codegen = codegenReactiveFunction(
294
+ new Context(
295
+ cx.env,
296
+ reactiveFunction.id ?? "[[ anonymous ]]",
297
+ identifiers
298
+ ),
299
+ reactiveFunction
300
+ );
301
+ if (codegen.isErr()) {
302
+ return codegen;
303
+ }
304
+ outlined.push({ fn: codegen.unwrap(), type });
305
+ }
306
+ compiled.outlined = outlined;
307
+
308
return compileResult;
309
}
310
353
memoValues: countMemoBlockVisitor.memoValues,
354
prunedMemoBlocks: countMemoBlockVisitor.prunedMemoBlocks,
355
prunedMemoValues: countMemoBlockVisitor.prunedMemoValues,
356
+ outlined: [],
357
});
358
}
359