Skip to content
This repository has been archived by the owner on Feb 12, 2022. It is now read-only.

Disable generation of .bind() calls instead of wrapper functions #2577

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions src/serializer/ResidualFunctions.js
Original file line number Diff line number Diff line change
Expand Up @@ -663,16 +663,22 @@ export class ResidualFunctions {
let firstUsage = this.firstFunctionUsages.get(functionValue);
// todo: why can this be undefined?
invariant(insertionPoint !== undefined);
if (
// The same free variables in shared instances may refer to objects with different initialization values
// so a stub forward function is needed during delay initializations.

let cannotBind =
this.residualFunctionInitializers.hasInitializerStatement(functionValue) ||
usesThis ||
hasFunctionArg ||
(firstUsage === undefined || !firstUsage.isNotEarlierThan(insertionPoint)) ||
this.functionPrototypes.get(functionValue) !== undefined ||
hasAnyLeakedIds
) {
hasAnyLeakedIds;

// TODO 2589: Code size reduction opportunity: bring back .bind calls
cannotBind = true;

if (cannotBind) {
// The same free variables in shared instances may refer to objects with different initialization values
// so a stub forward function is needed during delay initializations.

let callArgs: Array<BabelNodeExpression | BabelNodeSpreadElement> = [t.thisExpression()];
for (let flatArg of flatArgs) callArgs.push(flatArg);
for (let param of params) {
Expand Down