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

Comprehensions can't handle arguments objects. #33

Closed
jashkenas opened this issue Jan 5, 2010 · 5 comments
Closed

Comprehensions can't handle arguments objects. #33

jashkenas opened this issue Jan 5, 2010 · 5 comments

Comments

@jashkenas
Copy link
Owner

A little help would be good on this one. Our array/object comprehensions can't handle argument objects being passed. The for..in loop doesn't see any properties on them, and doesn't run. Is there any way around this, other than generating two code paths for comprehensions (one for arrays/arguments and one for objects)? See the following JS:

for (key in [1, 2, 3]) console.log(key)
=> 0
=> 1
=> 2
=> undefined

(function(){ for (key in arguments) console.log(key) })(1, 2, 3)
=> undefined
@weepy
Copy link

weepy commented Jan 5, 2010

could CS replace the arguments keyword with an Array.spliced version ? I thought about suggesting this before.

x: => 
  for arg in arguments
    ...
var x
x = function x() {
 var _arguments = Array.prototype.slice.call(arguments,0,arguments.length)
 for(var i in _arguments) 
    ....

(function(){ var args = Array.prototype.slice.call(arguments,0,arguments.length); for (key in args) console.log(key) })(1, 2, 3) // => 1 2 3

@jashkenas
Copy link
Owner Author

We could add it as a check on obj.length -- you don't want to do it for vanilla objects (it makes them disappear), just arguments objects. So then you'd have to do the "isArguments" check for every array comprehension, which is a bit nasty. It's better to have CoffeeScript generate as little code as possible.

@weepy
Copy link

weepy commented Jan 5, 2010

but isn't the problem only ever on the keyword "arguments". Can't we look for that keyword and substitute?

@jashkenas
Copy link
Owner Author

I wish.

 func: =>
   something: arguments
   arg for arg in something

Boom.

@jashkenas
Copy link
Owner Author

Oh, I'm sorry, what you're suggesting is totally great. I'm just sleep deprived. I'll make a patch for it.

Edit:
It's now on master. Thanks weepy. Closing the ticket.

alangpierce added a commit to alangpierce/coffeescript that referenced this issue Mar 11, 2018
…s#33)

This fixes stack traces in other tools.

This also changes the header to just use 2.2.1 instead of the package.json
version.
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants