mirror of
https://github.com/jashkenas/coffeescript.git
synced 2026-01-13 16:57:54 -05:00
Compare commits
14 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0b0a9ef2c4 | ||
|
|
9df1457c55 | ||
|
|
22f92f23ae | ||
|
|
cd516b954f | ||
|
|
27eff5ca77 | ||
|
|
5cbd25f5d4 | ||
|
|
eb127923a7 | ||
|
|
42da56deb1 | ||
|
|
81260bff7d | ||
|
|
35f784bcdf | ||
|
|
c17b6b8863 | ||
|
|
1965996933 | ||
|
|
a67dfae985 | ||
|
|
1cb733989c |
43
README.md
43
README.md
@@ -1,22 +1,27 @@
|
||||
{
|
||||
} } {
|
||||
{ { } }
|
||||
} }{ {
|
||||
{ }{ } } _____ __ __
|
||||
{ }{ }{ { } / ____| / _|/ _|
|
||||
.- { { } { }} -. | | ___ | |_| |_ ___ ___
|
||||
( { } { } { } } ) | | / _ \| _| _/ _ \/ _ \
|
||||
|`-..________ ..-'| | |___| (_) | | | || __/ __/
|
||||
| | \_____\___/|_| |_| \___|\___|
|
||||
| ;--.
|
||||
| (__ \ _____ _ _
|
||||
| | ) ) / ____| (_) | |
|
||||
| |/ / | (___ ___ _ __ _ _ __ | |_
|
||||
| ( / \___ \ / __| '__| | '_ \| __|
|
||||
| |/ ____) | (__| | | | |_) | |_
|
||||
| | |_____/ \___|_| |_| .__/ \__|
|
||||
`-.._________..-' | |
|
||||
|_|
|
||||
@@@@@@@ @@@@ @@@@@
|
||||
{ @@@@@@@@@@ @@@ @@@
|
||||
} } { @@@@ @@ @@@ @@@
|
||||
{ { } } @@@@ @@@@@@@ @@@ @@@ @@@@@@ @@@@@@
|
||||
} }{ { @@@@ @@@ @@ @@@@@ @@@@@@ @@@ @@ @@@@ @@
|
||||
{ }{ } } @@@@ @@@@ @@ @@@ @@@ @@@ @@@ @@@ @@@
|
||||
{ }{ }{ { } @@@@ @@@@ @@ @@@ @@@ @@@@@@@@ @@@@@@@@
|
||||
{ { } { } { } } @@@@@ @@@@ @@ @@@ @@@ @@@ @@@
|
||||
{ } { } { } @@@@@@@@@@ @@@@@@@@ @@@ @@@ @@@@@@@@ @@@@@@@@
|
||||
@@@@@@ { } { } @@@@@@@ @@@@@ @@@ @@@ @@@@@ @@@@@
|
||||
@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @@@ @@@
|
||||
@@ @@@@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@ @@@ @@@
|
||||
@@ @@@@@@@@@@@@@@@@@@@@@@@@ @@@@ @@ @@@ @@@@
|
||||
@@@ @@@@@@@@@@@@@@@@@@@@@ @@@@ @@@ @@ @@@@
|
||||
@@@ @@@@@@@@@@@@@@@@@@ @@@@@ @@@@@ @@ @@ @@@ @@@@@@@ @@@@@
|
||||
@@@ @@@@@@@@@@@@@@@@ @@@@@ @@@ @@@ @@@@@@@@ @@@@ @@@@ @@@@@@@
|
||||
@@@@@@@@@@@@@@ @@@@@ @@@ @@@@ @@@@ @@@ @@@ @@@
|
||||
@@@@@ @@@@ @@@@ @@@@ @@@@ @@@@ @@@@ @@@@
|
||||
@@@ @@@@ @@@ @@@@ @@@@ @@@ @@@@ @@@@
|
||||
@@@ @@@@ @@@@ @@@@ @@@@ @@@@ @@@@ @@@@
|
||||
@@@@@@@@@ @@@@@@ @@@@ @@@@ @@@@@@@@@ @@@@
|
||||
@@@ @@@@
|
||||
@@@
|
||||
@@@
|
||||
|
||||
CoffeeScript is a little language that compiles into JavaScript.
|
||||
|
||||
|
||||
@@ -862,19 +862,17 @@ same directory as the <code>.js</code> file.</p>
|
||||
<a class="pilcrow" href="#section-26">¶</a>
|
||||
</div>
|
||||
<p>The user has requested that the CoffeeScript compiler also transpile
|
||||
via Babel. We use Babel as an <code>optionalDependency</code>; see
|
||||
<a href="https://docs.npmjs.com/files/package.json#optionaldependencies">https://docs.npmjs.com/files/package.json#optionaldependencies</a>.</p>
|
||||
via Babel. We don’t include Babel as a dependency because we want to
|
||||
avoid dependencies in general, and most users probably won’t be relying
|
||||
on us to transpile for them; we assume most users will probably either
|
||||
run CoffeeScript’s output without transpilation (modern Node or evergreen
|
||||
browsers) or use a proper build chain like Gulp or Webpack.</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre> <span class="hljs-keyword">try</span>
|
||||
<span class="hljs-built_in">require</span> <span class="hljs-string">'babel-core'</span>
|
||||
<span class="hljs-keyword">catch</span>
|
||||
<span class="hljs-built_in">console</span>.error <span class="hljs-string">'''
|
||||
To use --transpile, you must have Babel installed and configured.
|
||||
See http://coffeescript.org/#transpilation
|
||||
'''</span>
|
||||
process.exit <span class="hljs-number">1</span></pre></div></div>
|
||||
<span class="hljs-keyword">catch</span></pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
@@ -885,14 +883,28 @@ via Babel. We use Babel as an <code>optionalDependency</code>; see
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-27">¶</a>
|
||||
</div>
|
||||
<p>We’re giving Babel only a string, not a filename or path to a file, so
|
||||
it doesn’t know where to search to find a <code>.babelrc</code> file or a <code>babel</code>
|
||||
key in a <code>package.json</code>. So if <code>opts.transpile</code> is an object, use that
|
||||
as Babel’s options; otherwise figure out what the options should be.</p>
|
||||
<p>Give appropriate instructions depending on whether <code>coffee</code> was run
|
||||
locally or globally.</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre> <span class="hljs-keyword">unless</span> <span class="hljs-keyword">typeof</span> opts.transpile <span class="hljs-keyword">is</span> <span class="hljs-string">'object'</span></pre></div></div>
|
||||
<div class="content"><div class='highlight'><pre> <span class="hljs-keyword">if</span> <span class="hljs-built_in">require</span>.resolve(<span class="hljs-string">'.'</span>).indexOf(process.cwd()) <span class="hljs-keyword">is</span> <span class="hljs-number">0</span>
|
||||
<span class="hljs-built_in">console</span>.error <span class="hljs-string">'''
|
||||
To use --transpile, you must have babel-core installed:
|
||||
npm install --save-dev babel-core
|
||||
And you must save options to configure Babel in one of the places it looks to find its options.
|
||||
See http://coffeescript.org/#transpilation
|
||||
'''</span>
|
||||
<span class="hljs-keyword">else</span>
|
||||
<span class="hljs-built_in">console</span>.error <span class="hljs-string">'''
|
||||
To use --transpile with globally-installed CoffeeScript, you must have babel-core installed globally:
|
||||
npm install --global babel-core
|
||||
And you must save options to configure Babel in one of the places it looks to find its options, relative to the file being compiled or to the current folder.
|
||||
See http://coffeescript.org/#transpilation
|
||||
'''</span>
|
||||
process.exit <span class="hljs-number">1</span>
|
||||
|
||||
opts.transpile = {} <span class="hljs-keyword">unless</span> <span class="hljs-keyword">typeof</span> opts.transpile <span class="hljs-keyword">is</span> <span class="hljs-string">'object'</span></pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
@@ -903,46 +915,14 @@ as Babel’s options; otherwise figure out what the options should be.</p>
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-28">¶</a>
|
||||
</div>
|
||||
<p>Find the options based on the path to the file being compiled.</p>
|
||||
<p>Pass a reference to Babel into the compiler, so that the transpile option
|
||||
is available for the CLI. We need to do this so that tools like Webpack
|
||||
can <code>require('coffeescript')</code> and build correctly, without trying to
|
||||
require Babel.</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre><span class="hljs-function"> <span class="hljs-title">cantFindOptions</span> = -></span>
|
||||
<span class="hljs-built_in">console</span>.error <span class="hljs-string">'''
|
||||
To use the transpile option, there must be a .babelrc file
|
||||
(or a package.json file with a "babel" key) in the path of the file
|
||||
to be compiled, or in the path of the current working directory.
|
||||
If you are compiling a string via the Node API, the transpile option
|
||||
must be an object with the options to pass to Babel.
|
||||
See http://coffeescript.org/#transpilation
|
||||
'''</span>
|
||||
process.exit <span class="hljs-number">1</span>
|
||||
|
||||
checkPath = <span class="hljs-keyword">if</span> filename
|
||||
path.dirname filename
|
||||
<span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> base
|
||||
base
|
||||
<span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> process?
|
||||
process.cwd()
|
||||
<span class="hljs-keyword">else</span>
|
||||
cantFindOptions()
|
||||
|
||||
<span class="hljs-keyword">loop</span>
|
||||
<span class="hljs-keyword">try</span>
|
||||
opts.transpile = JSON.parse fs.readFileSync path.join(checkPath, <span class="hljs-string">'.babelrc'</span>), <span class="hljs-string">'utf-8'</span>
|
||||
<span class="hljs-keyword">break</span>
|
||||
<span class="hljs-keyword">catch</span>
|
||||
<span class="hljs-keyword">try</span>
|
||||
packageJson = JSON.parse fs.readFileSync(path.join(checkPath, <span class="hljs-string">'package.json'</span>), <span class="hljs-string">'utf-8'</span>)
|
||||
<span class="hljs-keyword">if</span> packageJson.babel?
|
||||
opts.transpile = packageJson.babel
|
||||
<span class="hljs-keyword">break</span>
|
||||
|
||||
<span class="hljs-keyword">if</span> checkPath <span class="hljs-keyword">is</span> path.dirname checkPath <span class="hljs-comment"># We’ve reached the root.</span>
|
||||
cantFindOptions()
|
||||
<span class="hljs-keyword">break</span>
|
||||
<span class="hljs-keyword">else</span>
|
||||
checkPath = path.dirname checkPath</pre></div></div>
|
||||
<div class="content"><div class='highlight'><pre> opts.transpile.transpile = CoffeeScript.transpile</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
@@ -953,14 +933,15 @@ as Babel’s options; otherwise figure out what the options should be.</p>
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-29">¶</a>
|
||||
</div>
|
||||
<p>Pass a reference to Babel into the compiler, so that the transpile option
|
||||
is available for the CLI. We need to do this so that tools like Webpack
|
||||
can <code>require('coffeescript')</code> and build correctly, without trying to
|
||||
require Babel.</p>
|
||||
<p>Babel searches for its options (a <code>.babelrc</code> file, a <code>.babelrc.js</code> file,
|
||||
a <code>package.json</code> file with a <code>babel</code> key, etc.) relative to the path
|
||||
given to it in its <code>filename</code> option. Make sure we have a path to pass
|
||||
along.</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre> opts.transpile.transpile = CoffeeScript.transpile
|
||||
<div class="content"><div class='highlight'><pre> <span class="hljs-keyword">unless</span> opts.transpile.filename
|
||||
opts.transpile.filename = filename <span class="hljs-keyword">or</span> path.resolve(base <span class="hljs-keyword">or</span> process.cwd(), <span class="hljs-string">'<anonymous>'</span>)
|
||||
<span class="hljs-keyword">else</span>
|
||||
opts.transpile = <span class="hljs-literal">no</span>
|
||||
|
||||
|
||||
@@ -3641,13 +3641,25 @@ exports.Class = <span class="hljs-class"><span class="hljs-keyword">class</span>
|
||||
<a class="pilcrow" href="#section-148">¶</a>
|
||||
</div>
|
||||
<p>Add an expression to the class initializer</p>
|
||||
<p>NOTE Currently, only methods and static methods are valid in ES class initializers.
|
||||
When additional expressions become valid, this method should be updated to handle them.</p>
|
||||
<p>This is the key method for determining whether an expression in a class
|
||||
body should appear in the initializer or the executable body. If the given
|
||||
<code>node</code> is valid in a class body the method will return a (new, modified,
|
||||
or identical) node for inclusion in the class initializer, otherwise
|
||||
nothing will be returned and the node will appear in the executable body.</p>
|
||||
<p>At time of writing, only methods (instance and static) are valid in ES
|
||||
class initializers. As new ES class features (such as class fields) reach
|
||||
Stage 4, this method will need to be updated to support them. We
|
||||
additionally allow <code>PassthroughLiteral</code>s (backticked expressions) in the
|
||||
initializer as an escape hatch for ES features that are not implemented
|
||||
(e.g. getters and setters defined via the <code>get</code> and <code>set</code> keywords as
|
||||
opposed to the <code>Object.defineProperty</code> method).</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre> addInitializerExpression: <span class="hljs-function"><span class="hljs-params">(node)</span> -></span>
|
||||
<span class="hljs-keyword">if</span> @validInitializerMethod node
|
||||
<span class="hljs-keyword">if</span> node.unwrapAll() <span class="hljs-keyword">instanceof</span> PassthroughLiteral
|
||||
node
|
||||
<span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> @validInitializerMethod node
|
||||
@addInitializerMethod node
|
||||
<span class="hljs-keyword">else</span>
|
||||
<span class="hljs-literal">null</span></pre></div></div>
|
||||
|
||||
0
docs/v2/annotated-source/public/fonts/roboto-black.eot
Executable file → Normal file
0
docs/v2/annotated-source/public/fonts/roboto-black.eot
Executable file → Normal file
0
docs/v2/annotated-source/public/fonts/roboto-black.ttf
Executable file → Normal file
0
docs/v2/annotated-source/public/fonts/roboto-black.ttf
Executable file → Normal file
0
docs/v2/annotated-source/public/fonts/roboto-black.woff
Executable file → Normal file
0
docs/v2/annotated-source/public/fonts/roboto-black.woff
Executable file → Normal file
File diff suppressed because one or more lines are too long
@@ -180,16 +180,17 @@ button:focus, .navbar-dark .navbar-toggler:focus {
|
||||
font-family: Lato;
|
||||
font-weight: 300;
|
||||
font-size: 1.1em;
|
||||
line-height: 1.7;
|
||||
}
|
||||
.main blockquote {
|
||||
font-size: 1.1em;
|
||||
}
|
||||
.main li p, .main li li, .main li blockquote {
|
||||
font-size: 1em;
|
||||
}
|
||||
@media (min-width: 768px) {
|
||||
.main p, .main li, .main td, .main th {
|
||||
font-size: 1.3em;
|
||||
}
|
||||
.main blockquote {
|
||||
font-size: 1.3em;
|
||||
.main p, .main li, .main td, .main th, .main blockquote {
|
||||
font-size: 1.2em;
|
||||
}
|
||||
}
|
||||
.main td {
|
||||
@@ -214,11 +215,18 @@ button:focus, .navbar-dark .navbar-toggler:focus {
|
||||
}
|
||||
|
||||
p, blockquote, table, .code-example {
|
||||
margin-bottom: 1.3rem;
|
||||
margin-bottom: 1.1em;
|
||||
}
|
||||
.main li {
|
||||
margin-bottom: 0.6em;
|
||||
}
|
||||
|
||||
td code {
|
||||
code, td code {
|
||||
white-space: nowrap;
|
||||
padding: 2px 8px;
|
||||
}
|
||||
pre code {
|
||||
white-space: pre; /* We want newlines to be newlines in code blocks */
|
||||
}
|
||||
|
||||
h2, h3, h4 {
|
||||
@@ -239,13 +247,18 @@ h3, h4, h2 time {
|
||||
margin-top: -2.3rem;
|
||||
}
|
||||
|
||||
@media (min-width: 1200px) {
|
||||
.main > header, .main section > h2, .main section > h3, .main section > h4, .main section > p, .main section > blockquote, .main section > ul, .main section > table {
|
||||
max-width: 80%;
|
||||
}
|
||||
}
|
||||
|
||||
code, button {
|
||||
font-family: 'Roboto Mono';
|
||||
font-weight: 400;
|
||||
}
|
||||
code, a > code {
|
||||
background-color: #f8f3f0;
|
||||
padding: 0.2rem 0.4rem;
|
||||
}
|
||||
code {
|
||||
color: #2f2625;
|
||||
@@ -290,6 +303,10 @@ textarea {
|
||||
height: 1em;
|
||||
}
|
||||
|
||||
.CodeMirror pre, pre.placeholder-code {
|
||||
line-height: 1.4em;
|
||||
}
|
||||
|
||||
.CodeMirror,
|
||||
.placeholder-code {
|
||||
/* https://codemirror.net/demo/resize.html */
|
||||
@@ -379,12 +396,18 @@ textarea {
|
||||
/* Prevent mobile Safari from zooming in on our code editors; the code is 16px naturally, but somehow being explicit about it prevents the zooming */
|
||||
font-size: 16px;
|
||||
}
|
||||
@media (min-width: 768px) {
|
||||
.CodeMirror,
|
||||
.placeholder-code {
|
||||
font-size: 90%; /* Matching Bootstrap’s font size for code, which calculates to 14.4px */
|
||||
}
|
||||
}
|
||||
.CodeMirror-lines {
|
||||
padding: 0.5em 0;
|
||||
}
|
||||
.placeholder-code {
|
||||
padding: 0.5em 4px;
|
||||
margin-bottom: 1.3rem;
|
||||
margin-bottom: 1.37em;
|
||||
white-space: pre-wrap;
|
||||
}
|
||||
div.CodeMirror-cursor {
|
||||
@@ -530,7 +553,6 @@ div.CodeMirror-cursor {
|
||||
<a href="#coffeescript-2" class="nav-link" data-action="sidebar-nav">CoffeeScript 2</a>
|
||||
<nav class="nav flex-column">
|
||||
<a href="#whats-new-in-coffeescript-2" class="nav-link" data-action="sidebar-nav">What’s New in CoffeeScript 2</a>
|
||||
<a href="#why-coffeescript" class="nav-link" data-action="sidebar-nav">Why CoffeeScript When There’s ES6?</a>
|
||||
<a href="#compatibility" class="nav-link" data-action="sidebar-nav">Compatibility</a>
|
||||
</nav>
|
||||
<a href="#installation" class="nav-link" data-action="sidebar-nav">Installation</a>
|
||||
@@ -609,20 +631,26 @@ div.CodeMirror-cursor {
|
||||
|
||||
</nav>
|
||||
<main class="main col-lg-9 ml-auto">
|
||||
<header class="title-logo d-none d-lg-block">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="-22 347 566 100">
|
||||
<header class="d-none d-lg-block">
|
||||
<p class="title-logo">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="-22 347 566 100">
|
||||
<title>
|
||||
CoffeeScript Logo
|
||||
</title>
|
||||
<path d="M21.7 351.1c.1.6-.2 1.1-1.2 1.6-1.3-.7-4.1-1.1-6.4-.9-2.5.2-4.6 1-4.3 2.7.4 1.7 2.8 2.7 7.1 2.3 10.5-.9 10.4-8 25.8-9.4 12-1.1 18.7 2.6 19.6 7.1.7 3.5-2.2 6.9-10.9 7.6-7.7.7-12.2-1.4-12.6-3.5-.2-1.1.4-2.7 4.1-3.1.4 1.7 2.5 3.5 7.5 3 3.6-.3 6.6-1.6 6.2-3.6-.4-2.1-4.2-3.3-10.2-2.8-12.2 1.1-15.2 7.8-25.6 8.7-7.4.7-13.4-2-14.2-6-.3-1.5-.3-5 7.5-5.7 4-.3 7.2.4 7.6 2zm-39 41.8c-3.4 4.3-4.9 9.3-4.6 14.2.3 4.9 2.7 8.9 6.5 12 4 3.1 8.3 4 13.2 3.1 1.9-.3 4-1.3 5.9-1.9-4 0-7.4-1.3-10.8-4-3.7-2.7-6.2-6.5-6.8-11.1-.9-4.3 0-8.3 2.4-11.8 2.7-3.4 6.2-5.3 10.8-5.9 4.6-.3 8.6.9 12.6 3.7-.9-1.3-2.2-2.2-3.4-3.4-4-2.7-8.3-4-13.6-2.7-4.8 1-8.8 3.5-12.2 7.8zm53.6-23.1c-12.9 0-24.4-1.3-32.7-3.1-8.9-2.2-13.6-4.6-13.6-7.7 0-1.3.6-2.4 2.4-3.7-5.6 2.2-8.6 4-8.6 6.8.3 3.1 5.3 6.2 15.5 8.6 9.6 2.4 21.9 3.7 36.7 3.7 15.1 0 27.1-1.3 36.7-3.7 10.2-2.4 15.1-5.6 15.1-8.6 0-2.2-2.2-4.3-6.2-5.9.9.6 1.6 1.6 1.6 2.7 0 3.1-4.6 5.6-13.9 7.7-8.6 1.9-19.6 3.2-33 3.2zm36.8 8.6c-9.6 2.2-21.9 3.7-36.7 3.7-15.1 0-27.4-1.6-37-3.7-8.6-2.2-13.2-4.6-14.8-7.1 1.6 10.8 5.3 21 10.2 30 3.7 5.6 7.4 10.5 11.1 15.8 1.6 3.1 2.7 6.2 3.4 9.3 2.4 3.4 5.9 5.6 10.2 6.8 5.3 1.9 10.8 2.7 16.4 2.4h.6c5.6.3 11.5-.6 16.9-2.4 4-1.3 7.4-3.4 9.9-6.8h.3c.6-3.1 1.6-6.2 3.1-9.3 3.7-5.3 7.4-10.2 11.1-15.8 4.9-8.9 8.3-19.1 10.2-30-2 2.8-6.6 5.2-14.9 7.1zm106.2 30.1c-4.8 12.1-17.6 16.9-25.9 16.9-13.4 0-19.9-6-19.9-22.3 0-16.5 7.9-47.3 31.7-47.3 8.5 0 15.2 3.3 15.2 12.1 0 4.8-1.8 8.3-6.4 8.3-1.5 0-3.4-.4-5.2-2.4 2.2-1.1 4.2-4.9 4.2-8.3 0-2.9-1.5-5.6-5.6-5.6-10 0-18.9 23.9-18.9 42.4 0 8.3 2.2 14.2 10.9 14.2 7.1 0 13.5-3.4 17.7-9.1l2.2 1.1zm32.9-16.3c.4.2.7.2 1 .2 4.2 0 10.1-2.7 14-5.5l.8 2.4c-3.4 3.7-9.5 6.5-16.1 7.5-1.5 16.8-10.6 27.3-21.7 27.3-8.4 0-14.5-4-14.5-14.4 0-10.5 6.2-32.2 24.9-32.2 7.8.3 11.6 5.3 11.6 14.7zm-7.7 5c-1.9-.5-2.4-2-2.4-3.8 0-2.5 1.2-4.2 2.8-4.9-.2-3.8-1.1-5.3-3.4-5.3-6.5 0-12 16.6-12 25.6 0 6 1.2 7.3 4.6 7.3 4.2.1 8.9-8 10.4-18.9zm-6.6 39.7c0-8.3 7.1-11 15.8-13.6l10.9-51.9c2.7-13 10.6-15.5 16.5-15.5 4.1 0 8 2.2 9.7 5.7 3.6-4.6 8.4-5.7 12.4-5.7 5.6 0 10.8 3.9 10.8 9.8 0 1.5-.1 2.6-.3 3.7h-4.3c.1-.9.2-1.7.2-2.4 0-2.1-1.7-3.1-3.4-3.1-2 0-4.8 1.1-6.2 7.1l-1.7 7.4h9.1l-.8 3.6h-9l-10.3 49.1c-2.7 13-10.6 15.5-16.5 15.5-5.2 0-8.3-2.3-9.8-5.7-3.5 4.6-8.3 5.7-12.3 5.7-5.6.1-10.8-3.8-10.8-9.7zm9.1 1.8c1.9 0 4.2-1.8 5.4-7.1l1.1-5.3c-5.7 2-10.1 4.4-10.1 9.4 0 1.2 1.7 3 3.6 3zm21.7 0c1.9 0 4.2-1.8 5.4-7.1l2.2-10.4-9.4 1.8-1.8 8.3c-.5 2.1-1.1 4-1.8 5.6.9 1.3 3 1.8 5.4 1.8zm-1.4-18l9.4-1.7 7.7-36.8h-9l-8.1 38.5zm16.6-56.7c-2 0-4.8 1.1-6.2 7.1l-1.7 7.4h9l2.1-9.5c.2-.7.2-1.3.2-2 .1-2-1.5-3-3.4-3zm37.9 53c7.1 0 11.6-4 16.1-9.2h3.1c-5.2 8.3-12.9 16.8-25 16.8-8.5 0-14.2-4.2-14.2-14.5 0-10.5 5.9-32.3 24.6-32.3 8.1 0 10 4.2 10 8.7 0 10.5-10 18.5-20.9 19.2-.1 1.3-.2 2.5-.2 3.6 0 6.2 2.2 7.7 6.5 7.7zm5.3-34.4c-4.6 0-9.1 9.7-10.9 18.7 7-.5 13.2-7.4 13.2-15 0-2.2-.5-3.7-2.3-3.7zm28.6 33.4c3.4 0 7.8-2.3 10.8-4.8-2 10.4-8.4 13.4-15.8 13.4-8.4 0-14.1-4.2-14.1-14.5 0-10.5 5.9-32.3 24.6-32.3 8.1 0 10 4.2 10 8.7 0 10.6-10 18.5-20.9 19.2-.1.9-.2 2-.2 2.7 0 5.7 2.5 7.6 5.6 7.6zm6.2-33.4c-4.5 0-9.1 10.1-11 18.7 7.1-.4 13.3-7.3 13.3-15 0-2.2-.6-3.7-2.3-3.7zm51.3-6.7c-1.7 0-3-.6-4.2-1.9 2.4-1.5 4.1-4.8 4.1-7.8 0-3.1-1.8-6.1-6.8-6.1s-8.3 2.8-8.3 8.2c0 13.3 20.5 15.2 20.5 34.8 0 15.3-12.3 22.7-25.6 22.7-10.4 0-19.3-4.5-19.3-15.7 0-9.8 7-14.9 13.3-14.9 3.1 0 7.7 1.3 8 6-4.9 0-10.7 2.3-10.7 8.5 0 4.5 2.9 8.7 8.7 8.7 6.1 0 10.6-4.4 10.6-12 0-15.6-18.6-21.1-18.6-34.5 0-9.5 9.3-16.3 21-16.3 4.3 0 14.6.9 14.6 10.9.1 5.5-2.8 9.4-7.3 9.4zm36.2 10.3c0-2.3-.8-3.7-2.5-3.7-5.7 0-11.7 16.6-11.7 26.7 0 6.2 2.2 7.6 6.6 7.6 7.1 0 11.6-4 16.1-9.2h3.1c-5.2 8.3-12.9 16.8-25 16.8-8.5 0-14.2-4.2-14.2-14.5 0-10.6 6-32.3 24.5-32.3 8.1 0 10.1 4.2 10.1 8.3 0 4.4-2.2 6.7-4.8 6.7-1 0-2.1-.4-3.1-1.1.5-1.9.9-3.6.9-5.3zm27.7-7.6l-1.2 5.7c3.1-2.7 6.7-5.7 11-5.7 4.1 0 6.3 3.3 6.3 6.9 0 3.1-2.1 6.7-6.6 6.7-5.1 0-2.5-6-5.3-6-2.7 0-4.4 1.4-6.7 3.4l-7.2 34.6h-13.1l9.6-45.4 13.2-.2zm34.2 0l-6.6 30.9c-.3 1.2-.4 2.1-.4 2.9 0 2.5 1.2 3.3 3.7 3.3 3.5 0 6.9-3.4 8.1-8h3.8c-5.2 14.8-14.2 16.8-19.1 16.8-5.5 0-9.7-3.2-9.7-10.9 0-1.8.3-3.7.7-5.9l6.2-29.2 13.3.1zm-4.1-19.4c4 0 7.2 3.2 7.2 7.2s-3.2 7.1-7.2 7.1-7.1-3.1-7.1-7.1c-.1-4 3.2-7.2 7.1-7.2zm29.1 16l-1.5 6.9c2.6-2.3 6.1-3.9 10.7-3.9 6.2 0 11.1 3.5 11.1 14.4 0 12.2-4.7 32.1-22.3 32.1-4.5 0-6.8-1.6-7.7-3.2l-4.7 22.1-13.7 3.2 15.2-71.5 12.9-.1zm7.8 17c0-7-2.9-7.5-4.5-7.5-2 0-4.5 1.6-6.3 4.4l-5.4 25.5c.4 1 1.4 2.1 3.4 2.1 9.7 0 12.8-15.9 12.8-24.5zm27.8 17.3c-.3 1.1-.5 2.2-.5 3.1 0 1.9.7 3.2 3.1 3.2.7 0 1.7 0 2.4-.3-2.5 7.8-6.6 8.9-9.6 8.9-6.4 0-9.1-4.4-9.1-10.3 0-1.6.2-3.1.6-4.8l5.8-27.2h-3l.7-3.6h3L528 366l13.4-1.9s-1.4 6.2-3.1 14.4h5.5l-.7 3.6h-5.5l-5.7 27.4z"/>
|
||||
</svg>
|
||||
|
||||
</p>
|
||||
</header>
|
||||
<section id="overview">
|
||||
<p><strong>CoffeeScript is a little language that compiles into JavaScript.</strong> Underneath that awkward Java-esque patina, JavaScript has always had a gorgeous heart. CoffeeScript is an attempt to expose the good parts of JavaScript in a simple way.</p>
|
||||
<p>The golden rule of CoffeeScript is: <em>“It’s just JavaScript.”</em> The code 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, pretty-printed, and tends to run as fast or faster than the equivalent handwritten JavaScript.</p>
|
||||
<p><strong>Latest Version:</strong> <a href="https://github.com/jashkenas/coffeescript/tarball/2.0.0">2.0.0</a></p>
|
||||
<blockquote class="uneditable-code-block"><pre><code class="language-bash">npm install -g coffeescript
|
||||
<p><strong>Latest Version:</strong> <a href="https://github.com/jashkenas/coffeescript/tarball/2.0.1">2.0.1</a></p>
|
||||
<blockquote class="uneditable-code-block"><pre><code class="language-bash"><span class="comment"># Install locally for a project:</span>
|
||||
npm install --save-dev coffeescript
|
||||
|
||||
<span class="comment"># Install globally to execute .coffee files anywhere:</span>
|
||||
npm install --global coffeescript
|
||||
</code></pre>
|
||||
</blockquote>
|
||||
<h2>Overview</h2>
|
||||
@@ -813,12 +841,6 @@ cubes = (function() {
|
||||
<p>The biggest change in CoffeeScript 2 is that now the CoffeeScript compiler produces modern JavaScript syntax (ES6, or ES2015 and later). A CoffeeScript <code>=></code> becomes a JS <code>=></code>, a CoffeeScript <code>class</code> becomes a JS <code>class</code> and so on. Major new features in CoffeeScript 2 include <a href="#async-functions">async functions</a> and <a href="#jsx">JSX</a>. You can read more in the <a href="announcing-coffeescript-2/">announcement</a>.</p>
|
||||
<p>There are very few <a href="#breaking-changes">breaking changes from CoffeeScript 1.x to 2</a>; we hope the upgrade process is smooth for most projects.</p>
|
||||
|
||||
</section>
|
||||
<section id="why-coffeescript">
|
||||
<h3>Why CoffeeScript When There’s ES6?</h3>
|
||||
<p>CoffeeScript introduced many new features to the JavaScript world, such as <a href="#fat-arrow"><code>=></code></a> and <a href="#destructuring">destructuring</a> and <a href="#classes">classes</a>. We are happy that ECMA has seen their utility and adopted them into ECMAScript.</p>
|
||||
<p>CoffeeScript’s intent, however, was never to be a superset of JavaScript. One of the guiding principles of CoffeeScript has been <em>simplicity:</em> not just removing JavaScript’s “bad parts,” but providing an elegant, concise syntax that eschews unnecessary punctuation whenever possible, to make code easier to read and reason about. This benefit of CoffeeScript remains, even in an ES2015+ world.</p>
|
||||
|
||||
</section>
|
||||
<section id="compatibility">
|
||||
<h3>Compatibility</h3>
|
||||
@@ -829,15 +851,16 @@ cubes = (function() {
|
||||
</section>
|
||||
<section id="installation">
|
||||
<h2>Installation</h2>
|
||||
<p>The command-line version of <code>coffee</code> is available as a <a href="https://nodejs.org/">Node.js</a> utility. The <a href="/v2/browser-compiler/coffeescript.js">core compiler</a> however, does not depend on Node, and can be run in any JavaScript environment, or in the browser (see <a href="#try">Try CoffeeScript</a>).</p>
|
||||
<p>The command-line version of <code>coffee</code> is available as a <a href="https://nodejs.org/">Node.js</a> utility, requiring Node 6 or later. The <a href="/v2/browser-compiler/coffeescript.js">core compiler</a> however, does not depend on Node, and can be run in any JavaScript environment, or in the browser (see <a href="#try">Try CoffeeScript</a>).</p>
|
||||
<p>To install, first make sure you have a working copy of the latest stable version of <a href="https://nodejs.org/">Node.js</a>. You can then install CoffeeScript globally with <a href="https://www.npmjs.com/">npm</a>:</p>
|
||||
<blockquote class="uneditable-code-block"><pre><code class="language-bash">npm install --global coffeescript
|
||||
</code></pre>
|
||||
</blockquote><p>This will make the <code>coffee</code> and <code>cake</code> commands available globally.</p>
|
||||
<p>When you need CoffeeScript as a dependency of a project, within that project’s folder you can install it locally:</p>
|
||||
<p>If you are using CoffeeScript in a project, you should install it locally for that project so that the version of CoffeeScript is tracked as one of your project’s dependencies. Within that project’s folder:</p>
|
||||
<blockquote class="uneditable-code-block"><pre><code class="language-bash">npm install --save-dev coffeescript
|
||||
</code></pre>
|
||||
</blockquote><p>The <code>coffee</code> and <code>cake</code> commands will first look in the current folder to see if CoffeeScript is installed locally, and use that version if so. This allows different versions of CoffeeScript to be installed globally and locally.</p>
|
||||
<p>If you plan to use the <code>--transpile</code> option (see <a href="#transpilation">Transpilation</a>) you will need to also install <code>babel-core</code> either globally or locally, depending on whether you are running a globally or locally installed version of CoffeeScript.</p>
|
||||
|
||||
</section>
|
||||
<section id="usage">
|
||||
@@ -967,30 +990,31 @@ eval CoffeeScript.compile <span class="string">'console.log "Mmmmm, I could real
|
||||
</section>
|
||||
<section id="transpilation">
|
||||
<h3>Transpilation</h3>
|
||||
<p>CoffeeScript 2 generates JavaScript that uses the latest, modern syntax. Your runtime <a href="#compatibility">might not support all of that syntax</a>. If so, you need to <em>transpile</em> the JavaScript. To make things a little easier, CoffeeScript has built-in support for the popular <a href="http://babeljs.io/">Babel</a> transpiler.</p>
|
||||
<p>CoffeeScript 2 generates JavaScript that uses the latest, modern syntax. The runtime or browsers where you want your code to run <a href="#compatibility">might not support all of that syntax</a>. In that case, we want to convert modern JavaScript into older JavaScript that will run in older versions of Node or older browsers; for example, <code>{ a } = obj</code> into <code>a = obj.a</code>. This is done via transpilers like <a href="http://babeljs.io/">Babel</a>, <a href="https://buble.surge.sh/">Bublé</a> or <a href="https://github.com/google/traceur-compiler">Traceur Compiler</a>.</p>
|
||||
<h4>Quickstart</h4>
|
||||
<p>From the root of your project:</p>
|
||||
<blockquote class="uneditable-code-block"><pre><code class="language-bash">npm install --save-dev babel-core babel-preset-env
|
||||
<span class="built_in">echo</span> <span class="string">'{ "presets": ["env"] }'</span> > .babelrc
|
||||
coffee --compile --transpile --inline-map some-file.coffee
|
||||
</code></pre>
|
||||
</blockquote><h4>About Transpilation</h4>
|
||||
<p>Transpilation is the conversion of source code into equivalent but different source code. In our case, we want to convert modern JavaScript into older JavaScript that will run in older versions of Node or older browsers; for example, <code>{ a } = obj</code> into <code>a = obj.a</code>. This is done via transpilers like <a href="http://babeljs.io/">Babel</a>, <a href="https://buble.surge.sh/">Bublé</a> or <a href="https://github.com/google/traceur-compiler">Traceur Compiler</a>.</p>
|
||||
<p>CoffeeScript includes a <code>--transpile</code> option when used via the <code>coffee</code> command, or a <code>transpile</code> option when used via Node. To use either, <a href="http://babeljs.io/">Babel</a> must be installed in your project:</p>
|
||||
</blockquote><h4>Transpiling with the CoffeeScript compiler</h4>
|
||||
<p>To make things easy, CoffeeScript has built-in support for the popular <a href="http://babeljs.io/">Babel</a> transpiler. You can use it via the <code>--transpile</code> command-line option or the <code>transpile</code> Node API option. To use either, <code>babel-core</code> must be installed in your project:</p>
|
||||
<blockquote class="uneditable-code-block"><pre><code class="language-bash">npm install --save-dev babel-core
|
||||
</code></pre>
|
||||
</blockquote><p>By default, Babel doesn’t do anything—it doesn’t make assumptions about what you want to transpile to. You might know that your code will run in Node 8, and so you want Babel to transpile modules and JSX and nothing else. Or you might want to support Internet Explorer 8, in which case Babel will transpile every feature introduced in ES2015 and later specs.</p>
|
||||
<p>If you’re not sure what you need, a good starting point is <a href="https://babeljs.io/docs/plugins/preset-env/"><code>babel-preset-env</code></a>:</p>
|
||||
<blockquote class="uneditable-code-block"><pre><code class="language-bash">npm install --save-dev babel-preset-env
|
||||
</blockquote><p>Or if you’re running the <code>coffee</code> command outside of a project folder, using a globally-installed <code>coffeescript</code> module, <code>babel-core</code> needs to be installed globally:</p>
|
||||
<blockquote class="uneditable-code-block"><pre><code class="language-bash">npm install --global babel-core
|
||||
</code></pre>
|
||||
</blockquote><p>See <a href="https://babeljs.io/docs/plugins/">Babel’s website to learn about presets and plugins</a> and the multitude of options you have.</p>
|
||||
<p>Simply installing <code>babel-preset-env</code> isn’t enough. You also need to define the configuration options that you want Babel to use. You can do this by creating a <a href="https://babeljs.io/docs/usage/babelrc/"><code>.babelrc</code> file</a> in the folder containing the files you’re compiling, or in any parent folder up the path above those files. So if your project is in <code>~/app</code> and your files are in <code>~/app/src</code>, you can put <code>.babelrc</code> in either <code>~/app</code> or in <code>~/app/src</code>. You can also define the Babel options via a <code>babel</code> key in the <code>package.json</code> file for your project. A minimal <code>.babelrc</code> file (or <code>package.json</code> <code>babel</code> key) for use with <code>babel-preset-env</code> would be just <code>{ "presets": ["env"] }</code>.</p>
|
||||
<p>Once you have <code>babel-core</code> and <code>babel-preset-env</code> (or other presets or plugins) installed, and a <code>.babelrc</code> file (or <code>package.json</code> <code>babel</code> key) in place, you can use <code>coffee --transpile</code> to pipe CoffeeScript’s output through Babel using the options you’ve saved.</p>
|
||||
</blockquote><p>By default, Babel doesn’t do anything—it doesn’t make assumptions about what you want to transpile to. You need to provide it with a configuration so that it knows what to do. One way to do this is by creating a <a href="https://babeljs.io/docs/usage/babelrc/"><code>.babelrc</code> file</a> in the folder containing the files you’re compiling, or in any parent folder up the path above those files. (Babel supports <a href="https://babeljs.io/docs/usage/babelrc/">other ways</a>, too.) A minimal <code>.babelrc</code> file would be just <code>{ "presets": ["env"] }</code>. This implies that you have installed <a href="https://babeljs.io/docs/plugins/preset-env/"><code>babel-preset-env</code></a>:</p>
|
||||
<blockquote class="uneditable-code-block"><pre><code class="language-bash">npm install --save-dev babel-preset-env <span class="comment"># Or --global for non-project-based usage</span>
|
||||
</code></pre>
|
||||
</blockquote><p>See <a href="https://babeljs.io/docs/plugins/">Babel’s website to learn about presets and plugins</a> and the multitude of options you have. Another preset you might need is <a href="https://babeljs.io/docs/plugins/transform-react-jsx/"><code>transform-react-jsx</code></a> if you’re using JSX with React (JSX can also be used with other frameworks).</p>
|
||||
<p>Once you have <code>babel-core</code> and <code>babel-preset-env</code> (or other presets or plugins) installed, and a <code>.babelrc</code> file (or other equivalent) in place, you can use <code>coffee --transpile</code> to pipe CoffeeScript’s output through Babel using the options you’ve saved.</p>
|
||||
<p>If you’re using CoffeeScript via the <a href="nodejs_usage">Node API</a>, where you call <code>CoffeeScript.compile</code> with a string to be compiled and an <code>options</code> object, the <code>transpile</code> key of the <code>options</code> object should be the Babel options:</p>
|
||||
<blockquote class="uneditable-code-block"><pre><code class="language-js">CoffeeScript.compile(code, {<span class="attr">transpile</span>: {<span class="attr">presets</span>: [<span class="string">'env'</span>]}})
|
||||
</code></pre>
|
||||
</blockquote><p>You can also transpile CoffeeScript’s output without using the <code>transpile</code> option, for example as part of a build chain. This lets you use transpilers other than Babel, and it gives you greater control over the process. There are many great task runners for setting up JavaScript build chains, such as <a href="http://gulpjs.com/">Gulp</a>, <a href="https://webpack.github.io/">Webpack</a>, <a href="https://gruntjs.com/">Grunt</a> and <a href="http://broccolijs.com/">Broccoli</a>.</p>
|
||||
<p>Note that <a href="https://babeljs.io/docs/plugins/preset-env/">babel-preset-env</a> doesn’t automatically supply <a href="https://developer.mozilla.org/en-US/docs/Glossary/Polyfill">polyfills</a> for your code. CoffeeScript itself will output <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/indexOf"><code>Array.indexOf</code></a> if you use the <code>in</code> operator, or destructuring or spread/rest syntax; and <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind"><code>Function.bind</code></a> if you use a bound (<code>=></code>) method in a class. Both are supported in Internet Explorer 9+ and all more recent browsers, but you will need to supply polyfills if you need to support Internet Explorer 8 or below and are using features that would cause these methods to be output. You’ll also need to supply polyfills if your own code uses these methods or another method added in recent versions of JavaScript. One polyfill option is <a href="https://babeljs.io/docs/usage/polyfill/"><code>babel-polyfill</code></a>, though there are many <a href="https://hackernoon.com/polyfills-everything-you-ever-wanted-to-know-or-maybe-a-bit-less-7c8de164e423">other</a> <a href="https://philipwalton.com/articles/loading-polyfills-only-when-needed/">strategies</a>.</p>
|
||||
<h4>Polyfills</h4>
|
||||
<p>Note that transpiling doesn’t automatically supply <a href="https://developer.mozilla.org/en-US/docs/Glossary/Polyfill">polyfills</a> for your code. CoffeeScript itself will output <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/indexOf"><code>Array.indexOf</code></a> if you use the <code>in</code> operator, or destructuring or spread/rest syntax; and <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind"><code>Function.bind</code></a> if you use a bound (<code>=></code>) method in a class. Both are supported in Internet Explorer 9+ and all more recent browsers, but you will need to supply polyfills if you need to support Internet Explorer 8 or below and are using features that would cause these methods to be output. You’ll also need to supply polyfills if your own code uses these methods or another method added in recent versions of JavaScript. One polyfill option is <a href="https://babeljs.io/docs/usage/polyfill/"><code>babel-polyfill</code></a>, though there are many <a href="https://hackernoon.com/polyfills-everything-you-ever-wanted-to-know-or-maybe-a-bit-less-7c8de164e423">other</a> <a href="https://philipwalton.com/articles/loading-polyfills-only-when-needed/">strategies</a>.</p>
|
||||
|
||||
</section>
|
||||
</section>
|
||||
@@ -1678,7 +1702,10 @@ alert(`Gold: ${gold}\nSilver: ${silver}\nThe Field: ${rest.join(', ')}`);
|
||||
|
||||
<div class="row">
|
||||
<div class="col text-right">
|
||||
<button type="button" class="btn btn-primary" data-action="run-code-example" data-example="splats" data-run="true"></button>
|
||||
<button type="button" class="btn btn-primary" data-action="run-code-example" data-example="splats" data-run="true"><small><svg class="play-button" viewBox="0 0 24 24">
|
||||
<path d="M2.56-0.01v24.02L21.44 11.98 2.56-0.01z"/>
|
||||
</svg>
|
||||
</small></button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -2473,7 +2500,10 @@ alert((function() {
|
||||
|
||||
<div class="row">
|
||||
<div class="col text-right">
|
||||
<button type="button" class="btn btn-primary" data-action="run-code-example" data-example="expressions_try" data-run="true"></button>
|
||||
<button type="button" class="btn btn-primary" data-action="run-code-example" data-example="expressions_try" data-run="true"><small><svg class="play-button" viewBox="0 0 24 24">
|
||||
<path d="M2.56-0.01v24.02L21.44 11.98 2.56-0.01z"/>
|
||||
</svg>
|
||||
</small></button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -3543,7 +3573,10 @@ countdown(3);
|
||||
|
||||
<div class="row">
|
||||
<div class="col text-right">
|
||||
<button type="button" class="btn btn-primary" data-action="run-code-example" data-example="async" data-run="true"></button>
|
||||
<button type="button" class="btn btn-primary" data-action="run-code-example" data-example="async" data-run="true"><small><svg class="play-button" viewBox="0 0 24 24">
|
||||
<path d="M2.56-0.01v24.02L21.44 11.98 2.56-0.01z"/>
|
||||
</svg>
|
||||
</small></button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -3681,7 +3714,10 @@ tom.move();
|
||||
|
||||
<div class="row">
|
||||
<div class="col text-right">
|
||||
<button type="button" class="btn btn-primary" data-action="run-code-example" data-example="classes" data-run="true"></button>
|
||||
<button type="button" class="btn btn-primary" data-action="run-code-example" data-example="classes" data-run="true"><small><svg class="play-button" viewBox="0 0 24 24">
|
||||
<path d="M2.56-0.01v24.02L21.44 11.98 2.56-0.01z"/>
|
||||
</svg>
|
||||
</small></button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -4575,28 +4611,50 @@ renderStarRating = function({rating, maxStars}) {
|
||||
<div class="col-md-6 coffeescript-input-column">
|
||||
<textarea class="coffeescript-input" id="type_annotations-coffee"># @flow
|
||||
|
||||
fn = (str ###: string ###, num ###: number ###) ###: string ### ->
|
||||
str + num
|
||||
###::
|
||||
type Obj = {
|
||||
num: number,
|
||||
};
|
||||
###
|
||||
|
||||
fn = (str ###: string ###, obj ###: Obj ###) ###: string ### ->
|
||||
str + obj.num
|
||||
</textarea>
|
||||
<pre class="placeholder-code"><span class="cm-comment"># @flow</span>
|
||||
|
||||
<span class="cm-variable">fn</span> <span class="cm-punctuation">=</span> <span class="cm-punctuation">(</span><span class="cm-variable">str</span> <span class="cm-comment">###: string ###</span><span class="cm-punctuation">,</span> <span class="cm-variable">num</span> <span class="cm-comment">###: number ###</span><span class="cm-punctuation">)</span> <span class="cm-comment">###: string ###</span> <span class="cm-operator">-></span>
|
||||
<span class="cm-variable">str</span> <span class="cm-operator">+</span> <span class="cm-variable">num</span>
|
||||
<span class="cm-comment">###::</span>
|
||||
<span class="cm-comment">type Obj = {</span>
|
||||
<span class="cm-comment"> num: number,</span>
|
||||
<span class="cm-comment">};</span>
|
||||
<span class="cm-comment">###</span>
|
||||
|
||||
<span class="cm-variable">fn</span> <span class="cm-punctuation">=</span> <span class="cm-punctuation">(</span><span class="cm-variable">str</span> <span class="cm-comment">###: string ###</span><span class="cm-punctuation">,</span> <span class="cm-variable">obj</span> <span class="cm-comment">###: Obj ###</span><span class="cm-punctuation">)</span> <span class="cm-comment">###: string ###</span> <span class="cm-operator">-></span>
|
||||
<span class="cm-variable">str</span> <span class="cm-operator">+</span> <span class="cm-variable">obj</span><span class="cm-punctuation">.</span><span class="cm-property">num</span>
|
||||
</pre>
|
||||
</div>
|
||||
<div class="col-md-6 javascript-output-column">
|
||||
<textarea class="javascript-output" id="type_annotations-js">// @flow
|
||||
var fn;
|
||||
|
||||
fn = function(str/*: string */, num/*: number */)/*: string */ {
|
||||
return str + num;
|
||||
/*::
|
||||
type Obj = {
|
||||
num: number,
|
||||
};
|
||||
*/
|
||||
fn = function(str/*: string */, obj/*: Obj */)/*: string */ {
|
||||
return str + obj.num;
|
||||
};
|
||||
</textarea>
|
||||
<pre class="placeholder-code"><span class="cm-comment">// @flow</span>
|
||||
<span class="cm-keyword">var</span> <span class="cm-def">fn</span>;
|
||||
|
||||
<span class="cm-variable">fn</span> <span class="cm-operator">=</span> <span class="cm-keyword">function</span>(<span class="cm-def">str</span><span class="cm-comment">/*: string */</span>, <span class="cm-def">num</span><span class="cm-comment">/*: number */</span>)<span class="cm-comment">/*: string */</span> {
|
||||
<span class="cm-keyword">return</span> <span class="cm-variable-2">str</span> <span class="cm-operator">+</span> <span class="cm-variable-2">num</span>;
|
||||
<span class="cm-comment">/*::</span>
|
||||
<span class="cm-comment">type Obj = {</span>
|
||||
<span class="cm-comment"> num: number,</span>
|
||||
<span class="cm-comment">};</span>
|
||||
<span class="cm-comment">*/</span>
|
||||
<span class="cm-variable">fn</span> <span class="cm-operator">=</span> <span class="cm-keyword">function</span>(<span class="cm-def">str</span><span class="cm-comment">/*: string */</span>, <span class="cm-def">obj</span><span class="cm-comment">/*: Obj */</span>)<span class="cm-comment">/*: string */</span> {
|
||||
<span class="cm-keyword">return</span> <span class="cm-variable-2">str</span> <span class="cm-operator">+</span> <span class="cm-variable-2">obj</span>.<span class="cm-property">num</span>;
|
||||
};
|
||||
</pre>
|
||||
</div>
|
||||
@@ -4713,7 +4771,7 @@ If you’ve ever learned a neat CoffeeScript tip or trick, or ran into a gotcha
|
||||
Perhaps your CoffeeScript-related question has been asked before. Check the FAQ first.</li>
|
||||
<li><a href="http://js2.coffee/">JS2Coffee</a><br>
|
||||
Is a very well done reverse JavaScript-to-CoffeeScript compiler. It’s not going to be perfect (infer what your JavaScript classes are, when you need bound functions, and so on…) — but it’s a great starting point for converting simple scripts.</li>
|
||||
<li><a href="https://github.com/jashkenas/coffeescript/tree/master/documentation/images">High-Rez Logo</a><br>
|
||||
<li><a href="https://github.com/jashkenas/coffeescript/tree/master/documentation/site">High-Rez Logo</a><br>
|
||||
The CoffeeScript logo is available in SVG for use in presentations.</li>
|
||||
</ul>
|
||||
|
||||
@@ -4762,7 +4820,7 @@ The CoffeeScript logo is available in SVG for use in presentations.</li>
|
||||
</section>
|
||||
<section id="annotated-source">
|
||||
<h2>Annotated Source</h2>
|
||||
<p>You can browse the CoffeeScript 2.0.0 source in readable, annotated form <a href="annotated-source/">here</a>. You can also jump directly to a particular source file:</p>
|
||||
<p>You can browse the CoffeeScript 2.0.1 source in readable, annotated form <a href="annotated-source/">here</a>. You can also jump directly to a particular source file:</p>
|
||||
<ul>
|
||||
<li><a href="annotated-source/grammar.html">Grammar Rules — src/grammar</a></li>
|
||||
<li><a href="annotated-source/lexer.html">Lexing Tokens — src/lexer</a></li>
|
||||
@@ -5390,10 +5448,19 @@ x = <span class="number">2</span> + <span class="number">2</span>
|
||||
</section>
|
||||
<section id="changelog">
|
||||
<h2>Changelog</h2>
|
||||
<div class="anchor" id="2.0.1"></div>
|
||||
<h2 class="header">
|
||||
<a href="https://github.com/jashkenas/coffeescript/compare/2.0.0...2.0.1">2.0.1</a>
|
||||
<span class="timestamp"> — <time datetime="2017-09-26">September 26, 2017</time></span>
|
||||
</h2><ul>
|
||||
<li><code>babel-core</code> is no longer listed in <code>package.json</code>, even as an <code>optionalDependency</code>, to avoid it being automatically installed for most users. If you wish to use <code>--transpile</code>, simply install <code>babel-core</code> manually. See <a href="#transpilation">Transpilation</a>.</li>
|
||||
<li><code>--transpile</code> now relies on Babel to find its options, i.e. the <code>.babelrc</code> file in the path of the file(s) being compiled. (Previously the CoffeeScript compiler was duplicating this logic, so nothing has changed from a user’s perspective.) This provides automatic support for additional ways to pass options to Babel in future versions, such as the <code>.babelrc.js</code> file coming in Babel 7.</li>
|
||||
<li>Backticked expressions in a class body, outside any class methods, are now output in the JavaScript class body itself. This allows for passing through experimental JavaScript syntax like the <a href="https://github.com/tc39/proposal-class-fields">class fields proposal</a>, assuming your <a href="https://babeljs.io/docs/plugins/transform-class-properties/">transpiler supports it</a>.</li>
|
||||
</ul>
|
||||
<div class="anchor" id="2.0.0"></div>
|
||||
<h2 class="header">
|
||||
<a href="https://github.com/jashkenas/coffeescript/compare/2.0.0-beta5...2.0.0">2.0.0</a>
|
||||
<span class="timestamp"> — <time datetime="2017-09-17">September 17, 2017</time></span>
|
||||
<span class="timestamp"> — <time datetime="2017-09-18">September 18, 2017</time></span>
|
||||
</h2><ul>
|
||||
<li>Added <code>--transpile</code> flag or <code>transpile</code> Node API option to tell the CoffeeScript compiler to pipe its output through Babel before saving or returning it; see <a href="#transpilation">Transpilation</a>. Also changed the <code>-t</code> short flag to refer to <code>--transpile</code> instead of <code>--tokens</code>.</li>
|
||||
<li>Always populate source maps’ <code>sourcesContent</code> property.</li>
|
||||
@@ -5586,21 +5653,12 @@ x = <span class="number">2</span> + <span class="number">2</span>
|
||||
<a href="https://github.com/jashkenas/coffeescript/compare/1.10.0...1.11.0">1.11.0</a>
|
||||
<span class="timestamp"> — <time datetime="2016-09-24">September 24, 2016</time></span>
|
||||
</h2><ul>
|
||||
<li>
|
||||
<p>CoffeeScript now supports ES2015 <a href="#modules"><code>import</code> and <code>export</code> syntax</a>.</p>
|
||||
</li>
|
||||
<li>
|
||||
<p>Added the <code>-M, --inline-map</code> flag to the compiler, allowing you embed the source map directly into the output JavaScript, rather than as a separate file.</p>
|
||||
</li>
|
||||
<li>
|
||||
<p>A bunch of fixes for <code>yield</code>:</p>
|
||||
<li>CoffeeScript now supports ES2015 <a href="#modules"><code>import</code> and <code>export</code> syntax</a>.</li>
|
||||
<li>Added the <code>-M, --inline-map</code> flag to the compiler, allowing you embed the source map directly into the output JavaScript, rather than as a separate file.</li>
|
||||
<li>A bunch of fixes for <code>yield</code>:
|
||||
<ul>
|
||||
<li>
|
||||
<p><code>yield return</code> can no longer mistakenly be used as an expression.</p>
|
||||
</li>
|
||||
<li>
|
||||
<p><code>yield</code> now mirrors <code>return</code> in that it can be used stand-alone as well as with expressions. Where you previously wrote <code>yield undefined</code>, you may now write simply <code>yield</code>. However, this means also inheriting the same syntax limitations that <code>return</code> has, so these examples no longer compile:</p>
|
||||
<blockquote class="uneditable-code-block"><pre><code>doubles = ->
|
||||
<li><code>yield return</code> can no longer mistakenly be used as an expression.</li>
|
||||
<li><code>yield</code> now mirrors <code>return</code> in that it can be used stand-alone as well as with expressions. Where you previously wrote <code>yield undefined</code>, you may now write simply <code>yield</code>. However, this means also inheriting the same syntax limitations that <code>return</code> has, so these examples no longer compile:<blockquote class="uneditable-code-block"><pre><code>doubles = ->
|
||||
yield for i in [1..3]
|
||||
i * 2
|
||||
six = ->
|
||||
@@ -5608,28 +5666,15 @@ six = ->
|
||||
2 * 3
|
||||
</code></pre>
|
||||
</blockquote></li>
|
||||
<li>
|
||||
<p>The JavaScript output is a bit nicer, with unnecessary parentheses and spaces, double indentation and double semicolons around <code>yield</code> no longer present.</p>
|
||||
</li>
|
||||
<li>The JavaScript output is a bit nicer, with unnecessary parentheses and spaces, double indentation and double semicolons around <code>yield</code> no longer present.</li>
|
||||
</ul>
|
||||
</li>
|
||||
<li>
|
||||
<p><code>&&=</code>, <code>||=</code>, <code>and=</code> and <code>or=</code> no longer accidentally allow a space before the equals sign.</p>
|
||||
</li>
|
||||
<li>
|
||||
<p>Improved several error messages.</p>
|
||||
</li>
|
||||
<li>
|
||||
<p>Just like <code>undefined</code> compiles to <code>void 0</code>, <code>NaN</code> now compiles into <code>0/0</code> and <code>Infinity</code> into <code>2e308</code>.</p>
|
||||
</li>
|
||||
<li>
|
||||
<p>Bugfix for renamed destructured parameters with defaults. <code>({a: b = 1}) -></code> no longer crashes the compiler.</p>
|
||||
</li>
|
||||
<li>
|
||||
<p>Improved the internal representation of a CoffeeScript program. This is only noticeable to tools that use <code>CoffeeScript.tokens</code> or <code>CoffeeScript.nodes</code>. Such tools need to update to take account for changed or added tokens and nodes.</p>
|
||||
</li>
|
||||
<li>
|
||||
<p>Several minor bug fixes, including:</p>
|
||||
<li><code>&&=</code>, <code>||=</code>, <code>and=</code> and <code>or=</code> no longer accidentally allow a space before the equals sign.</li>
|
||||
<li>Improved several error messages.</li>
|
||||
<li>Just like <code>undefined</code> compiles to <code>void 0</code>, <code>NaN</code> now compiles into <code>0/0</code> and <code>Infinity</code> into <code>2e308</code>.</li>
|
||||
<li>Bugfix for renamed destructured parameters with defaults. <code>({a: b = 1}) -></code> no longer crashes the compiler.</li>
|
||||
<li>Improved the internal representation of a CoffeeScript program. This is only noticeable to tools that use <code>CoffeeScript.tokens</code> or <code>CoffeeScript.nodes</code>. Such tools need to update to take account for changed or added tokens and nodes.</li>
|
||||
<li>Several minor bug fixes, including:
|
||||
<ul>
|
||||
<li>The caught error in <code>catch</code> blocks is no longer declared unnecessarily, and no longer mistakenly named <code>undefined</code> for <code>catch</code>-less <code>try</code> blocks.</li>
|
||||
<li>Unassignable parameter destructuring no longer crashes the compiler.</li>
|
||||
@@ -5646,14 +5691,9 @@ six = ->
|
||||
<a href="https://github.com/jashkenas/coffeescript/compare/1.9.3...1.10.0">1.10.0</a>
|
||||
<span class="timestamp"> — <time datetime="2015-09-03">September 3, 2015</time></span>
|
||||
</h2><ul>
|
||||
<li>
|
||||
<p>CoffeeScript now supports ES2015-style destructuring defaults.</p>
|
||||
</li>
|
||||
<li>
|
||||
<p><code>(offsetHeight: height) -></code> no longer compiles. That syntax was accidental and partly broken. Use <code>({offsetHeight: height}) -></code> instead. Object destructuring always requires braces.</p>
|
||||
</li>
|
||||
<li>
|
||||
<p>Several minor bug fixes, including:</p>
|
||||
<li>CoffeeScript now supports ES2015-style destructuring defaults.</li>
|
||||
<li><code>(offsetHeight: height) -></code> no longer compiles. That syntax was accidental and partly broken. Use <code>({offsetHeight: height}) -></code> instead. Object destructuring always requires braces.</li>
|
||||
<li>Several minor bug fixes, including:
|
||||
<ul>
|
||||
<li>A bug where the REPL would sometimes report valid code as invalid, based on what you had typed earlier.</li>
|
||||
<li>A problem with multiple JS contexts in the jest test framework.</li>
|
||||
@@ -6078,7 +6118,7 @@ The <code>extends</code> keyword now functions identically to <code>goog.inherit
|
||||
|
||||
<script src="browser-compiler/coffeescript.js"></script>
|
||||
<script>
|
||||
(function(){window.location.origin||(window.location.origin=window.location.protocol+'//'+window.location.hostname),$(document).ready(function(){var a,b,c,d,e,f,g,h,i,j;if(i=function(){return $('.navbar-toggler, .sidebar').toggleClass('show')},$('[data-toggle="offcanvas"]').click(i),$('[data-action="sidebar-nav"]').click(function(a){return $('.navbar-toggler').is(':visible')&&(a.preventDefault(),i(),setTimeout(function(){return window.location=a.target.href},260)),gtag('event','sidebar_navigate',{event_category:'navigation',event_label:a.target.href.replace(window.location.origin,'')})}),$('body').scrollspy({target:'#contents',offset:Math.round($('main').css('padding-top').replace('px',''))}),e=function(a){return $('#contents a.active[href!=\''+a+'\']').removeClass('show')},$(window).on('activate.bs.scrollspy',function(a,b){var c;if($('#contents a.active[href!=\''+b.relatedTarget+'\']').removeClass('show'),c=$('#contents a[href=\''+b.relatedTarget+'\']'),c.prop('href')!==window.location.origin+'/#try')return window.history.pushState({},c.text(),c.prop('href')),gtag('config',GA_TRACKING_ID,{page_path:c.prop('href').replace(window.location.origin,'')})}),h=[],c=[],g=200,$('textarea').each(function(a){return h[a]=this,$(this).data('index',a)}),d=function(a){var b,d,e,f;if(d=a.data('index'),e=a.hasClass('javascript-output')?'javascript':'coffeescript',c[d]=b=CodeMirror.fromTextArea(a[0],{mode:e,theme:'twilight',indentUnit:2,tabSize:2,lineWrapping:!0,lineNumbers:!1,inputStyle:'contenteditable',readOnly:'coffeescript'!==e,viewportMargin:2e308}),'coffeescript'===e)return f=null,b.on('change',function(){return clearTimeout(f),f=setTimeout(function(){var e,f,h,i,j;h=Date.now();try{if(e=b.getValue(),0===d&&$('#try').hasClass('show')){i='try:'+encodeURIComponent(e),window.history.pushState({},'CoffeeScript',location.href.split('#')[0]+'#'+i);try{null!=window.localStorage&&window.localStorage.setItem('tryCoffeeScriptCode',e)}catch(a){f=a}}j=CoffeeScript.compile(e,{bare:!0}),g=Math.max(200,Date.now()-h)}catch(a){f=a,j=''+f}return c[d+1].setValue(j),gtag('event','edit_code',{event_category:'engagement',event_label:a.closest('[data-example]').data('example')})},g)}),b.addKeyMap({Tab:function Tab(a){return a.somethingSelected()?a.indentSelection('add'):/^\t/m.test(a.getValue())?a.execCommand('insertTab'):a.execCommand('insertSoftTab')},"Shift-Tab":function ShiftTab(a){return a.indentSelection('subtract')},Enter:function Enter(a){return a.options.indentWithTabs=/^\t/m.test(a.getValue()),a.execCommand('newlineAndIndent')}})},$('.placeholder-code').one('mouseover',function(){var a,b;return b=$(this).prev('textarea'),$(this).remove(),d(b),a=$(b.parent().siblings()[0]),a.children('.placeholder-code').remove(),d($(a.children('textarea')[0]))}),f=function(){return d($('#try-coffeescript-coffee')),d($('#try-coffeescript-js'))},$('[data-action="run-code-example"]').click(function(){var a,b,d;return d=$(this).data('run'),a=$('#'+$(this).data('example')+'-js').data('index'),b=null==c[a]?$(h[a]).val():c[a].getValue(),!0!==d&&(b=b+'\nalert('+unescape(d)+');'),eval(b),gtag('event','run_code',{event_category:'engagement',event_label:$(this).closest('[data-example]').data('example')})}),a=function(){return window.history.pushState('',document.title,window.location.pathname)},$(window).on('hashchange',function(){if(''===window.location.hash)return a()}),j=function(){var b,d=0<arguments.length&&void 0!==arguments[0]&&arguments[0];if(0===$('#try .CodeMirror').length&&f(),d&&null!=window.localStorage)try{b=window.localStorage.getItem('tryCoffeeScriptCode'),null!=b&&c[0].setValue(b)}catch(a){}return($('#try, #try-link').toggleClass('show'),!$('#try').hasClass('show'))?setTimeout(a,200):void 0},b=function(){return $('#try, #try-link').removeClass('show'),window.history.pushState('',document.title,window.location.pathname)},$('[data-toggle="try"]').click(j),$('[data-close="try"]').click(b),null!=window.location.hash){if('#try'===window.location.hash)return j(!0);if(0===window.location.hash.indexOf('#try'))return 0===$('#try .CodeMirror').length&&f(),c[0].setValue(decodeURIComponent(window.location.hash.slice(5))),j();if(''===window.location.hash)return a();if(e(window.location.hash),1<window.location.hash.length)return document.getElementById(window.location.hash.slice(1).replace(/try:.*/,'')).scrollIntoView()}})}).call(this);
|
||||
(function(){window.location.origin||(window.location.origin=window.location.protocol+'//'+window.location.hostname),$(document).ready(function(){var a,b,c,d,e,f,g,h,i,j,k,l;if(k=function(){return $('.navbar-toggler, .sidebar').toggleClass('show')},$('[data-toggle="offcanvas"]').click(k),$('[data-action="sidebar-nav"]').click(function(a){return $('.navbar-toggler').is(':visible')&&(a.preventDefault(),k(),setTimeout(function(){return window.location=a.target.href},260)),gtag('event','sidebar_navigate',{event_category:'navigation',event_label:a.target.href.replace(window.location.origin,'')})}),$('body').scrollspy({target:'#contents',offset:Math.round($('main').css('padding-top').replace('px',''))}),e=function(a){return $('#contents a.active[href!=\''+a+'\']').removeClass('show')},$(window).on('activate.bs.scrollspy',function(a,b){var c;if($('#contents a.active[href!=\''+b.relatedTarget+'\']').removeClass('show'),c=$('#contents a[href=\''+b.relatedTarget+'\']'),c.prop('href')!==window.location.origin+'/#try')return i(c.prop('href')),gtag('config',GA_TRACKING_ID,{page_path:c.prop('href').replace(window.location.origin,'')})}),j=[],c=[],g=200,$('textarea').each(function(a){return j[a]=this,$(this).data('index',a)}),d=function(a){var b,d,e,f;if(d=a.data('index'),e=a.hasClass('javascript-output')?'javascript':'coffeescript',c[d]=b=CodeMirror.fromTextArea(a[0],{mode:e,theme:'twilight',indentUnit:2,tabSize:2,lineWrapping:!0,lineNumbers:!1,inputStyle:'contenteditable',readOnly:'coffeescript'!==e,viewportMargin:2e308}),'coffeescript'===e)return f=null,b.on('change',function(){return clearTimeout(f),f=setTimeout(function(){var e,f,h,j,k;h=Date.now();try{if(e=b.getValue(),0===d&&$('#try').hasClass('show')){$('#try').hasClass('show')&&(j='try:'+encodeURIComponent(e),i(window.location.href.split('#')[0]+'#'+j));try{null!=window.localStorage&&window.localStorage.setItem('tryCoffeeScriptCode',e)}catch(a){f=a}}k=CoffeeScript.compile(e,{bare:!0}),g=Math.max(200,Date.now()-h)}catch(a){f=a,k=''+f}return c[d+1].setValue(k),gtag('event','edit_code',{event_category:'engagement',event_label:a.closest('[data-example]').data('example')})},g)}),b.addKeyMap({Tab:function Tab(a){return a.somethingSelected()?a.indentSelection('add'):/^\t/m.test(a.getValue())?a.execCommand('insertTab'):a.execCommand('insertSoftTab')},"Shift-Tab":function ShiftTab(a){return a.indentSelection('subtract')},Enter:function Enter(a){return a.options.indentWithTabs=/^\t/m.test(a.getValue()),a.execCommand('newlineAndIndent')}})},$('.placeholder-code').one('mouseover',function(){var a,b;return b=$(this).prev('textarea'),$(this).remove(),d(b),a=$(b.parent().siblings()[0]),a.children('.placeholder-code').remove(),d($(a.children('textarea')[0]))}),f=function(){return d($('#try-coffeescript-coffee')),d($('#try-coffeescript-js'))},$('[data-action="run-code-example"]').click(function(){var a,b,d;return d=$(this).data('run'),a=$('#'+$(this).data('example')+'-js').data('index'),b=null==c[a]?$(j[a]).val():c[a].getValue(),!0!==d&&(b=b+'\nalert('+unescape(d)+');'),eval(b),gtag('event','run_code',{event_category:'engagement',event_label:$(this).closest('[data-example]').data('example')})}),h=null,l=function(b){var d,e;if($('#try, #try-link').toggleClass('show'),!$('#try').hasClass('show'))return h?i(h):a();if(window.location.hash&&(h=window.location.hash),0===$('#try .CodeMirror').length&&f(),b&&null!=window.localStorage)try{return d=window.localStorage.getItem('tryCoffeeScriptCode'),null==d?i('#try'):c[0].setValue(d)}catch(a){return e=a,i('#try')}else return i('#try')},b=function(){return $('#try, #try-link').removeClass('show'),h?i(h):a()},$('[data-toggle="try"]').click(function(a){return a.preventDefault(),l(!0)}),$('[data-close="try"]').click(b),a=function(){return window.history.replaceState({},document.title,window.location.pathname)},i=function(a){return 0===(null==a?void 0:a.indexOf('#'))&&(a=''+window.location.pathname+a),window.history.replaceState({},document.title,a||'')},$(window).on('hashchange',function(){if(''===window.location.hash)return a()}),null!=window.location.hash){if('#try'===window.location.hash)return l(!0);if(0===window.location.hash.indexOf('#try'))return 0===$('#try .CodeMirror').length&&f(),c[0].setValue(decodeURIComponent(window.location.hash.slice(5))),l(!1);if(''===window.location.hash)return a();if(e(window.location.hash),1<window.location.hash.length)return document.getElementById(window.location.hash.slice(1).replace(/try:.*/,'')).scrollIntoView()}})}).call(this);
|
||||
</script>
|
||||
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-106156830-1"></script>
|
||||
<script>
|
||||
|
||||
@@ -3529,6 +3529,21 @@ test "#4591: super.x.y, super['x'].y", ->
|
||||
eq 2, b.s
|
||||
eq 2, b.r
|
||||
|
||||
test "#4464: backticked expressions in class body", ->
|
||||
class A
|
||||
`get x() { return 42; }`
|
||||
|
||||
class B
|
||||
`get x() { return 42; }`
|
||||
constructor: ->
|
||||
@y = 84
|
||||
|
||||
a = new A
|
||||
eq 42, a.x
|
||||
b = new B
|
||||
eq 42, b.x
|
||||
eq 84, b.y
|
||||
|
||||
</script>
|
||||
<script type="text/x-coffeescript" class="test" id="cluster">
|
||||
# Cluster Module
|
||||
|
||||
@@ -1,4 +1,10 @@
|
||||
# @flow
|
||||
|
||||
fn = (str ###: string ###, num ###: number ###) ###: string ### ->
|
||||
str + num
|
||||
###::
|
||||
type Obj = {
|
||||
num: number,
|
||||
};
|
||||
###
|
||||
|
||||
fn = (str ###: string ###, obj ###: Obj ###) ###: string ### ->
|
||||
str + obj.num
|
||||
|
||||
@@ -1,7 +1,15 @@
|
||||
## Changelog
|
||||
|
||||
```
|
||||
releaseHeader('2017-09-17', '2.0.0', '2.0.0-beta5')
|
||||
releaseHeader('2017-09-26', '2.0.1', '2.0.0')
|
||||
```
|
||||
|
||||
* `babel-core` is no longer listed in `package.json`, even as an `optionalDependency`, to avoid it being automatically installed for most users. If you wish to use `--transpile`, simply install `babel-core` manually. See [Transpilation](#transpilation).
|
||||
* `--transpile` now relies on Babel to find its options, i.e. the `.babelrc` file in the path of the file(s) being compiled. (Previously the CoffeeScript compiler was duplicating this logic, so nothing has changed from a user’s perspective.) This provides automatic support for additional ways to pass options to Babel in future versions, such as the `.babelrc.js` file coming in Babel 7.
|
||||
* Backticked expressions in a class body, outside any class methods, are now output in the JavaScript class body itself. This allows for passing through experimental JavaScript syntax like the [class fields proposal](https://github.com/tc39/proposal-class-fields), assuming your [transpiler supports it](https://babeljs.io/docs/plugins/transform-class-properties/).
|
||||
|
||||
```
|
||||
releaseHeader('2017-09-18', '2.0.0', '2.0.0-beta5')
|
||||
```
|
||||
|
||||
* Added `--transpile` flag or `transpile` Node API option to tell the CoffeeScript compiler to pipe its output through Babel before saving or returning it; see [Transpilation](#transpilation). Also changed the `-t` short flag to refer to `--transpile` instead of `--tokens`.
|
||||
@@ -184,7 +192,6 @@ releaseHeader('2016-09-24', '1.11.0', '1.10.0')
|
||||
* CoffeeScript now supports ES2015 [`import` and `export` syntax](#modules).
|
||||
* Added the `-M, --inline-map` flag to the compiler, allowing you embed the source map directly into the output JavaScript, rather than as a separate file.
|
||||
* A bunch of fixes for `yield`:
|
||||
|
||||
* `yield return` can no longer mistakenly be used as an expression.
|
||||
* `yield` now mirrors `return` in that it can be used stand-alone as well as with expressions. Where you previously wrote `yield undefined`, you may now write simply `yield`. However, this means also inheriting the same syntax limitations that `return` has, so these examples no longer compile:
|
||||
```
|
||||
@@ -195,7 +202,6 @@ releaseHeader('2016-09-24', '1.11.0', '1.10.0')
|
||||
yield
|
||||
2 * 3
|
||||
```
|
||||
|
||||
* The JavaScript output is a bit nicer, with unnecessary parentheses and spaces, double indentation and double semicolons around `yield` no longer present.
|
||||
* `&&=`, `||=`, `and=` and `or=` no longer accidentally allow a space before the equals sign.
|
||||
* Improved several error messages.
|
||||
@@ -203,7 +209,6 @@ releaseHeader('2016-09-24', '1.11.0', '1.10.0')
|
||||
* Bugfix for renamed destructured parameters with defaults. `({a: b = 1}) ->` no longer crashes the compiler.
|
||||
* Improved the internal representation of a CoffeeScript program. This is only noticeable to tools that use `CoffeeScript.tokens` or `CoffeeScript.nodes`. Such tools need to update to take account for changed or added tokens and nodes.
|
||||
* Several minor bug fixes, including:
|
||||
|
||||
* The caught error in `catch` blocks is no longer declared unnecessarily, and no longer mistakenly named `undefined` for `catch`-less `try` blocks.
|
||||
* Unassignable parameter destructuring no longer crashes the compiler.
|
||||
* Source maps are now used correctly for errors thrown from .coffee.md files.
|
||||
@@ -219,7 +224,6 @@ releaseHeader('2015-09-03', '1.10.0', '1.9.3')
|
||||
* CoffeeScript now supports ES2015-style destructuring defaults.
|
||||
* `(offsetHeight: height) ->` no longer compiles. That syntax was accidental and partly broken. Use `({offsetHeight: height}) ->` instead. Object destructuring always requires braces.
|
||||
* Several minor bug fixes, including:
|
||||
|
||||
* A bug where the REPL would sometimes report valid code as invalid, based on what you had typed earlier.
|
||||
* A problem with multiple JS contexts in the jest test framework.
|
||||
* An error in io.js where strict mode is set on internal modules.
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
## Installation
|
||||
|
||||
The command-line version of `coffee` is available as a [Node.js](https://nodejs.org/) utility. The [core compiler](/v<%= majorVersion %>/browser-compiler/coffeescript.js) however, does not depend on Node, and can be run in any JavaScript environment, or in the browser (see [Try CoffeeScript](#try)).
|
||||
The command-line version of `coffee` is available as a [Node.js](https://nodejs.org/) utility, requiring Node 6 or later. The [core compiler](/v<%= majorVersion %>/browser-compiler/coffeescript.js) however, does not depend on Node, and can be run in any JavaScript environment, or in the browser (see [Try CoffeeScript](#try)).
|
||||
|
||||
To install, first make sure you have a working copy of the latest stable version of [Node.js](https://nodejs.org/). You can then install CoffeeScript globally with [npm](https://www.npmjs.com/):
|
||||
|
||||
@@ -10,10 +10,12 @@ npm install --global coffeescript
|
||||
|
||||
This will make the `coffee` and `cake` commands available globally.
|
||||
|
||||
When you need CoffeeScript as a dependency of a project, within that project’s folder you can install it locally:
|
||||
If you are using CoffeeScript in a project, you should install it locally for that project so that the version of CoffeeScript is tracked as one of your project’s dependencies. Within that project’s folder:
|
||||
|
||||
```bash
|
||||
npm install --save-dev coffeescript
|
||||
```
|
||||
|
||||
The `coffee` and `cake` commands will first look in the current folder to see if CoffeeScript is installed locally, and use that version if so. This allows different versions of CoffeeScript to be installed globally and locally.
|
||||
|
||||
If you plan to use the `--transpile` option (see [Transpilation](#transpilation)) you will need to also install `babel-core` either globally or locally, depending on whether you are running a globally or locally installed version of CoffeeScript.
|
||||
@@ -5,5 +5,9 @@ The golden rule of CoffeeScript is: _“It’s just JavaScript.”_ The code com
|
||||
**Latest Version:** [<%= fullVersion %>](https://github.com/jashkenas/coffeescript/tarball/<%= fullVersion %>)
|
||||
|
||||
```bash
|
||||
npm install -g coffeescript
|
||||
# Install locally for a project:
|
||||
npm install --save-dev coffeescript
|
||||
|
||||
# Install globally to execute .coffee files anywhere:
|
||||
npm install --global coffeescript
|
||||
```
|
||||
|
||||
@@ -11,5 +11,5 @@
|
||||
Perhaps your CoffeeScript-related question has been asked before. Check the FAQ first.
|
||||
* [JS2Coffee](http://js2.coffee/)<br>
|
||||
Is a very well done reverse JavaScript-to-CoffeeScript compiler. It’s not going to be perfect (infer what your JavaScript classes are, when you need bound functions, and so on…) — but it’s a great starting point for converting simple scripts.
|
||||
* [High-Rez Logo](https://github.com/jashkenas/coffeescript/tree/master/documentation/images)<br>
|
||||
* [High-Rez Logo](https://github.com/jashkenas/coffeescript/tree/master/documentation/site)<br>
|
||||
The CoffeeScript logo is available in SVG for use in presentations.
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
### Transpilation
|
||||
|
||||
CoffeeScript 2 generates JavaScript that uses the latest, modern syntax. Your runtime [might not support all of that syntax](#compatibility). If so, you need to _transpile_ the JavaScript. To make things a little easier, CoffeeScript has built-in support for the popular [Babel](http://babeljs.io/) transpiler.
|
||||
CoffeeScript 2 generates JavaScript that uses the latest, modern syntax. The runtime or browsers where you want your code to run [might not support all of that syntax](#compatibility). In that case, we want to convert modern JavaScript into older JavaScript that will run in older versions of Node or older browsers; for example, `{ a } = obj` into `a = obj.a`. This is done via transpilers like [Babel](http://babeljs.io/), [Bublé](https://buble.surge.sh/) or [Traceur Compiler](https://github.com/google/traceur-compiler).
|
||||
|
||||
#### Quickstart
|
||||
|
||||
@@ -12,29 +12,29 @@ echo '{ "presets": ["env"] }' > .babelrc
|
||||
coffee --compile --transpile --inline-map some-file.coffee
|
||||
```
|
||||
|
||||
#### About Transpilation
|
||||
#### Transpiling with the CoffeeScript compiler
|
||||
|
||||
Transpilation is the conversion of source code into equivalent but different source code. In our case, we want to convert modern JavaScript into older JavaScript that will run in older versions of Node or older browsers; for example, `{ a } = obj` into `a = obj.a`. This is done via transpilers like [Babel](http://babeljs.io/), [Bublé](https://buble.surge.sh/) or [Traceur Compiler](https://github.com/google/traceur-compiler).
|
||||
|
||||
CoffeeScript includes a `--transpile` option when used via the `coffee` command, or a `transpile` option when used via Node. To use either, [Babel](http://babeljs.io/) must be installed in your project:
|
||||
To make things easy, CoffeeScript has built-in support for the popular [Babel](http://babeljs.io/) transpiler. You can use it via the `--transpile` command-line option or the `transpile` Node API option. To use either, `babel-core` must be installed in your project:
|
||||
|
||||
```bash
|
||||
npm install --save-dev babel-core
|
||||
```
|
||||
|
||||
By default, Babel doesn’t do anything—it doesn’t make assumptions about what you want to transpile to. You might know that your code will run in Node 8, and so you want Babel to transpile modules and JSX and nothing else. Or you might want to support Internet Explorer 8, in which case Babel will transpile every feature introduced in ES2015 and later specs.
|
||||
|
||||
If you’re not sure what you need, a good starting point is [`babel-preset-env`](https://babeljs.io/docs/plugins/preset-env/):
|
||||
Or if you’re running the `coffee` command outside of a project folder, using a globally-installed `coffeescript` module, `babel-core` needs to be installed globally:
|
||||
|
||||
```bash
|
||||
npm install --save-dev babel-preset-env
|
||||
npm install --global babel-core
|
||||
```
|
||||
|
||||
See [Babel’s website to learn about presets and plugins](https://babeljs.io/docs/plugins/) and the multitude of options you have.
|
||||
By default, Babel doesn’t do anything—it doesn’t make assumptions about what you want to transpile to. You need to provide it with a configuration so that it knows what to do. One way to do this is by creating a [`.babelrc` file](https://babeljs.io/docs/usage/babelrc/) in the folder containing the files you’re compiling, or in any parent folder up the path above those files. (Babel supports [other ways](https://babeljs.io/docs/usage/babelrc/), too.) A minimal `.babelrc` file would be just `{ "presets": ["env"] }`. This implies that you have installed [`babel-preset-env`](https://babeljs.io/docs/plugins/preset-env/):
|
||||
|
||||
Simply installing `babel-preset-env` isn’t enough. You also need to define the configuration options that you want Babel to use. You can do this by creating a [`.babelrc` file](https://babeljs.io/docs/usage/babelrc/) in the folder containing the files you’re compiling, or in any parent folder up the path above those files. So if your project is in `~/app` and your files are in `~/app/src`, you can put `.babelrc` in either `~/app` or in `~/app/src`. You can also define the Babel options via a `babel` key in the `package.json` file for your project. A minimal `.babelrc` file (or `package.json` `babel` key) for use with `babel-preset-env` would be just `{ "presets": ["env"] }`.
|
||||
```bash
|
||||
npm install --save-dev babel-preset-env # Or --global for non-project-based usage
|
||||
```
|
||||
|
||||
Once you have `babel-core` and `babel-preset-env` (or other presets or plugins) installed, and a `.babelrc` file (or `package.json` `babel` key) in place, you can use `coffee --transpile` to pipe CoffeeScript’s output through Babel using the options you’ve saved.
|
||||
See [Babel’s website to learn about presets and plugins](https://babeljs.io/docs/plugins/) and the multitude of options you have. Another preset you might need is [`transform-react-jsx`](https://babeljs.io/docs/plugins/transform-react-jsx/) if you’re using JSX with React (JSX can also be used with other frameworks).
|
||||
|
||||
Once you have `babel-core` and `babel-preset-env` (or other presets or plugins) installed, and a `.babelrc` file (or other equivalent) in place, you can use `coffee --transpile` to pipe CoffeeScript’s output through Babel using the options you’ve saved.
|
||||
|
||||
If you’re using CoffeeScript via the [Node API](nodejs_usage), where you call `CoffeeScript.compile` with a string to be compiled and an `options` object, the `transpile` key of the `options` object should be the Babel options:
|
||||
|
||||
@@ -44,4 +44,6 @@ CoffeeScript.compile(code, {transpile: {presets: ['env']}})
|
||||
|
||||
You can also transpile CoffeeScript’s output without using the `transpile` option, for example as part of a build chain. This lets you use transpilers other than Babel, and it gives you greater control over the process. There are many great task runners for setting up JavaScript build chains, such as [Gulp](http://gulpjs.com/), [Webpack](https://webpack.github.io/), [Grunt](https://gruntjs.com/) and [Broccoli](http://broccolijs.com/).
|
||||
|
||||
Note that [babel-preset-env](https://babeljs.io/docs/plugins/preset-env/) doesn’t automatically supply [polyfills](https://developer.mozilla.org/en-US/docs/Glossary/Polyfill) for your code. CoffeeScript itself will output [`Array.indexOf`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/indexOf) if you use the `in` operator, or destructuring or spread/rest syntax; and [`Function.bind`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind) if you use a bound (`=>`) method in a class. Both are supported in Internet Explorer 9+ and all more recent browsers, but you will need to supply polyfills if you need to support Internet Explorer 8 or below and are using features that would cause these methods to be output. You’ll also need to supply polyfills if your own code uses these methods or another method added in recent versions of JavaScript. One polyfill option is [`babel-polyfill`](https://babeljs.io/docs/usage/polyfill/), though there are many [other](https://hackernoon.com/polyfills-everything-you-ever-wanted-to-know-or-maybe-a-bit-less-7c8de164e423) [strategies](https://philipwalton.com/articles/loading-polyfills-only-when-needed/).
|
||||
#### Polyfills
|
||||
|
||||
Note that transpiling doesn’t automatically supply [polyfills](https://developer.mozilla.org/en-US/docs/Glossary/Polyfill) for your code. CoffeeScript itself will output [`Array.indexOf`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/indexOf) if you use the `in` operator, or destructuring or spread/rest syntax; and [`Function.bind`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind) if you use a bound (`=>`) method in a class. Both are supported in Internet Explorer 9+ and all more recent browsers, but you will need to supply polyfills if you need to support Internet Explorer 8 or below and are using features that would cause these methods to be output. You’ll also need to supply polyfills if your own code uses these methods or another method added in recent versions of JavaScript. One polyfill option is [`babel-polyfill`](https://babeljs.io/docs/usage/polyfill/), though there are many [other](https://hackernoon.com/polyfills-everything-you-ever-wanted-to-know-or-maybe-a-bit-less-7c8de164e423) [strategies](https://philipwalton.com/articles/loading-polyfills-only-when-needed/).
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
### Why CoffeeScript When There’s ES6?
|
||||
|
||||
CoffeeScript introduced many new features to the JavaScript world, such as [`=>`](#fat-arrow) and [destructuring](#destructuring) and [classes](#classes). We are happy that ECMA has seen their utility and adopted them into ECMAScript.
|
||||
|
||||
CoffeeScript’s intent, however, was never to be a superset of JavaScript. One of the guiding principles of CoffeeScript has been _simplicity:_ not just removing JavaScript’s “bad parts,” but providing an elegant, concise syntax that eschews unnecessary punctuation whenever possible, to make code easier to read and reason about. This benefit of CoffeeScript remains, even in an ES2015+ world.
|
||||
@@ -8,8 +8,10 @@
|
||||
<%= include('sidebar.html') %>
|
||||
</nav>
|
||||
<main class="main col-lg-9 ml-auto">
|
||||
<header class="title-logo d-none d-lg-block">
|
||||
<%= include('logo.svg') %>
|
||||
<header class="d-none d-lg-block">
|
||||
<p class="title-logo">
|
||||
<%= include('logo.svg') %>
|
||||
</p>
|
||||
</header>
|
||||
<section id="overview">
|
||||
<%= htmlFor('introduction') %>
|
||||
@@ -20,9 +22,6 @@
|
||||
<section id="whats-new-in-coffeescript-2">
|
||||
<%= htmlFor('whats_new_in_coffeescript_2') %>
|
||||
</section>
|
||||
<section id="why-coffeescript">
|
||||
<%= htmlFor('why_coffeescript') %>
|
||||
</section>
|
||||
<section id="compatibility">
|
||||
<%= htmlFor('compatibility') %>
|
||||
</section>
|
||||
|
||||
@@ -7,12 +7,18 @@
|
||||
/* Prevent mobile Safari from zooming in on our code editors; the code is 16px naturally, but somehow being explicit about it prevents the zooming */
|
||||
font-size: 16px;
|
||||
}
|
||||
@media (min-width: 768px) {
|
||||
.CodeMirror,
|
||||
.placeholder-code {
|
||||
font-size: 90%; /* Matching Bootstrap’s font size for code, which calculates to 14.4px */
|
||||
}
|
||||
}
|
||||
.CodeMirror-lines {
|
||||
padding: 0.5em 0;
|
||||
}
|
||||
.placeholder-code {
|
||||
padding: 0.5em 4px;
|
||||
margin-bottom: 1.3rem;
|
||||
margin-bottom: 1.37em;
|
||||
white-space: pre-wrap;
|
||||
}
|
||||
div.CodeMirror-cursor {
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
<% if (run) { %>
|
||||
<div class="row">
|
||||
<div class="col text-right">
|
||||
<button type="button" class="btn btn-primary" data-action="run-code-example" data-example="<%= file %>" data-run="<%= escape(run) %>"><% if (run === true) { include('play.svg') } else { %><small><%= include('play.svg') %></small><%= run.replace(/"/g, '"') %><% } %></button>
|
||||
<button type="button" class="btn btn-primary" data-action="run-code-example" data-example="<%= file %>" data-run="<%= escape(run) %>"><small><%= include('play.svg') %></small><%= run === true ? '' : run.replace(/"/g, '"') %></button>
|
||||
</div>
|
||||
</div>
|
||||
<% } %>
|
||||
|
||||
@@ -33,8 +33,8 @@ $(document).ready ->
|
||||
$("#contents a.active[href!='#{target.relatedTarget}']").removeClass 'show'
|
||||
$target = $("#contents a[href='#{target.relatedTarget}']")
|
||||
return if $target.prop('href') is "#{window.location.origin}/#try"
|
||||
# Update the browser address bar on scroll or navigation
|
||||
window.history.pushState {}, $target.text(), $target.prop('href')
|
||||
# Update the browser address bar on scroll, without adding to the history; clicking the sidebar links will automatically add to the history
|
||||
replaceState $target.prop('href')
|
||||
# Track this as a new pageview; we only want '/#hash', not 'http://coffeescript.org/#hash'
|
||||
gtag 'config', GA_TRACKING_ID,
|
||||
page_path: $target.prop('href').replace window.location.origin, ''
|
||||
@@ -74,9 +74,10 @@ $(document).ready ->
|
||||
try
|
||||
coffee = editor.getValue()
|
||||
if index is 0 and $('#try').hasClass('show') # If this is the editor in Try CoffeeScript and it’s still visible
|
||||
# Update the hash with the current code
|
||||
link = "try:#{encodeURIComponent coffee}"
|
||||
window.history.pushState {}, 'CoffeeScript', "#{location.href.split('#')[0]}##{link}"
|
||||
if $('#try').hasClass('show')
|
||||
# Update the hash with the current code
|
||||
link = "try:#{encodeURIComponent coffee}"
|
||||
replaceState "#{window.location.href.split('#')[0]}##{link}"
|
||||
# Save this to the user’s localStorage
|
||||
try
|
||||
if window.localStorage?
|
||||
@@ -135,32 +136,46 @@ $(document).ready ->
|
||||
event_category: 'engagement'
|
||||
event_label: $(@).closest('[data-example]').data('example')
|
||||
|
||||
# Try CoffeeScript
|
||||
previousHash = null
|
||||
toggleTry = (checkLocalStorage) ->
|
||||
$('#try, #try-link').toggleClass 'show'
|
||||
if $('#try').hasClass('show')
|
||||
previousHash = window.location.hash if window.location.hash
|
||||
initializeTryEditors() if $('#try .CodeMirror').length is 0
|
||||
if checkLocalStorage and window.localStorage?
|
||||
try
|
||||
coffee = window.localStorage.getItem 'tryCoffeeScriptCode'
|
||||
if coffee?
|
||||
editors[0].setValue coffee
|
||||
else
|
||||
replaceState '#try'
|
||||
catch exception
|
||||
replaceState '#try'
|
||||
else
|
||||
replaceState '#try'
|
||||
else
|
||||
if previousHash then replaceState(previousHash) else clearHash()
|
||||
closeTry = ->
|
||||
$('#try, #try-link').removeClass 'show'
|
||||
if previousHash then replaceState(previousHash) else clearHash()
|
||||
|
||||
$('[data-toggle="try"]').click (event) ->
|
||||
event.preventDefault()
|
||||
toggleTry yes
|
||||
$('[data-close="try"]').click closeTry
|
||||
|
||||
clearHash = ->
|
||||
window.history.pushState '', document.title, window.location.pathname
|
||||
window.history.replaceState {}, document.title, window.location.pathname
|
||||
|
||||
replaceState = (newURL) ->
|
||||
newURL = "#{window.location.pathname}#{newURL}" if newURL?.indexOf('#') is 0
|
||||
window.history.replaceState {}, document.title, (newURL or '')
|
||||
|
||||
$(window).on 'hashchange', ->
|
||||
# Get rid of dangling # in the address bar
|
||||
clearHash() if window.location.hash is ''
|
||||
|
||||
# Try CoffeeScript
|
||||
toggleTry = (checkLocalStorage = no) ->
|
||||
initializeTryEditors() if $('#try .CodeMirror').length is 0
|
||||
if checkLocalStorage and window.localStorage?
|
||||
try
|
||||
coffee = window.localStorage.getItem 'tryCoffeeScriptCode'
|
||||
if coffee?
|
||||
editors[0].setValue coffee
|
||||
catch exception
|
||||
$('#try, #try-link').toggleClass 'show'
|
||||
setTimeout clearHash, 200 unless $('#try').hasClass('show')
|
||||
closeTry = ->
|
||||
$('#try, #try-link').removeClass 'show'
|
||||
window.history.pushState '', document.title, window.location.pathname
|
||||
|
||||
$('[data-toggle="try"]').click toggleTry
|
||||
$('[data-close="try"]').click closeTry
|
||||
|
||||
|
||||
# Configure the initial state
|
||||
if window.location.hash?
|
||||
if window.location.hash is '#try'
|
||||
@@ -168,7 +183,7 @@ $(document).ready ->
|
||||
else if window.location.hash.indexOf('#try') is 0
|
||||
initializeTryEditors() if $('#try .CodeMirror').length is 0
|
||||
editors[0].setValue decodeURIComponent window.location.hash[5..]
|
||||
toggleTry()
|
||||
toggleTry no
|
||||
else if window.location.hash is ''
|
||||
clearHash()
|
||||
else
|
||||
|
||||
@@ -160,16 +160,17 @@ button:focus, .navbar-dark .navbar-toggler:focus {
|
||||
font-family: Lato;
|
||||
font-weight: 300;
|
||||
font-size: 1.1em;
|
||||
line-height: 1.7;
|
||||
}
|
||||
.main blockquote {
|
||||
font-size: 1.1em;
|
||||
}
|
||||
.main li p, .main li li, .main li blockquote {
|
||||
font-size: 1em;
|
||||
}
|
||||
@media (min-width: 768px) {
|
||||
.main p, .main li, .main td, .main th {
|
||||
font-size: 1.3em;
|
||||
}
|
||||
.main blockquote {
|
||||
font-size: 1.3em;
|
||||
.main p, .main li, .main td, .main th, .main blockquote {
|
||||
font-size: 1.2em;
|
||||
}
|
||||
}
|
||||
.main td {
|
||||
@@ -194,11 +195,18 @@ button:focus, .navbar-dark .navbar-toggler:focus {
|
||||
}
|
||||
|
||||
p, blockquote, table, .code-example {
|
||||
margin-bottom: 1.3rem;
|
||||
margin-bottom: 1.1em;
|
||||
}
|
||||
.main li {
|
||||
margin-bottom: 0.6em;
|
||||
}
|
||||
|
||||
td code {
|
||||
code, td code {
|
||||
white-space: nowrap;
|
||||
padding: 2px 8px;
|
||||
}
|
||||
pre code {
|
||||
white-space: pre; /* We want newlines to be newlines in code blocks */
|
||||
}
|
||||
|
||||
h2, h3, h4 {
|
||||
@@ -219,13 +227,18 @@ h3, h4, h2 time {
|
||||
margin-top: -2.3rem;
|
||||
}
|
||||
|
||||
@media (min-width: 1200px) {
|
||||
.main > header, .main section > h2, .main section > h3, .main section > h4, .main section > p, .main section > blockquote, .main section > ul, .main section > table {
|
||||
max-width: 80%;
|
||||
}
|
||||
}
|
||||
|
||||
code, button {
|
||||
font-family: 'Roboto Mono';
|
||||
font-weight: 400;
|
||||
}
|
||||
code, a > code {
|
||||
background-color: #f8f3f0;
|
||||
padding: 0.2rem 0.4rem;
|
||||
}
|
||||
code {
|
||||
color: #2f2625;
|
||||
@@ -270,6 +283,10 @@ textarea {
|
||||
height: 1em;
|
||||
}
|
||||
|
||||
.CodeMirror pre, pre.placeholder-code {
|
||||
line-height: 1.4em;
|
||||
}
|
||||
|
||||
.CodeMirror,
|
||||
.placeholder-code {
|
||||
/* https://codemirror.net/demo/resize.html */
|
||||
|
||||
@@ -5,7 +5,6 @@
|
||||
<a href="#coffeescript-2" class="nav-link" data-action="sidebar-nav">CoffeeScript 2</a>
|
||||
<nav class="nav flex-column">
|
||||
<a href="#whats-new-in-coffeescript-2" class="nav-link" data-action="sidebar-nav">What’s New in CoffeeScript 2</a>
|
||||
<a href="#why-coffeescript" class="nav-link" data-action="sidebar-nav">Why CoffeeScript When There’s ES6?</a>
|
||||
<a href="#compatibility" class="nav-link" data-action="sidebar-nav">Compatibility</a>
|
||||
</nav>
|
||||
<a href="#installation" class="nav-link" data-action="sidebar-nav">Installation</a>
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Generated by CoffeeScript 2.0.0
|
||||
// Generated by CoffeeScript 2.0.1
|
||||
(function() {
|
||||
// This **Browser** compatibility layer extends core CoffeeScript functions
|
||||
// to make things work smoothly when compiling code directly in the browser.
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Generated by CoffeeScript 2.0.0
|
||||
// Generated by CoffeeScript 2.0.1
|
||||
(function() {
|
||||
// `cake` is a simplified version of [Make](http://www.gnu.org/software/make/)
|
||||
// ([Rake](http://rake.rubyforge.org/), [Jake](https://github.com/280north/jake))
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Generated by CoffeeScript 2.0.0
|
||||
// Generated by CoffeeScript 2.0.1
|
||||
(function() {
|
||||
// CoffeeScript can be used both on the server, as a command-line compiler based
|
||||
// on Node.js/V8, or to run CoffeeScript directly in the browser. This module
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Generated by CoffeeScript 2.0.0
|
||||
// Generated by CoffeeScript 2.0.1
|
||||
(function() {
|
||||
// The `coffee` utility. Handles command-line compilation of CoffeeScript
|
||||
// into various forms: saved into `.js` files or printed to stdout
|
||||
@@ -605,54 +605,41 @@
|
||||
|
||||
// The compile-time options to pass to the CoffeeScript compiler.
|
||||
compileOptions = function(filename, base) {
|
||||
var answer, cantFindOptions, checkPath, cwd, jsDir, jsPath, packageJson;
|
||||
var answer, cwd, jsDir, jsPath;
|
||||
if (opts.transpile) {
|
||||
try {
|
||||
// The user has requested that the CoffeeScript compiler also transpile
|
||||
// via Babel. We use Babel as an `optionalDependency`; see
|
||||
// https://docs.npmjs.com/files/package.json#optionaldependencies.
|
||||
// via Babel. We don’t include Babel as a dependency because we want to
|
||||
// avoid dependencies in general, and most users probably won’t be relying
|
||||
// on us to transpile for them; we assume most users will probably either
|
||||
// run CoffeeScript’s output without transpilation (modern Node or evergreen
|
||||
// browsers) or use a proper build chain like Gulp or Webpack.
|
||||
require('babel-core');
|
||||
} catch (error) {
|
||||
console.error('To use --transpile, you must have Babel installed and configured.\nSee http://coffeescript.org/#transpilation');
|
||||
// Give appropriate instructions depending on whether `coffee` was run
|
||||
// locally or globally.
|
||||
if (require.resolve('.').indexOf(process.cwd()) === 0) {
|
||||
console.error('To use --transpile, you must have babel-core installed:\n npm install --save-dev babel-core\nAnd you must save options to configure Babel in one of the places it looks to find its options.\nSee http://coffeescript.org/#transpilation');
|
||||
} else {
|
||||
console.error('To use --transpile with globally-installed CoffeeScript, you must have babel-core installed globally:\n npm install --global babel-core\nAnd you must save options to configure Babel in one of the places it looks to find its options, relative to the file being compiled or to the current folder.\nSee http://coffeescript.org/#transpilation');
|
||||
}
|
||||
process.exit(1);
|
||||
}
|
||||
// We’re giving Babel only a string, not a filename or path to a file, so
|
||||
// it doesn’t know where to search to find a `.babelrc` file or a `babel`
|
||||
// key in a `package.json`. So if `opts.transpile` is an object, use that
|
||||
// as Babel’s options; otherwise figure out what the options should be.
|
||||
if (typeof opts.transpile !== 'object') {
|
||||
// Find the options based on the path to the file being compiled.
|
||||
cantFindOptions = function() {
|
||||
console.error('To use the transpile option, there must be a .babelrc file\n(or a package.json file with a "babel" key) in the path of the file\nto be compiled, or in the path of the current working directory.\nIf you are compiling a string via the Node API, the transpile option\nmust be an object with the options to pass to Babel.\nSee http://coffeescript.org/#transpilation');
|
||||
return process.exit(1);
|
||||
};
|
||||
checkPath = filename ? path.dirname(filename) : base ? base : typeof process !== "undefined" && process !== null ? process.cwd() : cantFindOptions();
|
||||
while (true) {
|
||||
try {
|
||||
opts.transpile = JSON.parse(fs.readFileSync(path.join(checkPath, '.babelrc'), 'utf-8'));
|
||||
break;
|
||||
} catch (error) {
|
||||
try {
|
||||
packageJson = JSON.parse(fs.readFileSync(path.join(checkPath, 'package.json'), 'utf-8'));
|
||||
if (packageJson.babel != null) {
|
||||
opts.transpile = packageJson.babel;
|
||||
break;
|
||||
}
|
||||
} catch (error) {}
|
||||
}
|
||||
if (checkPath === path.dirname(checkPath)) { // We’ve reached the root.
|
||||
cantFindOptions();
|
||||
break;
|
||||
} else {
|
||||
checkPath = path.dirname(checkPath);
|
||||
}
|
||||
}
|
||||
opts.transpile = {};
|
||||
}
|
||||
// Pass a reference to Babel into the compiler, so that the transpile option
|
||||
// is available for the CLI. We need to do this so that tools like Webpack
|
||||
// can `require('coffeescript')` and build correctly, without trying to
|
||||
// require Babel.
|
||||
opts.transpile.transpile = CoffeeScript.transpile;
|
||||
// Babel searches for its options (a `.babelrc` file, a `.babelrc.js` file,
|
||||
// a `package.json` file with a `babel` key, etc.) relative to the path
|
||||
// given to it in its `filename` option. Make sure we have a path to pass
|
||||
// along.
|
||||
if (!opts.transpile.filename) {
|
||||
opts.transpile.filename = filename || path.resolve(base || process.cwd(), '<anonymous>');
|
||||
}
|
||||
} else {
|
||||
opts.transpile = false;
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Generated by CoffeeScript 2.0.0
|
||||
// Generated by CoffeeScript 2.0.1
|
||||
(function() {
|
||||
// The CoffeeScript parser is generated by [Jison](https://github.com/zaach/jison)
|
||||
// from this grammar file. Jison is a bottom-up parser generator, similar in
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Generated by CoffeeScript 2.0.0
|
||||
// Generated by CoffeeScript 2.0.1
|
||||
(function() {
|
||||
// This file contains the common helper functions that we'd like to share among
|
||||
// the **Lexer**, **Rewriter**, and the **Nodes**. Merge objects, flatten
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Generated by CoffeeScript 2.0.0
|
||||
// Generated by CoffeeScript 2.0.1
|
||||
(function() {
|
||||
// Node.js Implementation
|
||||
var CoffeeScript, ext, fn, fs, helpers, i, len, path, ref, universalCompile, vm,
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Generated by CoffeeScript 2.0.0
|
||||
// Generated by CoffeeScript 2.0.1
|
||||
(function() {
|
||||
// The CoffeeScript Lexer. Uses a series of token-matching regexes to attempt
|
||||
// matches against the beginning of the source code. When a match is found,
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Generated by CoffeeScript 2.0.0
|
||||
// Generated by CoffeeScript 2.0.1
|
||||
(function() {
|
||||
// `nodes.coffee` contains all of the node classes for the syntax tree. Most
|
||||
// nodes are created as the result of actions in the [grammar](grammar.html),
|
||||
@@ -2630,10 +2630,23 @@
|
||||
|
||||
// Add an expression to the class initializer
|
||||
|
||||
// NOTE Currently, only methods and static methods are valid in ES class initializers.
|
||||
// When additional expressions become valid, this method should be updated to handle them.
|
||||
// This is the key method for determining whether an expression in a class
|
||||
// body should appear in the initializer or the executable body. If the given
|
||||
// `node` is valid in a class body the method will return a (new, modified,
|
||||
// or identical) node for inclusion in the class initializer, otherwise
|
||||
// nothing will be returned and the node will appear in the executable body.
|
||||
|
||||
// At time of writing, only methods (instance and static) are valid in ES
|
||||
// class initializers. As new ES class features (such as class fields) reach
|
||||
// Stage 4, this method will need to be updated to support them. We
|
||||
// additionally allow `PassthroughLiteral`s (backticked expressions) in the
|
||||
// initializer as an escape hatch for ES features that are not implemented
|
||||
// (e.g. getters and setters defined via the `get` and `set` keywords as
|
||||
// opposed to the `Object.defineProperty` method).
|
||||
addInitializerExpression(node) {
|
||||
if (this.validInitializerMethod(node)) {
|
||||
if (node.unwrapAll() instanceof PassthroughLiteral) {
|
||||
return node;
|
||||
} else if (this.validInitializerMethod(node)) {
|
||||
return this.addInitializerMethod(node);
|
||||
} else {
|
||||
return null;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Generated by CoffeeScript 2.0.0
|
||||
// Generated by CoffeeScript 2.0.1
|
||||
(function() {
|
||||
var LONG_FLAG, MULTI_FLAG, OPTIONAL, OptionParser, SHORT_FLAG, buildRule, buildRules, normalizeArguments, repeat,
|
||||
slice = [].slice;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Generated by CoffeeScript 2.0.0
|
||||
// Generated by CoffeeScript 2.0.1
|
||||
(function() {
|
||||
var CoffeeScript, Module, binary, child_process, ext, findExtension, fork, helpers, i, len, loadFile, path, ref;
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Generated by CoffeeScript 2.0.0
|
||||
// Generated by CoffeeScript 2.0.1
|
||||
(function() {
|
||||
var CoffeeScript, addHistory, addMultilineHandler, fs, getCommandId, merge, nodeREPL, path, replDefaults, runInContext, sawSIGINT, updateSyntaxError, vm;
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Generated by CoffeeScript 2.0.0
|
||||
// Generated by CoffeeScript 2.0.1
|
||||
(function() {
|
||||
// The CoffeeScript language has a good deal of optional syntax, implicit syntax,
|
||||
// and shorthand syntax. This can greatly complicate a grammar and bloat
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Generated by CoffeeScript 2.0.0
|
||||
// Generated by CoffeeScript 2.0.1
|
||||
(function() {
|
||||
// The **Scope** class regulates lexical scoping within CoffeeScript. As you
|
||||
// generate code, you create a tree of scopes in the same shape as the nested
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Generated by CoffeeScript 2.0.0
|
||||
// Generated by CoffeeScript 2.0.1
|
||||
(function() {
|
||||
// Source maps allow JavaScript runtimes to match running JavaScript back to
|
||||
// the original source code that corresponds to it. This can be minified
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
"compiler"
|
||||
],
|
||||
"author": "Jeremy Ashkenas",
|
||||
"version": "2.0.0",
|
||||
"version": "2.0.1",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">=6"
|
||||
@@ -51,8 +51,5 @@
|
||||
"underscore": "~1.8.3",
|
||||
"webpack": "~3.6.0"
|
||||
},
|
||||
"optionalDependencies": {
|
||||
"babel-core": "^6"
|
||||
},
|
||||
"dependencies": {}
|
||||
}
|
||||
|
||||
@@ -444,65 +444,46 @@ parseOptions = ->
|
||||
compileOptions = (filename, base) ->
|
||||
if opts.transpile
|
||||
# The user has requested that the CoffeeScript compiler also transpile
|
||||
# via Babel. We use Babel as an `optionalDependency`; see
|
||||
# https://docs.npmjs.com/files/package.json#optionaldependencies.
|
||||
# via Babel. We don’t include Babel as a dependency because we want to
|
||||
# avoid dependencies in general, and most users probably won’t be relying
|
||||
# on us to transpile for them; we assume most users will probably either
|
||||
# run CoffeeScript’s output without transpilation (modern Node or evergreen
|
||||
# browsers) or use a proper build chain like Gulp or Webpack.
|
||||
try
|
||||
require 'babel-core'
|
||||
catch
|
||||
console.error '''
|
||||
To use --transpile, you must have Babel installed and configured.
|
||||
See http://coffeescript.org/#transpilation
|
||||
'''
|
||||
process.exit 1
|
||||
|
||||
# We’re giving Babel only a string, not a filename or path to a file, so
|
||||
# it doesn’t know where to search to find a `.babelrc` file or a `babel`
|
||||
# key in a `package.json`. So if `opts.transpile` is an object, use that
|
||||
# as Babel’s options; otherwise figure out what the options should be.
|
||||
unless typeof opts.transpile is 'object'
|
||||
# Find the options based on the path to the file being compiled.
|
||||
cantFindOptions = ->
|
||||
# Give appropriate instructions depending on whether `coffee` was run
|
||||
# locally or globally.
|
||||
if require.resolve('.').indexOf(process.cwd()) is 0
|
||||
console.error '''
|
||||
To use the transpile option, there must be a .babelrc file
|
||||
(or a package.json file with a "babel" key) in the path of the file
|
||||
to be compiled, or in the path of the current working directory.
|
||||
If you are compiling a string via the Node API, the transpile option
|
||||
must be an object with the options to pass to Babel.
|
||||
To use --transpile, you must have babel-core installed:
|
||||
npm install --save-dev babel-core
|
||||
And you must save options to configure Babel in one of the places it looks to find its options.
|
||||
See http://coffeescript.org/#transpilation
|
||||
'''
|
||||
process.exit 1
|
||||
|
||||
checkPath = if filename
|
||||
path.dirname filename
|
||||
else if base
|
||||
base
|
||||
else if process?
|
||||
process.cwd()
|
||||
else
|
||||
cantFindOptions()
|
||||
console.error '''
|
||||
To use --transpile with globally-installed CoffeeScript, you must have babel-core installed globally:
|
||||
npm install --global babel-core
|
||||
And you must save options to configure Babel in one of the places it looks to find its options, relative to the file being compiled or to the current folder.
|
||||
See http://coffeescript.org/#transpilation
|
||||
'''
|
||||
process.exit 1
|
||||
|
||||
loop
|
||||
try
|
||||
opts.transpile = JSON.parse fs.readFileSync path.join(checkPath, '.babelrc'), 'utf-8'
|
||||
break
|
||||
catch
|
||||
try
|
||||
packageJson = JSON.parse fs.readFileSync(path.join(checkPath, 'package.json'), 'utf-8')
|
||||
if packageJson.babel?
|
||||
opts.transpile = packageJson.babel
|
||||
break
|
||||
|
||||
if checkPath is path.dirname checkPath # We’ve reached the root.
|
||||
cantFindOptions()
|
||||
break
|
||||
else
|
||||
checkPath = path.dirname checkPath
|
||||
opts.transpile = {} unless typeof opts.transpile is 'object'
|
||||
|
||||
# Pass a reference to Babel into the compiler, so that the transpile option
|
||||
# is available for the CLI. We need to do this so that tools like Webpack
|
||||
# can `require('coffeescript')` and build correctly, without trying to
|
||||
# require Babel.
|
||||
opts.transpile.transpile = CoffeeScript.transpile
|
||||
|
||||
# Babel searches for its options (a `.babelrc` file, a `.babelrc.js` file,
|
||||
# a `package.json` file with a `babel` key, etc.) relative to the path
|
||||
# given to it in its `filename` option. Make sure we have a path to pass
|
||||
# along.
|
||||
unless opts.transpile.filename
|
||||
opts.transpile.filename = filename or path.resolve(base or process.cwd(), '<anonymous>')
|
||||
else
|
||||
opts.transpile = no
|
||||
|
||||
|
||||
@@ -1752,10 +1752,23 @@ exports.Class = class Class extends Base
|
||||
|
||||
# Add an expression to the class initializer
|
||||
#
|
||||
# NOTE Currently, only methods and static methods are valid in ES class initializers.
|
||||
# When additional expressions become valid, this method should be updated to handle them.
|
||||
# This is the key method for determining whether an expression in a class
|
||||
# body should appear in the initializer or the executable body. If the given
|
||||
# `node` is valid in a class body the method will return a (new, modified,
|
||||
# or identical) node for inclusion in the class initializer, otherwise
|
||||
# nothing will be returned and the node will appear in the executable body.
|
||||
#
|
||||
# At time of writing, only methods (instance and static) are valid in ES
|
||||
# class initializers. As new ES class features (such as class fields) reach
|
||||
# Stage 4, this method will need to be updated to support them. We
|
||||
# additionally allow `PassthroughLiteral`s (backticked expressions) in the
|
||||
# initializer as an escape hatch for ES features that are not implemented
|
||||
# (e.g. getters and setters defined via the `get` and `set` keywords as
|
||||
# opposed to the `Object.defineProperty` method).
|
||||
addInitializerExpression: (node) ->
|
||||
if @validInitializerMethod node
|
||||
if node.unwrapAll() instanceof PassthroughLiteral
|
||||
node
|
||||
else if @validInitializerMethod node
|
||||
@addInitializerMethod node
|
||||
else
|
||||
null
|
||||
|
||||
@@ -1833,3 +1833,18 @@ test "#4591: super.x.y, super['x'].y", ->
|
||||
eq 2, b.t
|
||||
eq 2, b.s
|
||||
eq 2, b.r
|
||||
|
||||
test "#4464: backticked expressions in class body", ->
|
||||
class A
|
||||
`get x() { return 42; }`
|
||||
|
||||
class B
|
||||
`get x() { return 42; }`
|
||||
constructor: ->
|
||||
@y = 84
|
||||
|
||||
a = new A
|
||||
eq 42, a.x
|
||||
b = new B
|
||||
eq 42, b.x
|
||||
eq 84, b.y
|
||||
|
||||
Reference in New Issue
Block a user