Skip to content

Instantly share code, notes, and snippets.

@Frost
Last active August 29, 2015 14:07
Show Gist options
  • Select an option

  • Save Frost/2530cefa99ba069ba752 to your computer and use it in GitHub Desktop.

Select an option

Save Frost/2530cefa99ba069ba752 to your computer and use it in GitHub Desktop.
coffeescript leading dots behavior change between minor versions

Take this snippet, borrowed from the coffeescript changelog:

$ 'body'
.click (e) ->
  $ '.box'
  .fadeIn 'fast'
  .addClass '.active'
.css 'background', 'white'

When compiled with anything older than 1.7.0, it will produce something like the following:

// Generated by CoffeeScript 1.6.3
(function() {
  $('body'.click(function(e) {
    return $('.box'.fadeIn('fast'.addClass('.active')));
  }).css('background', 'white'));

}).call(this);

However, in 1.7.0, they changed how leading dots are compiled:

// Generated by CoffeeScript 1.7.1
(function() {
  $('body').click(function(e) {
    return $('.box').fadeIn('fast').addClass('.active');
  }).css('background', 'white');

}).call(this);

Now, I like this change, because at least to me, it makes it more obvious what the code is actually trying to do.

However, effectively changing how a newline works in a minor version bump is not something I approve of. Sure, the coffeescript is not following semver, because they believe it's a lie.

This, combined with the section on versions on npmjs.org, did probably end up confusing a bunch of people, and at least gave me doubts as to what parts of the coffeescript API you can actually trust.

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