Not sure, if this is an issue or is it meant to be like this. I was just trying out prepack in the REPL and tried this code.
(function() {
ββlet opr = {
ββββ'sum': (x, y) => x + y,
ββββ'mul': (x, y) => x * y,
ββββ'div': (x, y) => x / y,
ββββ'dif': (x, y) => x - y
ββ};
ββ
ββlet operands = [
ββββ[1, 2],
ββββ[2, 3],
ββββ[3, 4],
ββββ[4, 5]
ββ];
ββββ
ββwindow.result = Object.keys(opr).map((key, index) => {
ββββreturn opr[key](...operands[index]);
ββ});
})();
This got compiled into:
result = [3, 6, 0.75, -1];
Which is awesome. But the thing I didn't understand is, as I converted the window.result global variable into a function without changing any other part of the code the initialized code wasn't eliminated at all.
Consider this code, all I changed was from window.result = to window.result = () =>:
(function() {
ββlet opr = {
ββββ'sum': (x, y) => x + y,
ββββ'mul': (x, y) => x * y,
ββββ'div': (x, y) => x / y,
ββββ'dif': (x, y) => x - y
ββ};
ββ
ββlet operands = [
ββββ[1, 2],
ββββ[2, 3],
ββββ[3, 4],
ββββ[4, 5]
ββ];
ββββ
ββwindow.result = () => Object.keys(opr).map((key, index) => {
ββββreturn opr[key](...operands[index]);
ββ});
})();
Now this gets compiled to:
(function () {
var _$0 = this;
function _0() {
return _$0.Object.keys(_1).map((key, index) => {
return _1[key](..._6[index]);
});
}
function _2(x, y) {
return x + y;
}
function _3(x, y) {
return x * y;
}
function _4(x, y) {
return x / y;
}
function _5(x, y) {
return x - y;
}
var _1 = {
sum: _2,
mul: _3,
div: _4,
dif: _5
};
var _6 = [[1, 2], [2, 3], [3, 4], [4, 5]];
result = _0;
}).call(this);
I was expecting the output to be something like this:
function result() {
return [3, 6, 0.75, -1];
}
But it didn't eliminate the computations at the compile time. IMO, these initializing codes in the second example should have been eliminated too, shouldn't it?
Prepack does not yet evaluate most functions that are not called on the initialization path (with a special exception for a specific require implementation). We have a plan to do this in the future #558
Nice. BTW, do we have a roadmap or milestone set about what features are going to be implemented for the first stable release eg: v1.x.x and when that is expected to be?
@NTillmann may have a better idea, but we should have a stable product by the end of the year. It is unclear at this point what exactly it will include, but we would at least want to have complete ES5 conformance and mostly bug-free implementation. At that point we should have a complete model for React Native and the ability to easily drop it in the React Native toolchain, but we're not sure what support we'll have for the web then.
Great. Anyway, I'm looking forward to using this in our regular dev workflow as soon as this is stable and production-ready. For now, I think a milestone/roadmap with expected features for the next stable version in the website/github would be helpful.
The issue is tracked in #558. We'll post a roadmap soon.
Great. Thanks :+1:
Most helpful comment
Prepack does not yet evaluate most functions that are not called on the initialization path (with a special exception for a specific require implementation). We have a plan to do this in the future #558