-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
StubArray
workaround is incompatible with terser's unsafe_arrows
option
#3825
Comments
Do you have an idea for workaround? |
It's hard to say. TBH I'm not exactly sure why this workaround even exists! In that commit I can see that there used to be some code that mutated the prototype - but that code is long since gone -- in v6 from the looks of it based on this comment: mobx/packages/mobx/src/types/legacyobservablearray.ts Lines 51 to 53 in 58d4328
Seems to me like this code could just be |
It also seems odd to me that MobX's build process downlevels classes to functions since all browser have had support since around 2016. |
This workaround is not fixable I think as the arrow functions cannot act as base classes. The reason this downlevels this way is IIRC because when proxies are not used, this was the only way to reasonably correct inherit from the built-in array. If I know it was a limitation in the past, and disabling proxies and using legacy array in the first place, is probably to target something from the past :) (Will be removed in next major) |
Intended outcome:
MobX should work with terser's
unsafe_arrows
optimisation option.Actual outcome:
Info
mobx/packages/mobx/src/types/legacyobservablearray.ts
Lines 38 to 49 in 58d4328
The mobx codebases utilises an empty class here.
This empty class is downlevelled by mobx's build process to be
var StubArray = function StubArray() {};
(unpkg).When terser runs with the [
unsafe_arrows
](https://terser.org/docs/options/#:~:text=unsafe_arrows%20(default%3A,2015%20or%20greater.) option it will convert allfunction
s that don't referencethis
to an arrow, converting the above line tovar StubArray = () => {}
. This then breaks theinherit
function which assumesStubArray.proto
is defined.Note:
unsafe_arrows
is (by definition) an unsafe optimisation - though in my experience it is generally safe because it's so rare to do operations on a function's prototype (outside of old-school "class" code).It would be great if this line could be changed to make mobx more minifyable.
The text was updated successfully, but these errors were encountered: