Intended outcome:
MobX should work with terser's unsafe_arrows optimisation option.
Actual outcome:
TypeError: Object.setPrototypeOf called on null or undefined
Info
|
// Typescript workaround to make sure ObservableArray extends Array |
|
class StubArray {} |
|
function inherit(ctor, proto) { |
|
if (Object.setPrototypeOf) { |
|
Object.setPrototypeOf(ctor.prototype, proto) |
|
} else if (ctor.prototype.__proto__ !== undefined) { |
|
ctor.prototype.__proto__ = proto |
|
} else { |
|
ctor.prototype = proto |
|
} |
|
} |
|
inherit(StubArray, Array.prototype) |
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 functions 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.
Intended outcome:
MobX should work with terser's
unsafe_arrowsoptimisation 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 allfunctions that don't referencethisto an arrow, converting the above line tovar StubArray = () => {}. This then breaks theinheritfunction which assumesStubArray.protois defined.Note:
unsafe_arrowsis (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.