Merge branch 'master' of github.com:jashkenas/coffeescript into 2

# Conflicts:
#	bower.json
This commit is contained in:
Geoffrey Booth
2016-11-22 22:13:13 -08:00
7 changed files with 69 additions and 14 deletions

View File

@@ -59,7 +59,7 @@ codeFor = ->
cshtml = "<pre><code>#{hljs.highlight('coffeescript', cs).value}</code></pre>"
# 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, '<span class="keyword">$1</span> '
jshtml = "<pre><code>#{hljs.highlight('javascript', js).value}</code></pre>"
append = if executable is yes then '' else "alert(#{executable});"

View File

@@ -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"
},

View File

@@ -0,0 +1,5 @@
```
function time() {
return `The time is ${new Date().toLocaleTimeString()}`;
}
```

View File

@@ -0,0 +1,3 @@
markdown = `function () {
return \`In Markdown, write code like \\\`this\\\`\`;
}`

View File

@@ -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

View File

@@ -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}!"

View File

@@ -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.
</p>
<p>
The CoffeeScript compiler goes to great lengths to generate output JavaScript
that runs in every JavaScript runtime, but there are exceptions. Use
<a href="#generator-functions">generator functions</a> only if you know that your
<a href="http://kangax.github.io/compat-table/es6/#test-generators">target
runtimes can support them</a>. If you use <a href="#modules">modules</a>, you
will need to <a href="#modules-note">use an additional tool to resolve them</a>.
</p>
<p>
@@ -457,6 +466,11 @@ Block
about it (say, when using jQuery).
</p>
<%= codeFor('objects_reserved') %>
<p>
CoffeeScript has a shortcut for creating objects when you want the key
to be set with a variable of the same name.
</p>
<%= codeFor('objects_shorthand') %>
<p>
<span id="lexical-scope" class="bookmark"></span>
@@ -572,6 +586,9 @@ Block
check to avoid properties that may be inherited from the prototype, use<br />
<code>for own key, value of object</code>
</p>
<p>
To iterate a generator function, use <code>from</code>.
See <a href="#generator-iteration">Generator Functions</a>.
<p>
The only low-level loop that CoffeeScript provides is the <b>while</b> loop. The
main difference from JavaScript is that the <b>while</b> loop can be used
@@ -859,8 +876,9 @@ Block
constructed.
</p>
<p>
<span id="generator-functions" class="bookmark"></span>
CoffeeScript functions also support
<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function*">ES6 generator functions</a>
<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function*">ES2015 generator functions</a>
through the <code>yield</code> keyword. There's no <code>function*(){}</code>
nonsense &mdash; a generator in CoffeeScript is simply a function that yields.
</p>
@@ -869,6 +887,11 @@ Block
<code>yield*</code> is called <code>yield from</code>, and <code>yield return</code>
may be used if you need to force a generator that doesn't yield.
</p>
<p>
<span id="generator-iteration" class="bookmark"></span>
You can iterate over a generator function using <code>for&hellip;from</code>.
</p>
<%= codeFor('generator_iteration', 'getFibonacciNumbers(10)') %>
<p>
<span id="embedded" class="bookmark"></span>
@@ -878,6 +901,19 @@ Block
use backticks to pass it straight through.
</p>
<%= codeFor('embedded', 'hi()') %>
<p>
Escape backticks with backslashes: <code>\`</code> becomes <code>`</code>.
</p>
<p>
Escape backslashes before backticks with more backslashes: <code>\\\`</code>
becomes <code>\`</code>.
</p>
<%= codeFor('embedded_escaped', 'markdown()') %>
<p>
You can also embed blocks of JavaScript using triple backticks. That's easier
than escaping backticks, if you need them inside your JavaScript block.
</p>
<%= codeFor('embedded_block', 'time()') %>
<p>
<span id="switch" class="bookmark"></span>
@@ -970,6 +1006,7 @@ Block
</p>
<%= codeFor('modules') %>
<p>
<span id="modules-note" class="bookmark"></span>
Note that the CoffeeScript compiler <strong>does not resolve modules</strong>; writing an
<code>import</code> or <code>export</code> statement in CoffeeScript will produce an
<code>import</code> or <code>export</code> statement in the resulting output.
@@ -1388,7 +1425,7 @@ six = -&gt;
<%= releaseHeader('2015-09-03', '1.10.0', '1.9.3') %>
<ul>
<li>
CoffeeScript now supports ES6-style destructuring defaults.
CoffeeScript now supports ES2015-style destructuring defaults.
</li>
<li>
<code>(offsetHeight: height) -&gt;</code> no longer compiles. That
@@ -1497,7 +1534,7 @@ six = -&gt;
<%= releaseHeader('2015-01-29', '1.9.0', '1.8.0') %>
<ul>
<li>
CoffeeScript now supports ES6 generators. A generator is simply a function
CoffeeScript now supports ES2015 generators. A generator is simply a function
that <code>yield</code>s.
</li>
<li>