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

Unexpected compile for paren-free method chaining #2035

Closed
ryanflorence opened this issue Jan 13, 2012 · 6 comments
Closed

Unexpected compile for paren-free method chaining #2035

ryanflorence opened this issue Jan 13, 2012 · 6 comments

Comments

@ryanflorence
Copy link

request
  foo: 'bar'
.then doStuff

request foo: 'bar'
.then doStuff

request 'foo'
.then doStuff

compiles to

request({
  foo: 'bar'
}).then(doStuff);

request({
  foo: 'bar'.then(doStuff)
});

request('foo'.then(doStuff));

But I'd expect example 2 to compile to the same thing as example 1, and example 3 to be

request('foo').then(doStuff));

Is my assumption wrong?

@michaelficarra
Copy link
Collaborator

See #1407, #1495

@ryanflorence
Copy link
Author

This ticket is slightly different in that it shows the behavior is inconsistent when different arguments are passed to the first function, rather than proposing some chaining syntax. Whatever coffeescript does with chaining, it should act the same regardless of the type of arguments used.

@TrevorBurnham
Copy link
Collaborator

You're right that this is odd, but there is an explanation: The syntax

func
  key1: val1
  key2: val2

is special-cased to be an acceptable way of passing a hash to func. By contrast,

func
  arg

is unacceptable. This necessarily leads to some quirks... I certainly agree that the inconsistency between your first two examples should be rectified, preferably by making the second one equivalent to the first. The excellent proposal at #1407 would accomplish that feat by making the . on line 2 close the implicit parens on line 1.

@satyr
Copy link
Collaborator

satyr commented Feb 29, 2012

func
  key1: val1
  key2: val2

is special-cased to be an acceptable way of passing a hash to func.

Related, but not an actual cause.

OP's first case works because dots right after OUTDENT is special-cased to close implicit calls. Observe:

$ coffee -bcs
  f ->
    x
  .y

  f -> x
  .y

// Generated by CoffeeScript 1.2.1-pre

f(function() {
  return x;
}).y;

f(function() {
  return x.y;
});

@TrevorBurnham
Copy link
Collaborator

Ah, good explanation, satyr.

@vendethiel
Copy link
Collaborator

closing in favor of #1495

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

5 participants