`StubArray` workaround is incompatible with terser's `unsafe_arrows` option
bradzacher opened this issue · comments
Intended outcome:
MobX should work with terser's unsafe_arrows
optimisation option.
Actual outcome:
TypeError: Object.setPrototypeOf called on null or undefined
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 all function
s that don't reference this
to an arrow, converting the above line to var StubArray = () => {}
. This then breaks the inherit
function which assumes StubArray.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.