Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tail call optimization doesn't work when using default values referring to other parameters #2547

Closed
joshuacaron opened this issue Oct 16, 2015 · 4 comments
Labels
outdated A closed issue/PR that is archived due to age. Recommended to make a new issue

Comments

@joshuacaron
Copy link

Tail call optimization doesn't work properly if you use a function which has a default parameter refering to another parameter, for example:

function test(a, b = a){
  if(a === 0) {
    return b
  } else {
    return test(a - 1, b)
  }
}

compiles to:

"use strict";

function test(a) {
  var b = arguments.length <= 1 || arguments[1] === undefined ? a : arguments[1];
  return (function () {
    if (a === 0) {
      return b;
    } else {
      return test(a - 1, b);
    }
  })();
}
@loganfsmyth
Copy link
Member

This is a downside to the current approach to the context injected for default arguments. Definitely something that'll need to be looked at.

@sebmck
Copy link
Contributor

sebmck commented Nov 10, 2015

TCO has since been removed from Babel 6 due to issues and will be redeveloped in the future.

@estaub
Copy link

estaub commented Nov 15, 2015

@sebmck The status should be updated in http://babeljs.io/docs/learn-es2015/#tail-calls

@sebmck
Copy link
Contributor

sebmck commented Nov 16, 2015

Open an issue on the babel.github.io repo.

On Sun, Nov 15, 2015 at 7:17 AM, Ed Staub notifications@github.com wrote:

@sebmck https://github.com/sebmck The status should be updated in
http://babeljs.io/docs/learn-es2015/#tail-calls


Reply to this email directly or view it on GitHub
#2547 (comment).

Sebastian McKenzie

@lock lock bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label May 9, 2018
@lock lock bot locked as resolved and limited conversation to collaborators May 9, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
outdated A closed issue/PR that is archived due to age. Recommended to make a new issue
Projects
None yet
Development

No branches or pull requests

5 participants