* Processes the provided function expression. * @private * @param {FunctionExpression | ArrowFunctionExpression} functionExpression function expression * @param {(Expression | SpreadElement)[]} options options * @param {Expression | SpreadElement | null} currentThis current this
(functionExpression, options, currentThis)
| 4061 | * @param {Expression | SpreadElement | null} currentThis current this |
| 4062 | */ |
| 4063 | _walkIIFE(functionExpression, options, currentThis) { |
| 4064 | /** |
| 4065 | * Returns var info. |
| 4066 | * @param {Expression | SpreadElement} argOrThis arg or this |
| 4067 | * @returns {string | VariableInfo | undefined} var info |
| 4068 | */ |
| 4069 | const getVarInfo = (argOrThis) => { |
| 4070 | const renameIdentifier = this.getRenameIdentifier(argOrThis); |
| 4071 | if ( |
| 4072 | renameIdentifier && |
| 4073 | this.callHooksForInfo( |
| 4074 | this.hooks.canRename, |
| 4075 | renameIdentifier, |
| 4076 | /** @type {Expression} */ |
| 4077 | (argOrThis) |
| 4078 | ) && |
| 4079 | !this.callHooksForInfo( |
| 4080 | this.hooks.rename, |
| 4081 | renameIdentifier, |
| 4082 | /** @type {Expression} */ |
| 4083 | (argOrThis) |
| 4084 | ) |
| 4085 | ) { |
| 4086 | return typeof renameIdentifier === "string" |
| 4087 | ? /** @type {string} */ (this.getVariableInfo(renameIdentifier)) |
| 4088 | : renameIdentifier; |
| 4089 | } |
| 4090 | this.walkExpression(argOrThis); |
| 4091 | }; |
| 4092 | const { params, type } = functionExpression; |
| 4093 | const arrow = type === "ArrowFunctionExpression"; |
| 4094 | const renameThis = currentThis ? getVarInfo(currentThis) : null; |
| 4095 | const varInfoForArgs = options.map(getVarInfo); |
| 4096 | const wasTopLevel = this.scope.topLevelScope; |
| 4097 | this.scope.topLevelScope = wasTopLevel && arrow ? "arrow" : false; |
| 4098 | const scopeParams = |
| 4099 | /** @type {(Identifier | string)[]} */ |
| 4100 | (params.filter((identifier, idx) => !varInfoForArgs[idx])); |
| 4101 | |
| 4102 | // Add function name in scope for recursive calls |
| 4103 | if ( |
| 4104 | functionExpression.type === "FunctionExpression" && |
| 4105 | functionExpression.id |
| 4106 | ) { |
| 4107 | scopeParams.push(functionExpression.id.name); |
| 4108 | } |
| 4109 | |
| 4110 | this.inFunctionScope(true, scopeParams, () => { |
| 4111 | if (renameThis && !arrow) { |
| 4112 | this.setVariable("this", renameThis); |
| 4113 | } |
| 4114 | for (let i = 0; i < varInfoForArgs.length; i++) { |
| 4115 | const varInfo = varInfoForArgs[i]; |
| 4116 | if (!varInfo) continue; |
| 4117 | if (!params[i] || params[i].type !== "Identifier") continue; |
| 4118 | this.setVariable(/** @type {Identifier} */ (params[i]).name, varInfo); |
| 4119 | } |
| 4120 | if (functionExpression.body.type === "BlockStatement") { |
no test coverage detected