diff --git a/Cakefile b/Cakefile index 9dd83e39..e1dd3923 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/bower.json b/bower.json
index 1f4323a8..f4e65dd3 100644
--- a/bower.json
+++ b/bower.json
@@ -1,6 +1,5 @@
{
"name": "coffee-script",
- "version": "2.0.0-alpha",
"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"
},
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/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/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/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 bebce62a..095f5940 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
@@ -107,8 +108,19 @@
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 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.
@@ -457,6 +469,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') %>
@@ -572,6 +589,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
@@ -869,6 +889,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
.
+
@@ -884,6 +909,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 \`
.
+
+ 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()') %>@@ -957,6 +995,28 @@ Block
<%= codeFor('block_comment') %> ++ + Tagged Template Literals + 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")') %> +Block Regular Expressions @@ -976,6 +1036,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.
@@ -1394,7 +1455,7 @@ six = ->
<%= releaseHeader('2015-09-03', '1.10.0', '1.9.3') %>
(offsetHeight: height) ->
no longer compiles. That
@@ -1503,7 +1564,7 @@ six = ->
<%= releaseHeader('2015-01-29', '1.9.0', '1.8.0') %>
yield
s.
- Hi ${state.name}. You're looking ${state.adjective}! + Hi #{state.name}. You're looking #{state.adjective}!
"""