2

If you use string interpolation in Coffeescript...

# source.coffee
bar = "Bar"
console.log "Foo #{bar}"

It compiles to

# compiled.js
var bar = 'Bar';
console.log(`Foo ${bar}`);

What version of Coffeescript started started compiling string interpolation into ES6 Template Literals? Is there a setting to have Coffeescript compile the old way? I also have to get on my soap box about this. The purpose of template literals was to make JavaScript easier to write by a human. So why was this change made in the compiled output? The old way Coffee compiled this was way more widely supported.

I'm actually using grunt-contrib-coffee and I ran into this. If there's a setting for the grunt task as well I'd appreciate the tip.

rb-
  • 2,315
  • 29
  • 41

1 Answers1

3

It's coffeescript 2 vs 1. I just tested it, the old version returns the concatenated string and the new one returns ES6 template literals.

Not sure how you ended up using coffeescript 2 on accident. It's in npm under a different package name (coffeescript for v2 vs coffee-script for v1).

max pleaner
  • 26,189
  • 9
  • 66
  • 118
  • My issue was that grunt-contrib-coffee started using coffeescript 2, so I had to drop back to grunt-contrib-coffee 1.0.0 to avoid coffeescript 2. Thanks for the answer. – rb- Dec 22 '17 at 18:19