Skip to content
Merged

2.0.1 #4719

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
91 changes: 36 additions & 55 deletions docs/v2/annotated-source/command.html
Original file line number Diff line number Diff line change
Expand Up @@ -862,19 +862,17 @@ <h1>command.coffee</h1>
<a class="pilcrow" href="#section-26">&#182;</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>

Expand All @@ -885,14 +883,28 @@ <h1>command.coffee</h1>
<div class="pilwrap ">
<a class="pilcrow" href="#section-27">&#182;</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>

Expand All @@ -903,46 +915,14 @@ <h1>command.coffee</h1>
<div class="pilwrap ">
<a class="pilcrow" href="#section-28">&#182;</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(&#39;coffeescript&#39;)</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> = -&gt;</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>

Expand All @@ -953,14 +933,15 @@ <h1>command.coffee</h1>
<div class="pilwrap ">
<a class="pilcrow" href="#section-29">&#182;</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(&#39;coffeescript&#39;)</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">'&lt;anonymous&gt;'</span>)
<span class="hljs-keyword">else</span>
opts.transpile = <span class="hljs-literal">no</span>

Expand Down
18 changes: 15 additions & 3 deletions docs/v2/annotated-source/nodes.html
Original file line number Diff line number Diff line change
Expand Up @@ -3641,13 +3641,25 @@ <h3 id="class">Class</h3>
<a class="pilcrow" href="#section-148">&#182;</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> -&gt;</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>
Expand Down
Empty file modified docs/v2/annotated-source/public/fonts/roboto-black.eot
100755 → 100644
Empty file.
Empty file modified docs/v2/annotated-source/public/fonts/roboto-black.ttf
100755 → 100644
Empty file.
Empty file modified docs/v2/annotated-source/public/fonts/roboto-black.woff
100755 → 100644
Empty file.
4 changes: 2 additions & 2 deletions docs/v2/browser-compiler/coffeescript.js

Large diffs are not rendered by default.

15 changes: 12 additions & 3 deletions docs/v2/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -645,7 +645,7 @@
<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>
<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

Expand Down Expand Up @@ -4820,7 +4820,7 @@ <h2>Web Chat (IRC)</h2>
</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>
Expand Down Expand Up @@ -5448,10 +5448,19 @@ <h3>Argument parsing and shebang (<code>#!</code>) lines</h3>
</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"> &mdash; <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"> &mdash; <time datetime="2017-09-17">September 17, 2017</time></span>
<span class="timestamp"> &mdash; <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>
Expand Down
15 changes: 15 additions & 0 deletions docs/v2/test.html
Original file line number Diff line number Diff line change
Expand Up @@ -3529,6 +3529,21 @@ <h1>CoffeeScript Test Suite</h1>
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
Expand Down
10 changes: 9 additions & 1 deletion documentation/sections/changelog.md
Original file line number Diff line number Diff line change
@@ -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`.
Expand Down
2 changes: 1 addition & 1 deletion lib/coffeescript/browser.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/coffeescript/cake.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/coffeescript/coffeescript.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/coffeescript/command.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/coffeescript/grammar.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/coffeescript/helpers.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/coffeescript/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/coffeescript/lexer.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/coffeescript/nodes.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/coffeescript/optparse.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/coffeescript/register.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/coffeescript/repl.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/coffeescript/rewriter.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/coffeescript/scope.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/coffeescript/sourcemap.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"compiler"
],
"author": "Jeremy Ashkenas",
"version": "2.0.0",
"version": "2.0.1",
"license": "MIT",
"engines": {
"node": ">=6"
Expand Down