From 5b74433cf94c7eda25a27e7e320f3889025f2380 Mon Sep 17 00:00:00 2001 From: Geoffrey Booth Date: Thu, 15 Sep 2016 00:15:07 -0700 Subject: [PATCH 1/8] Modules documentation first draft --- documentation/coffee/modules.coffee | 23 ++++++++++ documentation/index.html.js | 19 +++++++++ documentation/js/modules.js | 66 +++++++++++++++++++++++++++++ 3 files changed, 108 insertions(+) create mode 100644 documentation/coffee/modules.coffee create mode 100644 documentation/js/modules.js diff --git a/documentation/coffee/modules.coffee b/documentation/coffee/modules.coffee new file mode 100644 index 0000000000..9e383ae286 --- /dev/null +++ b/documentation/coffee/modules.coffee @@ -0,0 +1,23 @@ +import 'local-file.coffee' +import 'coffee-script' + +import _ from 'underscore' +import * as underscore from 'underscore' + +import { now } from 'underscore' +import { now as currentTimestamp } from 'underscore' +import { first, last } from 'underscore' +import utilityBelt, { each } from 'underscore' + +export default Math +export square = (x) -> x * x +export class Mathematics + least: (x, y) -> if x < y then x else y + +export { sqrt } +export { sqrt as squareRoot } +export { Mathematics as default, sqrt as squareRoot } + +export * from 'underscore' +export { max, min } from 'underscore' + diff --git a/documentation/index.html.js b/documentation/index.html.js index 7ada8e1125..3621aef634 100644 --- a/documentation/index.html.js +++ b/documentation/index.html.js @@ -41,6 +41,7 @@ Chained Comparisons String Interpolation, Block Strings, and Block Comments Block Regular Expressions + Modules Cake, and Cakefiles Source Maps "text/coffeescript" Script Tags @@ -937,6 +938,24 @@ Expressions

<%= codeFor('heregexes') %> +

+ + Modules + ES2015 modules are supported in CoffeeScript, with a very similar import + and export syntax: +

+ <%= codeFor('modules') %> +

+ Note that the CoffeeScript compiler does not resolve modules; writing an + import or export statement in CoffeeScript will produce an + import or export statement in the resulting output JavaScript. + It is your responsibility attach another transpiler, such as + Traceur Compiler, + Babel or + Rollup, to convert this ES2015 syntax into + code that will work in your target runtimes. +

+

diff --git a/documentation/js/modules.js b/documentation/js/modules.js new file mode 100644 index 0000000000..9fdfcd9a00 --- /dev/null +++ b/documentation/js/modules.js @@ -0,0 +1,66 @@ +// Generated by CoffeeScript 1.10.0 +import 'local-file.coffee'; + +import 'coffee-script'; + +import _ from 'underscore'; + +import * as underscore from 'underscore'; + +import { + now +} from 'underscore'; + +import { + now as currentTimestamp +} from 'underscore'; + +import { + first, + last +} from 'underscore'; + +import utilityBelt, { + each +} from 'underscore'; + +export default Math; + +export var square = function(x) { + return x * x; +}; + +export var Mathematics = (function() { + function Mathematics() {} + + Mathematics.prototype.least = function(x, y) { + if (x < y) { + return x; + } else { + return y; + } + }; + + return Mathematics; + +})(); + +export { + sqrt +}; + +export { + sqrt as squareRoot +}; + +export { + Mathematics as default, + sqrt as squareRoot +}; + +export * from 'underscore'; + +export { + max, + min +} from 'underscore'; From 72f7dbae08b86734c0afa5188f0d47e3f0d5abd8 Mon Sep 17 00:00:00 2001 From: Geoffrey Booth Date: Thu, 15 Sep 2016 20:02:03 -0700 Subject: [PATCH 2/8] Add note about bare output --- documentation/index.html.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/documentation/index.html.js b/documentation/index.html.js index 3621aef634..e1a2e5d66b 100644 --- a/documentation/index.html.js +++ b/documentation/index.html.js @@ -948,14 +948,19 @@ Expressions

Note that the CoffeeScript compiler does not resolve modules; writing an import or export statement in CoffeeScript will produce an - import or export statement in the resulting output JavaScript. + import or export statement in the resulting output. It is your responsibility attach another transpiler, such as Traceur Compiler, Babel or Rollup, to convert this ES2015 syntax into code that will work in your target runtimes.

- +

+ Also note that any file with an import or export statement will + be output without a top-level function safety wrapper; + in other words, importing or exporting modules will automatically trigger + bare mode for that file. This is because per the ES2015 spec, + import or export statements must occur at the topmost scope.

From 633dcb14aa44252434bd8217d5b0072b3d8b09f1 Mon Sep 17 00:00:00 2001 From: Geoffrey Booth Date: Thu, 15 Sep 2016 20:21:14 -0700 Subject: [PATCH 3/8] Update highlight.js --- bower.json | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/bower.json b/bower.json index da638df6cb..327b2d8110 100644 --- a/bower.json +++ b/bower.json @@ -14,7 +14,7 @@ "devDependencies": { "uglify-js": "~2.2", "jison": ">=0.2.0", - "highlight.js": "~8.0.0", + "highlight.js": "~9.6.0", "underscore": "~1.5.2", "docco": "~0.6.2" }, diff --git a/package.json b/package.json index 5dda687b21..526d5a6376 100644 --- a/package.json +++ b/package.json @@ -35,7 +35,7 @@ "devDependencies": { "uglify-js": "~2.2", "jison": ">=0.2.0", - "highlight.js": "~8.0.0", + "highlight.js": "~9.6.0", "underscore": "~1.5.2", "docco": "~0.7.0" } From c1629175fae02f058eb82720a3595931e7c9fcc9 Mon Sep 17 00:00:00 2001 From: Geoffrey Booth Date: Thu, 15 Sep 2016 20:26:02 -0700 Subject: [PATCH 4/8] Fix highlighting for CoffeeScript modules syntax, until highlight.js adds our new reserved words --- Cakefile | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Cakefile b/Cakefile index c9a675fd49..41031e04cd 100644 --- a/Cakefile +++ b/Cakefile @@ -54,6 +54,10 @@ codeFor = -> js = js.replace /^\/\/ generated.*?\n/i, '' cshtml = "
#{hljs.highlight('coffeescript', cs).value}
" + # Temporary fix until highlight.js adds support for newer CoffeeScript reserved words + if file is 'modules' + for reservedWord in ['import', 'export', 'from', 'as', 'default'] + cshtml = cshtml.replace new RegExp("#{reservedWord} ", 'g'), "#{reservedWord} " jshtml = "
#{hljs.highlight('javascript', js).value}
" append = if executable is yes then '' else "alert(#{executable});" if executable and executable != yes From 96b868acc4ba0106d11d740f2e4d34072893f0ac Mon Sep 17 00:00:00 2001 From: Geoffrey Booth Date: Thu, 15 Sep 2016 20:26:43 -0700 Subject: [PATCH 5/8] Updated generated documentation --- documentation/js/expressions_try.js | 1 - documentation/js/generators.js | 2 +- documentation/js/try.js | 2 +- index.html | 466 ++++++++++++++-------------- 4 files changed, 234 insertions(+), 237 deletions(-) diff --git a/documentation/js/expressions_try.js b/documentation/js/expressions_try.js index 4c5721b867..ecb6772afc 100644 --- a/documentation/js/expressions_try.js +++ b/documentation/js/expressions_try.js @@ -2,7 +2,6 @@ var error; alert((function() { - var error1; try { return nonexistent / void 0; } catch (error1) { diff --git a/documentation/js/generators.js b/documentation/js/generators.js index 3d6207d4cd..1553e210c4 100644 --- a/documentation/js/generators.js +++ b/documentation/js/generators.js @@ -6,7 +6,7 @@ perfectSquares = function*() { num = 0; while (true) { num += 1; - (yield num * num); + yield num * num; } }; diff --git a/documentation/js/try.js b/documentation/js/try.js index 9f85c4c51f..ed76116c58 100644 --- a/documentation/js/try.js +++ b/documentation/js/try.js @@ -1,5 +1,5 @@ // Generated by CoffeeScript 1.10.0 -var error, error1; +var error; try { allHellBreaksLoose(); diff --git a/index.html b/index.html index 4130c0a8d3..99583bdfa8 100644 --- a/index.html +++ b/index.html @@ -41,6 +41,7 @@ Chained Comparisons String Interpolation, Block Strings, and Block Comments Block Regular Expressions + Modules Cake, and Cakefiles Source Maps "text/coffeescript" Script Tags @@ -128,7 +129,7 @@

opposite = true # Conditions: -number = -42 if opposite +number = -42 if opposite # Functions: square = (x) -> x * x @@ -138,9 +139,9 @@

# Objects: math = - root: Math.sqrt - square: square - cube: (x) -> x * square x + root: Math.sqrt + square: square + cube: (x) -> x * square x # Splats: race = (winner, runners...) -> @@ -159,10 +160,10 @@

opposite = true; if (opposite) { - number = -42; + number = -42; } -square = function(x) { +square = function(x) { return x * x; }; @@ -171,12 +172,12 @@

math = { root: Math.sqrt, square: square, - cube: function(x) { + cube: function(x) { return x * square(x); } }; -race = function() { +race = function() { var runners, winner; winner = arguments[0], runners = 2 <= arguments.length ? slice.call(arguments, 1) : []; return print(winner, runners); @@ -186,7 +187,7 @@

alert("I knew it!"); } -cubes = (function() { +cubes = (function() { var i, len, results; results = []; for (i = 0, len = list.length; i < len; i++) { @@ -531,11 +532,11 @@

cube = (x) -> square(x) * x
var cube, square;
 
-square = function(x) {
+square = function(x) {
   return x * x;
 };
 
-cube = function(x) {
+cube = function(x) {
   return square(x) * x;
 };
 
load
song = ["do", "re", "mi", "fa", "so"]
 
-singers = {Jagger: "Rock", Elvis: "Roll"}
+singers = {Jagger: "Rock", Elvis: "Roll"}
 
 bitlist = [
   1, 0, 1
@@ -591,12 +592,12 @@ 

] kids = - brother: - name: "Max" - age: 11 - sister: - name: "Ida" - age: 9 + brother: + name: "Max" + age: 11 + sister: + name: "Ida" + age: 9

var bitlist, kids, singers, song;
 
 song = ["do", "re", "mi", "fa", "so"];
@@ -665,20 +666,21 @@ 

outer = 1
 changeNumbers = ->
-  inner = -1
+  inner = -1
   outer = 10
-inner = changeNumbers()
var changeNumbers, inner, outer;
+inner = changeNumbers()
+
var changeNumbers, inner, outer;
 
 outer = 1;
 
-changeNumbers = function() {
+changeNumbers = function() {
   var inner;
-  inner = -1;
+  inner = -1;
   return outer = 10;
 };
 
 inner = changeNumbers();
-
load
load
gold = silver = rest = "unknown"
-
-awardMedals = (first, second, others...) ->
+
+awardMedals = (first, second, others...) ->
   gold   = first
   silver = second
   rest   = others
@@ -797,7 +799,7 @@ 

gold = silver = rest = "unknown"; -awardMedals = function() { +awardMedals = function() { var first, others, second; first = arguments[0], second = arguments[1], others = 3 <= arguments.length ? slice.call(arguments, 2) : []; gold = first; @@ -892,7 +894,7 @@

countdown = (num for num in [10..1])
 
var countdown, num;
 
-countdown = (function() {
+countdown = (function() {
   var i, results;
   results = [];
   for (num = i = 10; i >= 1; num = --i) {
@@ -934,7 +936,7 @@ 

an object. Use of to signal comprehension over the properties of an object instead of the values in an array.

-
yearsOld = max: 10, ida: 9, tim: 11
+    
yearsOld = max: 10, ida: 9, tim: 11
 
 ages = for child, age of yearsOld
   "#{child} is #{age}"
@@ -946,7 +948,7 @@ 

tim: 11 }; -ages = (function() { +ages = (function() { var results; results = []; for (child in yearsOld) { @@ -1008,7 +1010,7 @@

num = 6; -lyrics = (function() { +lyrics = (function() { var results; results = []; while (num -= 1) { @@ -1037,9 +1039,7 @@

} return results; })(); -;alert(lyrics.join(" -"));'>run: lyrics.join(" -")


+;alert(lyrics.join("\n"));'>run: lyrics.join("\n")


For readability, the until keyword is equivalent to while not, and the loop keyword is equivalent to while true. @@ -1052,12 +1052,13 @@

forwarding any arguments.

for filename in list
-  do (filename) ->
+  do (filename) ->
     fs.readFile filename, (err, contents) ->
-      compile filename, contents.toString()
var filename, fn, i, len;
+      compile filename, contents.toString()
+
var filename, fn, i, len;
 
-fn = function(filename) {
-  return fs.readFile(filename, function(err, contents) {
+fn = function(filename) {
+  return fs.readFile(filename, function(err, contents) {
     return compile(filename, contents.toString());
   });
 };
@@ -1065,7 +1066,7 @@ 

filename = list[i]; fn(filename); } -

load

+

load

@@ -1080,9 +1081,9 @@

start = numbers[0..2] -middle = numbers[3...-2] +middle = numbers[3...-2] -end = numbers[-2..] +end = numbers[-2..] copy = numbers[..]
var copy, end, middle, numbers, start;
@@ -1091,9 +1092,9 @@ 

start = numbers.slice(0, 3); -middle = numbers.slice(3, -2); +middle = numbers.slice(3, -2); -end = numbers.slice(-2); +end = numbers.slice(-2); copy = numbers.slice(0);

load
numbers = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
 
-numbers[3..6] = [-3, -4, -5, -6]
+numbers[3..6] = [-3, -4, -5, -6]
 
var numbers, ref;
 
 numbers = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
 
-[].splice.apply(numbers, [3, 4].concat(ref = [-3, -4, -5, -6])), ref;
+[].splice.apply(numbers, [3, 4].concat(ref = [-3, -4, -5, -6])), ref;
 
load
load
load
# The first ten global properties.
 
-globals = (name for name of window)[0...10]
var globals, name;
+globals = (name for name of window)[0...10]
+
var globals, name;
 
-globals = ((function() {
+globals = ((function() {
   var results;
   results = [];
-  for (name in window) {
+  for (name in window) {
     results.push(name);
   }
   return results;
 })()).slice(0, 10);
-
load
load
-7 % 5 == -2 # The remainder of 7 / 5
--7 %% 5 == 3 # n %% 5 is always between 0 and 4
+    
-7 % 5 == -2 # The remainder of 7 / 5
+-7 %% 5 == 3 # n %% 5 is always between 0 and 4
 
 tabs.selectTabAtIndex((tabs.currentIndex - count) %% tabs.length)
-
var modulo = function(a, b) { return (+a % (b = +b) + b) % b; };
+
var modulo = function(a, b) { return (+a % (b = +b) + b) % b; };
 
--7 % 5 === -2;
+-7 % 5 === -2;
 
-modulo(-7, 5) === 3;
+modulo(-7, 5) === 3;
 
 tabs.selectTabAtIndex(modulo(tabs.currentIndex - count, tabs.length));
 
load

@@ -1353,7 +1356,7 @@

winner = yes if pick in [47, 92, 13] -print inspect "My name is #{@name}" +print inspect "My name is #{@name}"

var volume, winner;
 
 if (ignition === true) {
@@ -1440,7 +1443,7 @@ 

Soaking up nulls is similar to Ruby's andand gem, and to the - safe navigation operator + safe navigation operator in Groovy.

@@ -1470,18 +1473,18 @@

In the first class in the example below, this.constructor.name is "Animal".

class Animal
-  constructor: (@name) ->
+  constructor: (@name) ->
 
-  move: (meters) ->
-    alert @name + " moved #{meters}m."
+  move: (meters) ->
+    alert @name + " moved #{meters}m."
 
 class Snake extends Animal
-  move: ->
+  move: ->
     alert "Slithering..."
     super 5
 
 class Horse extends Animal
-  move: ->
+  move: ->
     alert "Galloping..."
     super 45
 
@@ -1490,119 +1493,7 @@ 

sam.move() tom.move() -

var Animal, Horse, Snake, sam, tom,
-  extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
-  hasProp = {}.hasOwnProperty;
-
-Animal = (function() {
-  function Animal(name) {
-    this.name = name;
-  }
-
-  Animal.prototype.move = function(meters) {
-    return alert(this.name + (" moved " + meters + "m."));
-  };
-
-  return Animal;
-
-})();
-
-Snake = (function(superClass) {
-  extend(Snake, superClass);
-
-  function Snake() {
-    return Snake.__super__.constructor.apply(this, arguments);
-  }
-
-  Snake.prototype.move = function() {
-    alert("Slithering...");
-    return Snake.__super__.move.call(this, 5);
-  };
-
-  return Snake;
-
-})(Animal);
-
-Horse = (function(superClass) {
-  extend(Horse, superClass);
-
-  function Horse() {
-    return Horse.__super__.constructor.apply(this, arguments);
-  }
-
-  Horse.prototype.move = function() {
-    alert("Galloping...");
-    return Horse.__super__.move.call(this, 45);
-  };
-
-  return Horse;
-
-})(Animal);
-
-sam = new Snake("Sammy the Python");
-
-tom = new Horse("Tommy the Palomino");
-
-sam.move();
-
-tom.move();
-
load
run

+

load
run

If structuring your prototypes classically isn't your cup of tea, CoffeeScript provides a couple of lower-level conveniences. The extends operator @@ -1611,15 +1502,9 @@

quick access to an object's prototype; and super() is converted into a call against the immediate ancestor's method of the same name.

-
String::dasherize = ->
+    
String::dasherize = ->
   this.replace /_/g, "-"
-
String.prototype.dasherize = function() {
-  return this.replace(/_/g, "-");
-};
-
load
run: "one_two".dasherize()

+
load
run: "one_two".dasherize()

Finally, class definitions are blocks of executable code, which make for interesting metaprogramming possibilities. Because in the context of a class definition, @@ -1667,7 +1552,7 @@

[city, temp, forecast] = weatherReport "Berkeley, CA"
var city, forecast, ref, temp, weatherReport;
 
-weatherReport = function(location) {
+weatherReport = function(location) {
   return [location, 72, "Mostly Sunny"];
 };
 
@@ -1685,16 +1570,16 @@ 

to help pull out deeply nested properties.

futurists =
-  sculptor: "Umberto Boccioni"
-  painter:  "Vladimir Burliuk"
-  poet:
-    name:   "F.T. Marinetti"
-    address: [
+  sculptor: "Umberto Boccioni"
+  painter:  "Vladimir Burliuk"
+  poet:
+    name:   "F.T. Marinetti"
+    address: [
       "Via Roma 42R"
       "Bellagio, Italy 22021"
     ]
 
-{poet: {name, address: [street, city]}} = futurists
+{poet: {name, address: [street, city]}} = futurists
 
var city, futurists, name, ref, ref1, street;
 
 futurists = {
@@ -1762,14 +1647,14 @@ 

to assign properties to your instance from an options object passed to the constructor.

class Person
-  constructor: (options) ->
-    {@name, @age, @height = 'average'} = options
+  constructor: (options) ->
+    {@name, @age, @height = 'average'} = options
 
-tim = new Person name: 'Tim', age: 4
+tim = new Person name: 'Tim', age: 4
 
var Person, tim;
 
-Person = (function() {
-  function Person(options) {
+Person = (function() {
+  function Person(options) {
     var ref;
     this.name = options.name, this.age = options.age, this.height = (ref = options.height) != null ? ref : 'average';
   }
@@ -1813,7 +1698,7 @@ 

object that the current function is attached to. If you pass a function as a callback or attach it to a different object, the original value of this will be lost. If you're not familiar with this behavior, - this Digital Web article + this Digital Web article gives a good overview of the quirks.

@@ -1825,22 +1710,23 @@

properties of the this where they're defined.

Account = (customer, cart) ->
-  @customer = customer
-  @cart = cart
+  @customer = customer
+  @cart = cart
 
-  $('.shopping_cart').on 'click', (event) =>
-    @customer.purchase @cart
var Account;
+  $('.shopping_cart').on 'click', (event) =>
+    @customer.purchase @cart
+
var Account;
 
-Account = function(customer, cart) {
+Account = function(customer, cart) {
   this.customer = customer;
   this.cart = cart;
-  return $('.shopping_cart').on('click', (function(_this) {
-    return function(event) {
+  return $('.shopping_cart').on('click', (function(_this) {
+    return function(event) {
       return _this.customer.purchase(_this.cart);
     };
   })(this));
 };
-
load

+

load

If we had used -> in the callback above, @customer would have referred to the undefined "customer" property of the DOM element, @@ -1864,26 +1750,27 @@

yield num * num return -window.ps or= perfectSquares()

var perfectSquares;
+window.ps or= perfectSquares()
+
var perfectSquares;
 
-perfectSquares = function*() {
+perfectSquares = function*() {
   var num;
   num = 0;
   while (true) {
     num += 1;
-    (yield num * num);
+    yield num * num;
   }
 };
 
-window.ps || (window.ps = perfectSquares());
-
load
load
hi = `function() {
-  return [document.title, "Hello JavaScript"].join(": ");
+    
hi = `function() {
+  return [document.title, "Hello JavaScript"].join(": ");
 }`
 
var hi;
 
-hi = function() {
-  return [document.title, "Hello JavaScript"].join(": ");
+hi = function() {
+  return [document.title, "Hello JavaScript"].join(": ");
 };
 
load
load

+
load

Switch statements can also be used without a control expression, turning them in to a cleaner alternative to if/else chains. @@ -1980,7 +1868,7 @@

score = 76; -grade = (function() { +grade = (function() { switch (false) { case !(score < 60): return 'F'; @@ -2010,7 +1898,7 @@

print error finally cleanUp() -

var error, error1;
+
var error;
 
 try {
   allHellBreaksLoose();
@@ -2120,15 +2008,13 @@ 

SkinnyMochaHalfCaffScript Compiler v1.0 Released under the MIT License ### - -


 /*
 SkinnyMochaHalfCaffScript Compiler v1.0
 Released under the MIT License
  */
 
-
load

+
load

@@ -2153,6 +2039,117 @@

OPERATOR = /^(?:[-=]>|[-+*\/%<>&|^!?=]=|>>>=?|([-+:])\1|([&|<>])\2=?|\?\.|\.{2,3})/;
load

+

+ + Modules + ES2015 modules are supported in CoffeeScript, with a very similar import + and export syntax: +

+
import 'local-file.coffee'
+import 'coffee-script'
+
+import _ from 'underscore'
+import * as underscore from 'underscore'
+
+import { now } from 'underscore'
+import { now as currentTimestamp } from 'underscore'
+import { first, last } from 'underscore'
+import utilityBelt, { each } from 'underscore'
+
+export default Math
+export square = (x) -> x * x
+export class Mathematics
+  least: (x, y) -> if x < y then x else y
+
+export { sqrt }
+export { sqrt as squareRoot }
+export { Mathematics as default, sqrt as squareRoot }
+
+export * from 'underscore'
+export { max, min } from 'underscore'
+
+
import 'local-file.coffee';
+
+import 'coffee-script';
+
+import _ from 'underscore';
+
+import * as underscore from 'underscore';
+
+import {
+  now
+} from 'underscore';
+
+import {
+  now as currentTimestamp
+} from 'underscore';
+
+import {
+  first,
+  last
+} from 'underscore';
+
+import utilityBelt, {
+  each
+} from 'underscore';
+
+export default Math;
+
+export var square = function(x) {
+  return x * x;
+};
+
+export var Mathematics = (function() {
+  function Mathematics() {}
+
+  Mathematics.prototype.least = function(x, y) {
+    if (x < y) {
+      return x;
+    } else {
+      return y;
+    }
+  };
+
+  return Mathematics;
+
+})();
+
+export {
+  sqrt
+};
+
+export {
+  sqrt as squareRoot
+};
+
+export {
+  Mathematics as default,
+  sqrt as squareRoot
+};
+
+export * from 'underscore';
+
+export {
+  max,
+  min
+} from 'underscore';
+
load

+

+ Note that the CoffeeScript compiler does not resolve modules; writing an + import or export statement in CoffeeScript will produce an + import or export statement in the resulting output. + It is your responsibility attach another transpiler, such as + Traceur Compiler, + Babel or + Rollup, to convert this ES2015 syntax into + code that will work in your target runtimes. +

+

+ Also note that any file with an import or export statement will + be output without a top-level function safety wrapper; + in other words, importing or exporting modules will automatically trigger + bare mode for that file. This is because per the ES2015 spec, + import or export statements must occur at the topmost scope.

@@ -2185,20 +2182,21 @@

require 'jison' code = require('./lib/grammar').parser.generate() dir = options.output or 'lib' - fs.writeFile "#{dir}/parser.js", code
var fs;
+  fs.writeFile "#{dir}/parser.js", code
+
var fs;
 
 fs = require('fs');
 
 option('-o', '--output [DIR]', 'directory for compiled code');
 
-task('build:parser', 'rebuild the Jison parser', function(options) {
+task('build:parser', 'rebuild the Jison parser', function(options) {
   var code, dir;
   require('jison');
   code = require('./lib/grammar').parser.generate();
   dir = options.output || 'lib';
   return fs.writeFile(dir + "/parser.js", code);
 });
-
load

+
load

If you need to invoke one task before another — for example, running build before test, you can use the invoke function: @@ -2292,8 +2290,8 @@

  • CoffeeScript Programming with jQuery, Rails, and Node.js is a new book by Michael Erasmus that covers CoffeeScript with an eye - towards real-world usage both in the browser (jQuery) and on the server - size (Rails, Node). + towards real-world usage both in the browser (jQuery) and on the + server-side (Rails, Node).
  • CoffeeScript Ristretto @@ -2354,7 +2352,7 @@

    The best list of open-source CoffeeScript examples can be found on GitHub. But just - to throw out few more: + to throw out a few more:

      @@ -2550,7 +2548,7 @@

    • In <script type="text/coffeescript"> tags, to avoid - possible duplicate browser requests for .coffee files, + possible duplicate browser requests for .coffee files, you can now use the data-src attribute instead of src.
    • @@ -2688,15 +2686,15 @@

    $ 'body'
    -.click (e) ->
    +.click (e) ->
       $ '.box'
       .fadeIn 'fast'
       .addClass '.active'
     .css 'background', 'white'
    -
    $('body').click(function(e) {
    +
    $('body').click(function(e) {
       return $('.box').fadeIn('fast').addClass('.active');
     }).css('background', 'white');
    -
    load

    +
    load

    • Added **, // and %% operators and ... expansion in parameter lists and destructuring expressions. From 50a112d281e0c7d8b6529ce1d43479cc1ca929c3 Mon Sep 17 00:00:00 2001 From: Geoffrey Booth Date: Fri, 16 Sep 2016 12:57:56 -0700 Subject: [PATCH 6/8] Revert "Updated generated documentation" This reverts commit 96b868acc4ba0106d11d740f2e4d34072893f0ac. --- documentation/js/expressions_try.js | 1 + documentation/js/generators.js | 2 +- documentation/js/try.js | 2 +- index.html | 466 ++++++++++++++-------------- 4 files changed, 237 insertions(+), 234 deletions(-) diff --git a/documentation/js/expressions_try.js b/documentation/js/expressions_try.js index ecb6772afc..4c5721b867 100644 --- a/documentation/js/expressions_try.js +++ b/documentation/js/expressions_try.js @@ -2,6 +2,7 @@ var error; alert((function() { + var error1; try { return nonexistent / void 0; } catch (error1) { diff --git a/documentation/js/generators.js b/documentation/js/generators.js index 1553e210c4..3d6207d4cd 100644 --- a/documentation/js/generators.js +++ b/documentation/js/generators.js @@ -6,7 +6,7 @@ perfectSquares = function*() { num = 0; while (true) { num += 1; - yield num * num; + (yield num * num); } }; diff --git a/documentation/js/try.js b/documentation/js/try.js index ed76116c58..9f85c4c51f 100644 --- a/documentation/js/try.js +++ b/documentation/js/try.js @@ -1,5 +1,5 @@ // Generated by CoffeeScript 1.10.0 -var error; +var error, error1; try { allHellBreaksLoose(); diff --git a/index.html b/index.html index 99583bdfa8..4130c0a8d3 100644 --- a/index.html +++ b/index.html @@ -41,7 +41,6 @@ Chained Comparisons String Interpolation, Block Strings, and Block Comments Block Regular Expressions - Modules Cake, and Cakefiles Source Maps "text/coffeescript" Script Tags @@ -129,7 +128,7 @@

      opposite = true # Conditions: -number = -42 if opposite +number = -42 if opposite # Functions: square = (x) -> x * x @@ -139,9 +138,9 @@

      # Objects: math = - root: Math.sqrt - square: square - cube: (x) -> x * square x + root: Math.sqrt + square: square + cube: (x) -> x * square x # Splats: race = (winner, runners...) -> @@ -160,10 +159,10 @@

      opposite = true; if (opposite) { - number = -42; + number = -42; } -square = function(x) { +square = function(x) { return x * x; }; @@ -172,12 +171,12 @@

      math = { root: Math.sqrt, square: square, - cube: function(x) { + cube: function(x) { return x * square(x); } }; -race = function() { +race = function() { var runners, winner; winner = arguments[0], runners = 2 <= arguments.length ? slice.call(arguments, 1) : []; return print(winner, runners); @@ -187,7 +186,7 @@

      alert("I knew it!"); } -cubes = (function() { +cubes = (function() { var i, len, results; results = []; for (i = 0, len = list.length; i < len; i++) { @@ -532,11 +531,11 @@

      cube = (x) -> square(x) * x
      var cube, square;
       
      -square = function(x) {
      +square = function(x) {
         return x * x;
       };
       
      -cube = function(x) {
      +cube = function(x) {
         return square(x) * x;
       };
       
      load
      song = ["do", "re", "mi", "fa", "so"]
       
      -singers = {Jagger: "Rock", Elvis: "Roll"}
      +singers = {Jagger: "Rock", Elvis: "Roll"}
       
       bitlist = [
         1, 0, 1
      @@ -592,12 +591,12 @@ 

      ] kids = - brother: - name: "Max" - age: 11 - sister: - name: "Ida" - age: 9 + brother: + name: "Max" + age: 11 + sister: + name: "Ida" + age: 9

      var bitlist, kids, singers, song;
       
       song = ["do", "re", "mi", "fa", "so"];
      @@ -666,21 +665,20 @@ 

      outer = 1
       changeNumbers = ->
      -  inner = -1
      +  inner = -1
         outer = 10
      -inner = changeNumbers()
      -
      var changeNumbers, inner, outer;
      +inner = changeNumbers()
      var changeNumbers, inner, outer;
       
       outer = 1;
       
      -changeNumbers = function() {
      +changeNumbers = function() {
         var inner;
      -  inner = -1;
      +  inner = -1;
         return outer = 10;
       };
       
       inner = changeNumbers();
      -
      load
      load
      gold = silver = rest = "unknown"
      -
      -awardMedals = (first, second, others...) ->
      +
      +awardMedals = (first, second, others...) ->
         gold   = first
         silver = second
         rest   = others
      @@ -799,7 +797,7 @@ 

      gold = silver = rest = "unknown"; -awardMedals = function() { +awardMedals = function() { var first, others, second; first = arguments[0], second = arguments[1], others = 3 <= arguments.length ? slice.call(arguments, 2) : []; gold = first; @@ -894,7 +892,7 @@

      countdown = (num for num in [10..1])
       
      var countdown, num;
       
      -countdown = (function() {
      +countdown = (function() {
         var i, results;
         results = [];
         for (num = i = 10; i >= 1; num = --i) {
      @@ -936,7 +934,7 @@ 

      an object. Use of to signal comprehension over the properties of an object instead of the values in an array.

      -
      yearsOld = max: 10, ida: 9, tim: 11
      +    
      yearsOld = max: 10, ida: 9, tim: 11
       
       ages = for child, age of yearsOld
         "#{child} is #{age}"
      @@ -948,7 +946,7 @@ 

      tim: 11 }; -ages = (function() { +ages = (function() { var results; results = []; for (child in yearsOld) { @@ -1010,7 +1008,7 @@

      num = 6; -lyrics = (function() { +lyrics = (function() { var results; results = []; while (num -= 1) { @@ -1039,7 +1037,9 @@

      } return results; })(); -;alert(lyrics.join("\n"));'>run: lyrics.join("\n")


      +;alert(lyrics.join(" +"));'>run: lyrics.join(" +")


      For readability, the until keyword is equivalent to while not, and the loop keyword is equivalent to while true. @@ -1052,13 +1052,12 @@

      forwarding any arguments.

      for filename in list
      -  do (filename) ->
      +  do (filename) ->
           fs.readFile filename, (err, contents) ->
      -      compile filename, contents.toString()
      -
      var filename, fn, i, len;
      +      compile filename, contents.toString()
      var filename, fn, i, len;
       
      -fn = function(filename) {
      -  return fs.readFile(filename, function(err, contents) {
      +fn = function(filename) {
      +  return fs.readFile(filename, function(err, contents) {
           return compile(filename, contents.toString());
         });
       };
      @@ -1066,7 +1065,7 @@ 

      filename = list[i]; fn(filename); } -

      load

      +

      load

      @@ -1081,9 +1080,9 @@

      start = numbers[0..2] -middle = numbers[3...-2] +middle = numbers[3...-2] -end = numbers[-2..] +end = numbers[-2..] copy = numbers[..]
      var copy, end, middle, numbers, start;
      @@ -1092,9 +1091,9 @@ 

      start = numbers.slice(0, 3); -middle = numbers.slice(3, -2); +middle = numbers.slice(3, -2); -end = numbers.slice(-2); +end = numbers.slice(-2); copy = numbers.slice(0);

      load
      numbers = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
       
      -numbers[3..6] = [-3, -4, -5, -6]
      +numbers[3..6] = [-3, -4, -5, -6]
       
      var numbers, ref;
       
       numbers = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
       
      -[].splice.apply(numbers, [3, 4].concat(ref = [-3, -4, -5, -6])), ref;
      +[].splice.apply(numbers, [3, 4].concat(ref = [-3, -4, -5, -6])), ref;
       
      load
      load
      load
      # The first ten global properties.
       
      -globals = (name for name of window)[0...10]
      -
      var globals, name;
      +globals = (name for name of window)[0...10]
      var globals, name;
       
      -globals = ((function() {
      +globals = ((function() {
         var results;
         results = [];
      -  for (name in window) {
      +  for (name in window) {
           results.push(name);
         }
         return results;
       })()).slice(0, 10);
      -
      load
      load
      -7 % 5 == -2 # The remainder of 7 / 5
      --7 %% 5 == 3 # n %% 5 is always between 0 and 4
      +    
      -7 % 5 == -2 # The remainder of 7 / 5
      +-7 %% 5 == 3 # n %% 5 is always between 0 and 4
       
       tabs.selectTabAtIndex((tabs.currentIndex - count) %% tabs.length)
      -
      var modulo = function(a, b) { return (+a % (b = +b) + b) % b; };
      +
      var modulo = function(a, b) { return (+a % (b = +b) + b) % b; };
       
      --7 % 5 === -2;
      +-7 % 5 === -2;
       
      -modulo(-7, 5) === 3;
      +modulo(-7, 5) === 3;
       
       tabs.selectTabAtIndex(modulo(tabs.currentIndex - count, tabs.length));
       
      load

      @@ -1356,7 +1353,7 @@

      winner = yes if pick in [47, 92, 13] -print inspect "My name is #{@name}" +print inspect "My name is #{@name}"

      var volume, winner;
       
       if (ignition === true) {
      @@ -1443,7 +1440,7 @@ 

      Soaking up nulls is similar to Ruby's andand gem, and to the - safe navigation operator + safe navigation operator in Groovy.

      @@ -1473,18 +1470,18 @@

      In the first class in the example below, this.constructor.name is "Animal".

      class Animal
      -  constructor: (@name) ->
      +  constructor: (@name) ->
       
      -  move: (meters) ->
      -    alert @name + " moved #{meters}m."
      +  move: (meters) ->
      +    alert @name + " moved #{meters}m."
       
       class Snake extends Animal
      -  move: ->
      +  move: ->
           alert "Slithering..."
           super 5
       
       class Horse extends Animal
      -  move: ->
      +  move: ->
           alert "Galloping..."
           super 45
       
      @@ -1493,7 +1490,119 @@ 

      sam.move() tom.move() -

      load
      run

      +

      var Animal, Horse, Snake, sam, tom,
      +  extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
      +  hasProp = {}.hasOwnProperty;
      +
      +Animal = (function() {
      +  function Animal(name) {
      +    this.name = name;
      +  }
      +
      +  Animal.prototype.move = function(meters) {
      +    return alert(this.name + (" moved " + meters + "m."));
      +  };
      +
      +  return Animal;
      +
      +})();
      +
      +Snake = (function(superClass) {
      +  extend(Snake, superClass);
      +
      +  function Snake() {
      +    return Snake.__super__.constructor.apply(this, arguments);
      +  }
      +
      +  Snake.prototype.move = function() {
      +    alert("Slithering...");
      +    return Snake.__super__.move.call(this, 5);
      +  };
      +
      +  return Snake;
      +
      +})(Animal);
      +
      +Horse = (function(superClass) {
      +  extend(Horse, superClass);
      +
      +  function Horse() {
      +    return Horse.__super__.constructor.apply(this, arguments);
      +  }
      +
      +  Horse.prototype.move = function() {
      +    alert("Galloping...");
      +    return Horse.__super__.move.call(this, 45);
      +  };
      +
      +  return Horse;
      +
      +})(Animal);
      +
      +sam = new Snake("Sammy the Python");
      +
      +tom = new Horse("Tommy the Palomino");
      +
      +sam.move();
      +
      +tom.move();
      +
      load
      run

      If structuring your prototypes classically isn't your cup of tea, CoffeeScript provides a couple of lower-level conveniences. The extends operator @@ -1502,9 +1611,15 @@

      quick access to an object's prototype; and super() is converted into a call against the immediate ancestor's method of the same name.

      -
      String::dasherize = ->
      +    
      String::dasherize = ->
         this.replace /_/g, "-"
      -
      load
      run: "one_two".dasherize()

      +
      String.prototype.dasherize = function() {
      +  return this.replace(/_/g, "-");
      +};
      +
      load
      run: "one_two".dasherize()

      Finally, class definitions are blocks of executable code, which make for interesting metaprogramming possibilities. Because in the context of a class definition, @@ -1552,7 +1667,7 @@

      [city, temp, forecast] = weatherReport "Berkeley, CA"
      var city, forecast, ref, temp, weatherReport;
       
      -weatherReport = function(location) {
      +weatherReport = function(location) {
         return [location, 72, "Mostly Sunny"];
       };
       
      @@ -1570,16 +1685,16 @@ 

      to help pull out deeply nested properties.

      futurists =
      -  sculptor: "Umberto Boccioni"
      -  painter:  "Vladimir Burliuk"
      -  poet:
      -    name:   "F.T. Marinetti"
      -    address: [
      +  sculptor: "Umberto Boccioni"
      +  painter:  "Vladimir Burliuk"
      +  poet:
      +    name:   "F.T. Marinetti"
      +    address: [
             "Via Roma 42R"
             "Bellagio, Italy 22021"
           ]
       
      -{poet: {name, address: [street, city]}} = futurists
      +{poet: {name, address: [street, city]}} = futurists
       
      var city, futurists, name, ref, ref1, street;
       
       futurists = {
      @@ -1647,14 +1762,14 @@ 

      to assign properties to your instance from an options object passed to the constructor.

      class Person
      -  constructor: (options) ->
      -    {@name, @age, @height = 'average'} = options
      +  constructor: (options) ->
      +    {@name, @age, @height = 'average'} = options
       
      -tim = new Person name: 'Tim', age: 4
      +tim = new Person name: 'Tim', age: 4
       
      var Person, tim;
       
      -Person = (function() {
      -  function Person(options) {
      +Person = (function() {
      +  function Person(options) {
           var ref;
           this.name = options.name, this.age = options.age, this.height = (ref = options.height) != null ? ref : 'average';
         }
      @@ -1698,7 +1813,7 @@ 

      object that the current function is attached to. If you pass a function as a callback or attach it to a different object, the original value of this will be lost. If you're not familiar with this behavior, - this Digital Web article + this Digital Web article gives a good overview of the quirks.

      @@ -1710,23 +1825,22 @@

      properties of the this where they're defined.

      Account = (customer, cart) ->
      -  @customer = customer
      -  @cart = cart
      +  @customer = customer
      +  @cart = cart
       
      -  $('.shopping_cart').on 'click', (event) =>
      -    @customer.purchase @cart
      -
      var Account;
      +  $('.shopping_cart').on 'click', (event) =>
      +    @customer.purchase @cart
      var Account;
       
      -Account = function(customer, cart) {
      +Account = function(customer, cart) {
         this.customer = customer;
         this.cart = cart;
      -  return $('.shopping_cart').on('click', (function(_this) {
      -    return function(event) {
      +  return $('.shopping_cart').on('click', (function(_this) {
      +    return function(event) {
             return _this.customer.purchase(_this.cart);
           };
         })(this));
       };
      -
      load

      +

      load

      If we had used -> in the callback above, @customer would have referred to the undefined "customer" property of the DOM element, @@ -1750,27 +1864,26 @@

      yield num * num return -window.ps or= perfectSquares() -

      var perfectSquares;
      +window.ps or= perfectSquares()
      var perfectSquares;
       
      -perfectSquares = function*() {
      +perfectSquares = function*() {
         var num;
         num = 0;
         while (true) {
           num += 1;
      -    yield num * num;
      +    (yield num * num);
         }
       };
       
      -window.ps || (window.ps = perfectSquares());
      -
      load
      load
      hi = `function() {
      -  return [document.title, "Hello JavaScript"].join(": ");
      +    
      hi = `function() {
      +  return [document.title, "Hello JavaScript"].join(": ");
       }`
       
      var hi;
       
      -hi = function() {
      -  return [document.title, "Hello JavaScript"].join(": ");
      +hi = function() {
      +  return [document.title, "Hello JavaScript"].join(": ");
       };
       
      load
      load

      +
      load

      Switch statements can also be used without a control expression, turning them in to a cleaner alternative to if/else chains. @@ -1868,7 +1980,7 @@

      score = 76; -grade = (function() { +grade = (function() { switch (false) { case !(score < 60): return 'F'; @@ -1898,7 +2010,7 @@

      print error finally cleanUp() -

      var error;
      +
      var error, error1;
       
       try {
         allHellBreaksLoose();
      @@ -2008,13 +2120,15 @@ 

      SkinnyMochaHalfCaffScript Compiler v1.0 Released under the MIT License ### + +

      
       /*
       SkinnyMochaHalfCaffScript Compiler v1.0
       Released under the MIT License
        */
       
      -
      load

      +
      load

      @@ -2039,117 +2153,6 @@

      OPERATOR = /^(?:[-=]>|[-+*\/%<>&|^!?=]=|>>>=?|([-+:])\1|([&|<>])\2=?|\?\.|\.{2,3})/;
      load

      -

      - - Modules - ES2015 modules are supported in CoffeeScript, with a very similar import - and export syntax: -

      -
      import 'local-file.coffee'
      -import 'coffee-script'
      -
      -import _ from 'underscore'
      -import * as underscore from 'underscore'
      -
      -import { now } from 'underscore'
      -import { now as currentTimestamp } from 'underscore'
      -import { first, last } from 'underscore'
      -import utilityBelt, { each } from 'underscore'
      -
      -export default Math
      -export square = (x) -> x * x
      -export class Mathematics
      -  least: (x, y) -> if x < y then x else y
      -
      -export { sqrt }
      -export { sqrt as squareRoot }
      -export { Mathematics as default, sqrt as squareRoot }
      -
      -export * from 'underscore'
      -export { max, min } from 'underscore'
      -
      -
      import 'local-file.coffee';
      -
      -import 'coffee-script';
      -
      -import _ from 'underscore';
      -
      -import * as underscore from 'underscore';
      -
      -import {
      -  now
      -} from 'underscore';
      -
      -import {
      -  now as currentTimestamp
      -} from 'underscore';
      -
      -import {
      -  first,
      -  last
      -} from 'underscore';
      -
      -import utilityBelt, {
      -  each
      -} from 'underscore';
      -
      -export default Math;
      -
      -export var square = function(x) {
      -  return x * x;
      -};
      -
      -export var Mathematics = (function() {
      -  function Mathematics() {}
      -
      -  Mathematics.prototype.least = function(x, y) {
      -    if (x < y) {
      -      return x;
      -    } else {
      -      return y;
      -    }
      -  };
      -
      -  return Mathematics;
      -
      -})();
      -
      -export {
      -  sqrt
      -};
      -
      -export {
      -  sqrt as squareRoot
      -};
      -
      -export {
      -  Mathematics as default,
      -  sqrt as squareRoot
      -};
      -
      -export * from 'underscore';
      -
      -export {
      -  max,
      -  min
      -} from 'underscore';
      -
      load

      -

      - Note that the CoffeeScript compiler does not resolve modules; writing an - import or export statement in CoffeeScript will produce an - import or export statement in the resulting output. - It is your responsibility attach another transpiler, such as - Traceur Compiler, - Babel or - Rollup, to convert this ES2015 syntax into - code that will work in your target runtimes. -

      -

      - Also note that any file with an import or export statement will - be output without a top-level function safety wrapper; - in other words, importing or exporting modules will automatically trigger - bare mode for that file. This is because per the ES2015 spec, - import or export statements must occur at the topmost scope.

      @@ -2182,21 +2185,20 @@

      require 'jison' code = require('./lib/grammar').parser.generate() dir = options.output or 'lib' - fs.writeFile "#{dir}/parser.js", code -
      var fs;
      +  fs.writeFile "#{dir}/parser.js", code
      var fs;
       
       fs = require('fs');
       
       option('-o', '--output [DIR]', 'directory for compiled code');
       
      -task('build:parser', 'rebuild the Jison parser', function(options) {
      +task('build:parser', 'rebuild the Jison parser', function(options) {
         var code, dir;
         require('jison');
         code = require('./lib/grammar').parser.generate();
         dir = options.output || 'lib';
         return fs.writeFile(dir + "/parser.js", code);
       });
      -
      load

      +
      load

      If you need to invoke one task before another — for example, running build before test, you can use the invoke function: @@ -2290,8 +2292,8 @@

    • CoffeeScript Programming with jQuery, Rails, and Node.js is a new book by Michael Erasmus that covers CoffeeScript with an eye - towards real-world usage both in the browser (jQuery) and on the - server-side (Rails, Node). + towards real-world usage both in the browser (jQuery) and on the server + size (Rails, Node).
    • CoffeeScript Ristretto @@ -2352,7 +2354,7 @@

      The best list of open-source CoffeeScript examples can be found on GitHub. But just - to throw out a few more: + to throw out few more:

        @@ -2548,7 +2550,7 @@

      • In <script type="text/coffeescript"> tags, to avoid - possible duplicate browser requests for .coffee files, + possible duplicate browser requests for .coffee files, you can now use the data-src attribute instead of src.
      • @@ -2686,15 +2688,15 @@

      $ 'body'
      -.click (e) ->
      +.click (e) ->
         $ '.box'
         .fadeIn 'fast'
         .addClass '.active'
       .css 'background', 'white'
      -
      $('body').click(function(e) {
      +
      $('body').click(function(e) {
         return $('.box').fadeIn('fast').addClass('.active');
       }).css('background', 'white');
      -
      load

      +
      load

      • Added **, // and %% operators and ... expansion in parameter lists and destructuring expressions. From 502be0a3d03a278ee08a32485a458a1d1b6b4a4b Mon Sep 17 00:00:00 2001 From: Geoffrey Booth Date: Fri, 16 Sep 2016 13:12:50 -0700 Subject: [PATCH 7/8] Suggest export as an option for exporting symbols to other scripts --- documentation/index.html.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/documentation/index.html.js b/documentation/index.html.js index e1a2e5d66b..bf5bed2c99 100644 --- a/documentation/index.html.js +++ b/documentation/index.html.js @@ -468,10 +468,11 @@ Expressions

        If you'd like to create top-level variables for other scripts to use, - attach them as properties on window, or on the exports - object in CommonJS. The existential operator (covered below), gives you a - reliable way to figure out where to add them; if you're targeting both - CommonJS and the browser: exports ? this + attach them as properties on window; attach them as properties on the + exports object in CommonJS; or use an export + statement. If you’re targeting both CommonJS and the browser, the + existential operator (covered below), gives you a + reliable way to figure out where to add them: exports ? this

        From 1745601a5a3b4e6306016b67c0cf41ffe4fa0a7d Mon Sep 17 00:00:00 2001 From: Geoffrey Booth Date: Sat, 17 Sep 2016 09:43:40 -0700 Subject: [PATCH 8/8] Replace syntax highlighting for loop with regex --- Cakefile | 3 +-- documentation/index.html.js | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/Cakefile b/Cakefile index 41031e04cd..dbd21b0226 100644 --- a/Cakefile +++ b/Cakefile @@ -56,8 +56,7 @@ codeFor = -> cshtml = "

        #{hljs.highlight('coffeescript', cs).value}
        " # Temporary fix until highlight.js adds support for newer CoffeeScript reserved words if file is 'modules' - for reservedWord in ['import', 'export', 'from', 'as', 'default'] - cshtml = cshtml.replace new RegExp("#{reservedWord} ", 'g'), "#{reservedWord} " + cshtml = cshtml.replace /(import|export|from|as|default) /g, '$1 ' jshtml = "
        #{hljs.highlight('javascript', js).value}
        " append = if executable is yes then '' else "alert(#{executable});" if executable and executable != yes diff --git a/documentation/index.html.js b/documentation/index.html.js index bf5bed2c99..cd11a0b6bc 100644 --- a/documentation/index.html.js +++ b/documentation/index.html.js @@ -942,7 +942,7 @@ Expressions

        Modules - ES2015 modules are supported in CoffeeScript, with a very similar import + ES2015 modules are supported in CoffeeScript, with very similar import and export syntax:

        <%= codeFor('modules') %>