feat(minifier): substitute function.call(this) for iife#16619
feat(minifier): substitute function.call(this) for iife#16619armano2 wants to merge 8 commits intooxc-project:mainfrom
Conversation
Merging this PR will not alter performance
Comparing Footnotes
|
| test("(function* test () {foo()}).call(this)", "(function* () {foo()}).call(this)"); | ||
| test("(function* test () {}).call(this)", "(function* () {}).call(this)"); | ||
| test("(async function test(){foo()}).call(this)", "(async function (){foo()}).call(this)"); | ||
| test_same("(function test() {console.log(test.name)}).call(this)"); |
There was a problem hiding this comment.
| test_same("(function test() {console.log(test.name)}).call(this)"); | |
| test_same("(function test() {console.log(test.name)}).call(this)"); | |
| test_same("(function () {console.log(arguments)}).call(this)"); | |
| test_same("(function () {console.log(new.target)}).call(this)"); |
We need to handle these two cases.
There's also this behavior difference. But I didn't find a way to trigger it with IIFEs.
The thisArg value is passed without modification as the this value. This is a change from Edition 3, where an undefined or null thisArg is replaced with the global object and ToObject is applied to all other values and that result is passed as the this value. Even though the thisArg is passed without modification, non-strict functions still perform these transformations upon entry to the function.
https://tc39.es/ecma262/2025/multipage/fundamental-objects.html#sec-function.prototype.call
There was a problem hiding this comment.
this is actually going to be hard, i have hard time finding a way to check all nodes outside of adding impl for Visit,
i'm actually surprised that scope don't contain more information's
either by setting a bitmask flag or using references like state,
ThisExpression->thisIdentifier->arguments()Super->superMetaProperty->new.target
q, and toughts?
iterating over entire tree is not optimal, eg, loadsh wraps entire codebase in iff like call, and if user imports any iffe package, this can degrade performance just to remove few bytes
There was a problem hiding this comment.
I don't have an idea here. @Boshen What do you think?
…ction_call_bind_this_for_iife
there is a need for an asusmption here that user has not modified
Function.prototype.callto do something else