Skip to content

Compilation bug: bracket closes wrong context #3025

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

Closed
PatrickKing opened this issue Jun 10, 2013 · 1 comment
Closed

Compilation bug: bracket closes wrong context #3025

PatrickKing opened this issue Jun 10, 2013 · 1 comment

Comments

@PatrickKing
Copy link

Hello,

I've noticed some strange behaviour in the coffeescript compiler.

jQuery = require('./jquery-1.10.0.min.js').jQuery
root = exports ? this

jQuery ->
  $('body').each -> (
    console.log("foo")
   )
  console.log('bar')

This compiles to what you'd expect, the statements with 'foo' and 'bar' are both in the function passed to jQuery:

// Generated by CoffeeScript 1.6.3
(function() {
  var jQuery, root;

  jQuery = require('./jquery-1.10.0.min.js').jQuery;

  root = typeof exports !== "undefined" && exports !== null ? exports : this;

  jQuery(function() {
    $('body').each(function() {
      return console.log("foo");
    });
    return console.log('bar');
  });

}).call(this);

But if we move the bracket on line seven by one space...

jQuery = require('./jquery-1.10.0.min.js').jQuery
root = exports ? this

jQuery ->
  $('body').each -> (
    console.log("foo")
   ) # one extra space to the left of the bracket
  console.log('bar')

... now for some reason, the bracket does not end the function passed to each(), but seems to end the function passed to jQuery() instead. The 'bar' log statement runs somewhere we weren't expecting it to.

// Generated by CoffeeScript 1.6.3
(function() {
  var jQuery, root;

  jQuery = require('./jquery-1.10.0.min.js').jQuery;

  root = typeof exports !== "undefined" && exports !== null ? exports : this;

  jQuery(function() {
    return $('body').each(function() {
      return console.log("foo");
    });
  });

  console.log('bar');

}).call(this);

Should this happen? The bracket should either match to the last open bracket (and close each()'s function), or the compiler should report an indentation error.

What's the point of allowing brackets if they don't override whitespacing rules?

@michaelficarra
Copy link
Collaborator

Duplicate of #1275.

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