Prepacking this, with --instantRender (to trigger realm.arrayNestedOptimizedFunctionsEnabled, which is not otherwise directly exposed via the CLI)...
function f(a) {
return Array.from(a).map(function() {
function g() { return 21 + 21; }
__optimize(g);
return g;
});
}
__optimize(f);
...results in...
var f;
(function () {
var _$2 = this;
var _$3 = _$2.Array;
var _$4 = _$3.from;
var _1 = function (a) {
var _5 = function () {
var _8 = function () {
return 21 + 21;
};
return _8;
};
var _$0 = _$4(a);
var _$1 = _$0.map(_5);
return _$1;
};
_$2.f = _1;
}).call(this);
Note that _8 did NOT get optimized!
Also note that this message was produced:
In input file /tmp/test.js(3:5) RecoverableError PP1008: Called __optimize on function in failed speculative context (https://github.com/facebook/prepack/wiki/PP1008)
Not helpful, rather confusing, but likely related?