Merge branch 'better-tail-recursion'
This commit is contained in:
@@ -1,29 +1,20 @@
|
||||
"use strict";
|
||||
|
||||
(function f(n) {
|
||||
var _arguments = arguments,
|
||||
_this = this,
|
||||
_shouldContinue,
|
||||
_result;
|
||||
var _callee = function (n) {
|
||||
(function f(_x) {
|
||||
var _this = this,
|
||||
_arguments = arguments;
|
||||
_function: while (true) {
|
||||
var n = _x;
|
||||
if (n <= 0) {
|
||||
console.log(this, arguments);
|
||||
console.log(_this, _arguments);
|
||||
return "foo";
|
||||
}
|
||||
if (Math.random() > 0.5) {
|
||||
_arguments = [n - 1];
|
||||
_this = this;
|
||||
return _shouldContinue = true;
|
||||
_arguments = [_x = n - 1];
|
||||
continue _function;
|
||||
} else {
|
||||
_arguments = [n - 1];
|
||||
_this = this;
|
||||
return _shouldContinue = true;
|
||||
_arguments = [_x = n - 1];
|
||||
continue _function;
|
||||
}
|
||||
};
|
||||
|
||||
do {
|
||||
_shouldContinue = false;
|
||||
_result = _callee.apply(_this, _arguments);
|
||||
} while (_shouldContinue);
|
||||
return _result;
|
||||
})(1000000) === "foo";
|
||||
}
|
||||
})(1000000) === "foo";
|
||||
|
||||
@@ -1,12 +1,9 @@
|
||||
"use strict";
|
||||
|
||||
(function f(n) {
|
||||
var _arguments = arguments,
|
||||
_this = this,
|
||||
_shouldContinue,
|
||||
_result;
|
||||
var _callee = function (n) {
|
||||
var _left;
|
||||
(function f(_x) {
|
||||
var _left;
|
||||
_function: while (true) {
|
||||
var n = _x;
|
||||
if (n <= 0) {
|
||||
return "foo";
|
||||
} else {
|
||||
@@ -18,15 +15,8 @@
|
||||
if (_left = getFalseValue()) {
|
||||
return _left;
|
||||
}
|
||||
_arguments = [n - 1];
|
||||
_this = undefined;
|
||||
return _shouldContinue = true;
|
||||
_x = n - 1;
|
||||
continue _function;
|
||||
}
|
||||
};
|
||||
|
||||
do {
|
||||
_shouldContinue = false;
|
||||
_result = _callee.apply(_this, _arguments);
|
||||
} while (_shouldContinue);
|
||||
return _result;
|
||||
})(1000000, true) === "foo";
|
||||
}
|
||||
})(1000000, true) === "foo";
|
||||
|
||||
3
test/fixtures/transformation/es6-tail-call/factorial/actual.js
vendored
Normal file
3
test/fixtures/transformation/es6-tail-call/factorial/actual.js
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
function fact(n, acc = 1) {
|
||||
return n > 1 ? fact(n - 1, acc * n) : acc;
|
||||
}
|
||||
16
test/fixtures/transformation/es6-tail-call/factorial/expected.js
vendored
Normal file
16
test/fixtures/transformation/es6-tail-call/factorial/expected.js
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
"use strict";
|
||||
|
||||
function fact(_x2) {
|
||||
var _arguments = arguments;
|
||||
_function: while (true) {
|
||||
var n = _x2;
|
||||
acc = undefined;
|
||||
var acc = _arguments[1] === undefined ? 1 : _arguments[1];
|
||||
if (n > 1) {
|
||||
_arguments = [_x2 = n - 1, acc * n];
|
||||
continue _function;
|
||||
} else {
|
||||
return acc;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,14 @@
|
||||
(function f(n = getDefaultValue(), /* should be undefined after first pass */ m) {
|
||||
(function f(n, m = getDefaultValue()) {
|
||||
// `m` should be `getDefaultValue()` after first pass
|
||||
if (n <= 0) {
|
||||
return "foo";
|
||||
}
|
||||
// Should be clean (undefined) on each pass
|
||||
var local;
|
||||
// `local1`-`local3` should be fresh on each pass
|
||||
var local1;
|
||||
let local2;
|
||||
const local3 = 3;
|
||||
// `g` should be function here on each pass
|
||||
g = 123;
|
||||
function g() {}
|
||||
return f(n - 1);
|
||||
})(1e6, true) === "foo";
|
||||
|
||||
@@ -1,25 +1,24 @@
|
||||
"use strict";
|
||||
|
||||
(function f(_x, /* should be undefined after first pass */m) {
|
||||
var _arguments = arguments,
|
||||
_this = this,
|
||||
_shouldContinue,
|
||||
_result;
|
||||
var _callee = function (_x, m) {
|
||||
var n = arguments[0] === undefined ? getDefaultValue() : arguments[0];
|
||||
(function f(_x2) {
|
||||
var _arguments = arguments;
|
||||
_function: while (true) {
|
||||
var g = function g() {};
|
||||
|
||||
var n = _x2;
|
||||
m = local1 = local2 = local3 = undefined;
|
||||
var m = _arguments[1] === undefined ? getDefaultValue() : _arguments[1];
|
||||
// `m` should be `getDefaultValue()` after first pass
|
||||
if (n <= 0) {
|
||||
return "foo";
|
||||
}
|
||||
// Should be clean (undefined) on each pass
|
||||
var local;
|
||||
_arguments = [n - 1];
|
||||
_this = undefined;
|
||||
return _shouldContinue = true;
|
||||
};
|
||||
|
||||
do {
|
||||
_shouldContinue = false;
|
||||
_result = _callee.apply(_this, _arguments);
|
||||
} while (_shouldContinue);
|
||||
return _result;
|
||||
})(1000000, true) === "foo";
|
||||
// `local1`-`local3` should be fresh on each pass
|
||||
var local1;
|
||||
var local2 = undefined;
|
||||
var local3 = 3;
|
||||
// `g` should be function here on each pass
|
||||
g = 123;
|
||||
_arguments = [_x2 = n - 1];
|
||||
continue _function;
|
||||
}
|
||||
})(1000000, true) === "foo";
|
||||
|
||||
@@ -9,29 +9,19 @@
|
||||
} catch (e) {}
|
||||
})(1000000) === "foo";
|
||||
|
||||
(function f(n) {
|
||||
var _arguments = arguments,
|
||||
_this = this,
|
||||
_shouldContinue,
|
||||
_result;
|
||||
var _callee = function (n) {
|
||||
(function f(_x) {
|
||||
_function: while (true) {
|
||||
var n = _x;
|
||||
if (n <= 0) {
|
||||
return "foo";
|
||||
}
|
||||
try {
|
||||
throw new Error();
|
||||
} catch (e) {
|
||||
_arguments = [n - 1];
|
||||
_this = undefined;
|
||||
return _shouldContinue = true;
|
||||
_x = n - 1;
|
||||
continue _function;
|
||||
}
|
||||
};
|
||||
|
||||
do {
|
||||
_shouldContinue = false;
|
||||
_result = _callee.apply(_this, _arguments);
|
||||
} while (_shouldContinue);
|
||||
return _result;
|
||||
}
|
||||
})(1000000) === "foo";
|
||||
|
||||
(function f(n) {
|
||||
@@ -45,25 +35,15 @@
|
||||
} finally {}
|
||||
})(1000000) === "foo";
|
||||
|
||||
(function f(n) {
|
||||
var _arguments = arguments,
|
||||
_this = this,
|
||||
_shouldContinue,
|
||||
_result;
|
||||
var _callee = function (n) {
|
||||
(function f(_x) {
|
||||
_function: while (true) {
|
||||
var n = _x;
|
||||
if (n <= 0) {
|
||||
return "foo";
|
||||
}
|
||||
try {} finally {
|
||||
_arguments = [n - 1];
|
||||
_this = undefined;
|
||||
return _shouldContinue = true;
|
||||
_x = n - 1;
|
||||
continue _function;
|
||||
}
|
||||
};
|
||||
|
||||
do {
|
||||
_shouldContinue = false;
|
||||
_result = _callee.apply(_this, _arguments);
|
||||
} while (_shouldContinue);
|
||||
return _result;
|
||||
})(1000000) === "foo";
|
||||
}
|
||||
})(1000000) === "foo";
|
||||
|
||||
Reference in New Issue
Block a user