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

Babel returns invalid code when using `arguments.callee`. #6927

Open
jjant opened this Issue Nov 28, 2017 · 5 comments

Comments

Projects
None yet
4 participants
@jjant

jjant commented Nov 28, 2017

Choose one: is this a bug report or feature request?
Bug

Input Code

repl: https://babeljs.io/repl/#?babili=true&browsers=&build=&builtIns=false&code_lz=GYAgvCAUwK4HYGMAuBLA9nSAPANASgG8BuAJwFMkYS4psA-ABjxAH4osAqSSAQxIHMYAWzJwkAZwB0CHgBtZZMnjzdsAWgCMy_MwBcILUSIBfPACgzwSACY8QA&debug=false&circleciRepo=&evaluate=false&lineWrap=false&presets=es2015%2Ces2016%2Ces2017%2Creact%2Cstage-0%2Cstage-1%2Cstage-2%2Cstage-3%2Cbabili&prettier=false&targets=&version=6.26.0

f = (function(x,){;return ((x>0) ? (x*((arguments.callee))(((x-1)),)) : 1);;})

f(2)

Expected Behavior

Returns working code.

Current Behavior

Returns the following code:

"use strict";f=function f(a){return 0<a?a*arguments.callee(a-1):1},f(2);

Which is invalid code because it uses arguments.callee in strict mode.

Possible Solution

Change arguments.callee to the function name (f) in this case.

@babel-bot

This comment has been minimized.

Show comment
Hide comment
@babel-bot

babel-bot Nov 28, 2017

Collaborator

Hey @jjant! We really appreciate you taking the time to report an issue. The collaborators
on this project attempt to help as many people as possible, but we're a limited number of volunteers,
so it's possible this won't be addressed swiftly.

If you need any help, or just have general Babel or JavaScript questions, we have a vibrant Slack
community that typically always has someone willing to help. You can sign-up here
for an invite.

Collaborator

babel-bot commented Nov 28, 2017

Hey @jjant! We really appreciate you taking the time to report an issue. The collaborators
on this project attempt to help as many people as possible, but we're a limited number of volunteers,
so it's possible this won't be addressed swiftly.

If you need any help, or just have general Babel or JavaScript questions, we have a vibrant Slack
community that typically always has someone willing to help. You can sign-up here
for an invite.

@nicolo-ribaudo

This comment has been minimized.

Show comment
Hide comment
@nicolo-ribaudo

nicolo-ribaudo Nov 28, 2017

Member

You should disable the module transform (passing modules: false to preset-es2015), since modules are in strict mode.

Member

nicolo-ribaudo commented Nov 28, 2017

You should disable the module transform (passing modules: false to preset-es2015), since modules are in strict mode.

@jjant

This comment has been minimized.

Show comment
Hide comment
@jjant

jjant Nov 28, 2017

@nicolo-ribaudo But I want to have my code compiled to valid strict code, and this should be (sort of easily) doable.

jjant commented Nov 28, 2017

@nicolo-ribaudo But I want to have my code compiled to valid strict code, and this should be (sort of easily) doable.

@loganfsmyth

This comment has been minimized.

Show comment
Hide comment
@loganfsmyth

loganfsmyth Nov 28, 2017

Member

arguments.callee is not available in strict code, and it is not something that Babel handles. It is generally a feature that should be avoided. I assumed the issue here was that you were compiling old existing ES5 code. If you're writing new ES6, you should not use it.

Member

loganfsmyth commented Nov 28, 2017

arguments.callee is not available in strict code, and it is not something that Babel handles. It is generally a feature that should be avoided. I assumed the issue here was that you were compiling old existing ES5 code. If you're writing new ES6, you should not use it.

@loganfsmyth

This comment has been minimized.

Show comment
Hide comment
@loganfsmyth

loganfsmyth Nov 28, 2017

Member

I guess this is something we could support, but it's generally dramatically more readable to just name the function yourself.

Member

loganfsmyth commented Nov 28, 2017

I guess this is something we could support, but it's generally dramatically more readable to just name the function yourself.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment