Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
CoffeeScript upcoming changes.

CoffeeScript 1.7 is shaping up to be a pretty kick-ass release with significant improvements. Here are the ones I'm most excited about, in order of my own excitement.

Parentheses-free chaining

https://github.com/jashkenas/coffee-script/pull/3263

Years of being wished for, finally granted!

result = range 1, 3
  .concat range 4, 6
  .map (x) -> x * x
  .filter (x) -> x % 2 is 0

console.log result # [4, 16, 36]
$ 'body'
.click (e) ->
  $ '.box'
  .fadeIn 'fast'
  .addClass '.active'
  .css 'marginRight', '10px'

Proper multiline strings

These two both solve roughly the same problem:

https://github.com/jashkenas/coffee-script/pull/3246
https://github.com/jashkenas/coffee-script/pull/3256

These'll finally let you wrap long strings (e.g. user-facing messages) without breaking your code's indentation, or manually stripping newlines out. I've been wanting these for so long!

if true
  if not false
    console.log 'Hello world.
      This is a long line of text
      that I’d like split in my code.'

# equivalent to:

if true
  if not false
    console.log 'Hello world. This is a long line of text that I’d like split in my code.'
console.log '''
  By default, prefixed CSS will rewrite original files.
  If you didn't set input files, autoprefixer will \
    read from stdin stream.
  Output CSS will be written to stdout stream on \
    `-o -' argument or stdin input.
'''

# equivalent to:

desc = '''
  By default, prefixed CSS will rewrite original files.
  If you didn't set input files, autoprefixer will read from stdin stream.
  Output CSS will be written to stdout stream on `-o -' argument or stdin input.
'''

Expansion in array destructuring

https://github.com/jashkenas/coffee-script/pull/3268

The name sounds confusing, but this is straightforward:

# to get the first and last, what you have to do today:
[first, middle..., last] = array

# what you can do now:
[first, ..., last] = array

But here's the killer use for it:

# what you have to do today to get the last element in an array:
last = array[array.length - 1]

# or if you, like me, like to use features to their fullest:
[last] = array[-1..]

# what you can do now:
[..., last] = array

New mathematical operators

https://github.com/jashkenas/coffee-script/pull/2887

  • Power operator **
  • Floor division operator //
  • Correct modulo operator %% (respects negatives)

I remember wishing for each one of these when I worked on Seadragon Ajax!

Whitespace escaping in heregexes

https://github.com/jashkenas/coffee-script/pull/3214

Not a huge deal to most people, but I've frequently wondered about this.

regex = /// <link\ href="#{URL}" ///

Proper require.extensions registration

https://github.com/jashkenas/coffee-script/pull/3279

Like Streamline.js and others, extending Node's require() to automatically compile CoffeeScript files is now an explicit action. This now prevents versioning conflicts, etc. with nested local CoffeeScript dependencies.

# if you're working with the compiler programmatically:
CoffeeScript = require 'coffee-script'
CoffeeScript.register()

# or, e.g. for Mocha configuration
require 'coffee-script/register'

coffee <dir> executes index.coffee now

https://github.com/jashkenas/coffee-script/pull/3292

Like the title says. This brings the coffee executable closer in line with node. There's still a little room for improvement (e.g. if your main file is named app.coffee), but this is already a great step forward.

Credits

Phew! Talk about a powerful list.

My undying gratitute to the contributors of the above pull requests. A special shout-out to @xixixao in particular for contributing about half of them! Thank you all very, very much.

Looking forward to CoffeeScript 1.7!

@Anonyfox

This comment has been minimized.

Show comment Hide comment
@Anonyfox

Anonyfox Jan 27, 2014

Great! But still there are some goodies missing for some reason:

  1. regexp operator =~ as in ruby.
  2. functional style pattern matching for function definitions
  3. chained comparisons as in LiveScript, eg.: 1 < 2 == 4/2 > 0

Great! But still there are some goodies missing for some reason:

  1. regexp operator =~ as in ruby.
  2. functional style pattern matching for function definitions
  3. chained comparisons as in LiveScript, eg.: 1 < 2 == 4/2 > 0
@stefanpenner

This comment has been minimized.

Show comment Hide comment
@stefanpenner

stefanpenner Jan 27, 2014

seems like es6 import export support would be killer..

seems like es6 import export support would be killer..

@mattparlane

This comment has been minimized.

Show comment Hide comment
@mattparlane

mattparlane Jan 27, 2014

My bug, which was a regression from something which worked in 1.5.0, is fixed too:
jashkenas/coffee-script#3216

Again, thanks to @xixixao

My bug, which was a regression from something which worked in 1.5.0, is fixed too:
jashkenas/coffee-script#3216

Again, thanks to @xixixao

@aseemk

This comment has been minimized.

Show comment Hide comment
@aseemk

aseemk Jan 27, 2014

@Anonyfox: nice! I wasn't even aware of those. (I looked through only the past 6 months of commits; boy, it's been a while since the last release!) If it's not too much effort, would you mind linking the PRs here?

Owner

aseemk commented Jan 27, 2014

@Anonyfox: nice! I wasn't even aware of those. (I looked through only the past 6 months of commits; boy, it's been a while since the last release!) If it's not too much effort, would you mind linking the PRs here?

@aseemk

This comment has been minimized.

Show comment Hide comment
@aseemk

aseemk Jan 28, 2014

Ah, I just now realized @Anonyfox might have been saying "CoffeeScript still doesn't have these things", not "this gist didn't mention these things (that have also been added)". Alas, we all have our wishlists. =)

Owner

aseemk commented Jan 28, 2014

Ah, I just now realized @Anonyfox might have been saying "CoffeeScript still doesn't have these things", not "this gist didn't mention these things (that have also been added)". Alas, we all have our wishlists. =)

@msuarz

This comment has been minimized.

Show comment Hide comment
@msuarz

msuarz Jan 28, 2014

Awesome features ... thank you very much

msuarz commented Jan 28, 2014

Awesome features ... thank you very much

@caiogondim

This comment has been minimized.

Show comment Hide comment
@caiogondim

caiogondim Jan 28, 2014

Awesome =)

Awesome =)

@burkeholland

This comment has been minimized.

Show comment Hide comment
@burkeholland

burkeholland Jan 28, 2014

Baller

Baller

@L8D

This comment has been minimized.

Show comment Hide comment
@L8D

L8D Jan 28, 2014

@Anonyfox CoffeeScript already has function style pattern matching(i.e. head = ([x, xs...]) -> x). The RegEx testing operator has already been suggested and denied.

L8D commented Jan 28, 2014

@Anonyfox CoffeeScript already has function style pattern matching(i.e. head = ([x, xs...]) -> x). The RegEx testing operator has already been suggested and denied.

@xixixao

This comment has been minimized.

Show comment Hide comment
@xixixao

xixixao Jan 28, 2014

@aseemk What @Anonyfox mentions are things he wishes for, but are not in the language. I'd say 1) JS regex syntax is already pretty good, 2) Then you'd want algebraic data types as well, this is implementable via a library, 3) CoffeeScript has 2 < a < 3, not sure how LS works. Thanks for the shout-out .)

xixixao commented Jan 28, 2014

@aseemk What @Anonyfox mentions are things he wishes for, but are not in the language. I'd say 1) JS regex syntax is already pretty good, 2) Then you'd want algebraic data types as well, this is implementable via a library, 3) CoffeeScript has 2 < a < 3, not sure how LS works. Thanks for the shout-out .)

@Niggler

This comment has been minimized.

Show comment Hide comment
@Niggler

Niggler Jan 29, 2014

@aseemk spelling mistake: 'mathetmatical' should be 'mathematical'

Niggler commented Jan 29, 2014

@aseemk spelling mistake: 'mathetmatical' should be 'mathematical'

@aseemk

This comment has been minimized.

Show comment Hide comment
@aseemk

aseemk Jan 29, 2014

Thanks @Niggler!

Owner

aseemk commented Jan 29, 2014

Thanks @Niggler!

@dearfrankg

This comment has been minimized.

Show comment Hide comment
@dearfrankg

dearfrankg Feb 1, 2014

Some cool stuff - great job!

Some cool stuff - great job!

@trueter

This comment has been minimized.

Show comment Hide comment
@trueter

trueter Feb 2, 2014

Nice!

trueter commented Feb 2, 2014

Nice!

@vassilevsky

This comment has been minimized.

Show comment Hide comment
@vassilevsky

vassilevsky Feb 12, 2014

Ermagerd stweengs!

Ermagerd stweengs!

@ranska

This comment has been minimized.

Show comment Hide comment
@ranska

ranska Mar 2, 2014

nice, love Parentheses-free chaining

ranska commented Mar 2, 2014

nice, love Parentheses-free chaining

@alvaromuir

This comment has been minimized.

Show comment Hide comment
@alvaromuir

alvaromuir May 23, 2014

I was under a rock. Glad this was released.... been dreaming about chaining for a while. Thanks for continued work on this.

Now only if my IDE plugins would indent the new chain . . .

I was under a rock. Glad this was released.... been dreaming about chaining for a while. Thanks for continued work on this.

Now only if my IDE plugins would indent the new chain . . .

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