From 6c759d49bde9ba478ab3b98a656c13efb22aa7e8 Mon Sep 17 00:00:00 2001
From: Daniel Bayley
Date: Mon, 21 Nov 2016 07:04:49 +0000
Subject: [PATCH 1/5] Docs shorthand object notation (#4356)
* Docs shorthand object notation
A simple but slightly more imaginative example of shorthand object notation.
Closes #1808.
Signed-off-by: Daniel Bayley
* Update for new documentation folder structure
* Fix typo
---
documentation/examples/objects_shorthand.coffee | 5 +++++
documentation/index.html.js | 5 +++++
2 files changed, 10 insertions(+)
create mode 100644 documentation/examples/objects_shorthand.coffee
diff --git a/documentation/examples/objects_shorthand.coffee b/documentation/examples/objects_shorthand.coffee
new file mode 100644
index 00000000..4d3a9e25
--- /dev/null
+++ b/documentation/examples/objects_shorthand.coffee
@@ -0,0 +1,5 @@
+name = "Michelangelo"
+mask = "orange"
+weapon = "nunchuks"
+turtle = {name, mask, weapon}
+output = "#{turtle.name} wears an #{turtle.mask} mask. Watch out for his #{turtle.weapon}!"
diff --git a/documentation/index.html.js b/documentation/index.html.js
index 495201c2..75bf60c9 100644
--- a/documentation/index.html.js
+++ b/documentation/index.html.js
@@ -457,6 +457,11 @@ Block
about it (say, when using jQuery).
<%= codeFor('objects_reserved') %>
+
+ CoffeeScript has a shortcut for creating objects when you want the key
+ to be set with a variable of the same name.
+
+ <%= codeFor('objects_shorthand') %>
From 56482a31664a14965772f8a48d2bd755e0613e9c Mon Sep 17 00:00:00 2001
From: Geoffrey Booth
Date: Tue, 22 Nov 2016 09:30:39 -0800
Subject: [PATCH 2/5] =?UTF-8?q?Docs=20for=20`for=E2=80=A6from`=20(#4368)?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
* Documentation of `for...from` for iterating over generator functions
* Add note that the CoffeeScript compiler does not, in fact, generate JavaScript that runs in every JavaScript runtime :cry:
---
Cakefile | 2 +-
.../examples/generator_iteration.coffee | 13 +++++++++
documentation/index.html.js | 29 +++++++++++++++----
3 files changed, 38 insertions(+), 6 deletions(-)
create mode 100644 documentation/examples/generator_iteration.coffee
diff --git a/Cakefile b/Cakefile
index e9f92a5e..84ba247d 100644
--- a/Cakefile
+++ b/Cakefile
@@ -59,7 +59,7 @@ codeFor = ->
cshtml = "#{hljs.highlight('coffeescript', cs).value}
"
# Temporary fix until highlight.js adds support for newer CoffeeScript keywords
# Added in https://github.com/isagalaev/highlight.js/pull/1357, awaiting release
- if file in ['generators', 'modules']
+ if file in ['generator_iteration', 'generators', 'modules']
cshtml = cshtml.replace /(yield|import|export|from|as|default) /g, '$1 '
jshtml = "#{hljs.highlight('javascript', js).value}
"
append = if executable is yes then '' else "alert(#{executable});"
diff --git a/documentation/examples/generator_iteration.coffee b/documentation/examples/generator_iteration.coffee
new file mode 100644
index 00000000..ec98b08f
--- /dev/null
+++ b/documentation/examples/generator_iteration.coffee
@@ -0,0 +1,13 @@
+fibonacci = ->
+ [previous, current] = [1, 1]
+ loop
+ [previous, current] = [current, previous + current]
+ yield current
+ return
+
+getFibonacciNumbers = (length) ->
+ results = [1]
+ for n from fibonacci()
+ results.push n
+ break if results.length is length
+ results
diff --git a/documentation/index.html.js b/documentation/index.html.js
index 75bf60c9..6edec190 100644
--- a/documentation/index.html.js
+++ b/documentation/index.html.js
@@ -107,8 +107,17 @@
compiles one-to-one into the equivalent JS, and there is
no interpretation at runtime. You can use any existing JavaScript library
seamlessly from CoffeeScript (and vice-versa). The compiled output is
- readable and pretty-printed, will work in every JavaScript runtime, and tends
- to run as fast or faster than the equivalent handwritten JavaScript.
+ readable, pretty-printed, and tends to run as fast or faster than the
+ equivalent handwritten JavaScript.
+
+
+
+ The CoffeeScript compiler goes to great lengths to generate output JavaScript
+ that runs in every JavaScript runtime, but there are exceptions. Use
+ generator functions only if you know that your
+ target
+ runtimes can support them. If you use modules, you
+ will need to use an additional tool to resolve them.
@@ -577,6 +586,9 @@ Block
check to avoid properties that may be inherited from the prototype, use
for own key, value of object
+
+ To iterate a generator function, use from
.
+ See Generator Functions.
The only low-level loop that CoffeeScript provides is the while loop. The
main difference from JavaScript is that the while loop can be used
@@ -864,8 +876,9 @@ Block
constructed.
+
CoffeeScript functions also support
- ES6 generator functions
+ ES2015 generator functions
through the yield
keyword. There's no function*(){}
nonsense — a generator in CoffeeScript is simply a function that yields.
@@ -874,6 +887,11 @@ Block
yield*
is called yield from
, and yield return
may be used if you need to force a generator that doesn't yield.
+
+
+ You can iterate over a generator function using for…from
.
+
+ <%= codeFor('generator_iteration', 'getFibonacciNumbers(10)') %>
@@ -975,6 +993,7 @@ Block
<%= 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.
@@ -1393,7 +1412,7 @@ six = ->
<%= releaseHeader('2015-09-03', '1.10.0', '1.9.3') %>
-
- CoffeeScript now supports ES6-style destructuring defaults.
+ CoffeeScript now supports ES2015-style destructuring defaults.
-
(offsetHeight: height) ->
no longer compiles. That
@@ -1502,7 +1521,7 @@ six = ->
<%= releaseHeader('2015-01-29', '1.9.0', '1.8.0') %>
-
- CoffeeScript now supports ES6 generators. A generator is simply a function
+ CoffeeScript now supports ES2015 generators. A generator is simply a function
that
yield
s.
-
From 8ea67ff3e9a3620b15667892e47e9dc77536e7e7 Mon Sep 17 00:00:00 2001
From: Geoffrey Booth
Date: Tue, 22 Nov 2016 22:00:51 -0800
Subject: [PATCH 3/5] Update Bower.json per latest spec (#4371)
* Remove moot `version` property from bower.json
Per bower/bower.json-spec@a325da3
* No need for bower to know about dev dependencies, and this is one less thing to keep in sync
---
bower.json | 8 --------
1 file changed, 8 deletions(-)
diff --git a/bower.json b/bower.json
index 7917500b..f4e65dd3 100644
--- a/bower.json
+++ b/bower.json
@@ -1,6 +1,5 @@
{
"name": "coffee-script",
- "version": "1.11.1",
"main": [
"lib/coffee-script/coffee-script.js"
],
@@ -11,13 +10,6 @@
"coffeescript",
"compiler"
],
- "devDependencies": {
- "uglify-js": "~2.2",
- "jison": ">=0.2.0",
- "highlight.js": "~9.6.0",
- "underscore": "~1.5.2",
- "docco": "~0.6.2"
- },
"author": {
"name": "Jeremy Ashkenas"
},
From 992eb49e92c7008c76fdd23eeaa2cbdcb3e1b309 Mon Sep 17 00:00:00 2001
From: Geoffrey Booth
Date: Tue, 22 Nov 2016 22:09:35 -0800
Subject: [PATCH 4/5] Docs for triple-backticks and escaping backticks (#4369)
* Documentation for triple backticks and escaping backticks
* Better explanation of escaped backticks within triple-backticks block
---
documentation/examples/embedded_block.coffee | 5 +++++
documentation/examples/embedded_escaped.coffee | 3 +++
documentation/index.html.js | 13 +++++++++++++
3 files changed, 21 insertions(+)
create mode 100644 documentation/examples/embedded_block.coffee
create mode 100644 documentation/examples/embedded_escaped.coffee
diff --git a/documentation/examples/embedded_block.coffee b/documentation/examples/embedded_block.coffee
new file mode 100644
index 00000000..5ca5626e
--- /dev/null
+++ b/documentation/examples/embedded_block.coffee
@@ -0,0 +1,5 @@
+```
+function time() {
+ return `The time is ${new Date().toLocaleTimeString()}`;
+}
+```
diff --git a/documentation/examples/embedded_escaped.coffee b/documentation/examples/embedded_escaped.coffee
new file mode 100644
index 00000000..0eba110b
--- /dev/null
+++ b/documentation/examples/embedded_escaped.coffee
@@ -0,0 +1,3 @@
+markdown = `function () {
+ return \`In Markdown, write code like \\\`this\\\`\`;
+}`
diff --git a/documentation/index.html.js b/documentation/index.html.js
index 6edec190..4317c6e4 100644
--- a/documentation/index.html.js
+++ b/documentation/index.html.js
@@ -901,6 +901,19 @@ Block
use backticks to pass it straight through.
<%= codeFor('embedded', 'hi()') %>
+
+ Escape backticks with backslashes: \`
becomes `
.
+
+
+ Escape backslashes before backticks with more backslashes: \\\`
+ becomes \`
.
+
+ <%= codeFor('embedded_escaped', 'markdown()') %>
+
+ You can also embed blocks of JavaScript using triple backticks. That's easier
+ than escaping backticks, if you need them inside your JavaScript block.
+
+ <%= codeFor('embedded_block', 'time()') %>
From 555e47dbb92862305c8949d1a1ed0149cb0cce02 Mon Sep 17 00:00:00 2001
From: Gregory Huczynski
Date: Sun, 27 Nov 2016 03:28:43 +0000
Subject: [PATCH 5/5] Docs for tagged template literals (#4372)
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
* Correct tagged template literal test.
Should use Coffeescript form of interpolated
strings, not Javascript!
* First pass at docs for tagged template literals.
* Correct alerted variable.
* Add note re checking runtime for tagged template literals
* Fixed broken example.
* Consistent style
* Clarify that CoffeeScript isn’t handling the tagged template literal, the runtime is; fix CoffeeScript spelling
* Collapse notes about generator functions and tagged template literals into the same sentence
* Make tagged template literals example into a function
* Make text less clunky.
* More clarity on what CoffeeScript is doing versus what the runtime is doing, and emphasize runtimes vs Babel/Traceur
---
.../examples/tagged_template_literals.coffee | 8 +++++
documentation/index.html.js | 33 ++++++++++++++++---
test/tagged_template_literals.coffee | 2 +-
3 files changed, 38 insertions(+), 5 deletions(-)
create mode 100644 documentation/examples/tagged_template_literals.coffee
diff --git a/documentation/examples/tagged_template_literals.coffee b/documentation/examples/tagged_template_literals.coffee
new file mode 100644
index 00000000..a5a2edcb
--- /dev/null
+++ b/documentation/examples/tagged_template_literals.coffee
@@ -0,0 +1,8 @@
+upperCaseExpr = (textParts, expressions...) ->
+ textParts.reduce (text, textPart, i) ->
+ text + expressions[i - 1].toUpperCase() + textPart
+
+greet = (name, adjective) ->
+ upperCaseExpr"""
+ Hi #{name}. You look #{adjective}!
+ """
diff --git a/documentation/index.html.js b/documentation/index.html.js
index 4317c6e4..d163584a 100644
--- a/documentation/index.html.js
+++ b/documentation/index.html.js
@@ -41,6 +41,7 @@
Switch and Try/Catch
Chained Comparisons
String Interpolation, Block Strings, and Block Comments
+ Tagged Template Literals
Block Regular Expressions
Modules
Cake, and Cakefiles
@@ -114,10 +115,12 @@
The CoffeeScript compiler goes to great lengths to generate output JavaScript
that runs in every JavaScript runtime, but there are exceptions. Use
- generator functions only if you know that your
- target
- runtimes can support them. If you use modules, you
- will need to use an additional tool to resolve them.
+ generator functions or
+ tagged template literals only if you
+ know that your target
+ runtimes can support them. If you use modules,
+ you will need to use an additional tool to resolve
+ them.
@@ -987,6 +990,28 @@ Block
<%= codeFor('block_comment') %>
+
+
+
+ CoffeeScript supports
+ ES2015 tagged template literals,
+ which enable customized string interpolation. If you immediately prefix a string
+ with a function name (no space between the two), CoffeeScript will output this
+ 'function plus string' combination as an ES2015 tagged template literal, which will
+ behave accordingly:
+ the function is called, with the parameters being the input text and expression parts
+ that make up the interpolated string. The function can then assemble these parts
+ into an output string, providing custom string interpolation.
+
+
+ Be aware that the CoffeeScript compiler is outputting ES2015 syntax for this feature,
+ so your target JavaScript runtime(s) must support this syntax for your code to work;
+ or you could use tools like Babel or
+ Traceur Compiler to convert
+ this ES2015 syntax into compatible JavaScript.
+
+ <%= codeFor('tagged_template_literals', 'greet("greg", "awesome")') %>
+
diff --git a/test/tagged_template_literals.coffee b/test/tagged_template_literals.coffee
index 0efa8558..6ecacb0f 100644
--- a/test/tagged_template_literals.coffee
+++ b/test/tagged_template_literals.coffee
@@ -36,7 +36,7 @@ test "tagged template literal for html templating", ->
""",
html"""
- Hi ${state.name}. You're looking ${state.adjective}!
+ Hi #{state.name}. You're looking #{state.adjective}!
"""