Skip to content

[CS2] Add #! support for executable scripts on Linux. #3946

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 51 commits into from
Jul 19, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
6c48af3
Add #! support for executable scripts on Linux.
Apr 16, 2015
221dfc4
refactor option parsing
Apr 20, 2017
988f2af
address comments
Apr 20, 2017
fa3fe8b
intermediate save
May 24, 2017
aee066f
add note saying where OptionParser is used in coffee command
Apr 28, 2017
3c1fb7f
add some more work
May 24, 2017
a10c653
fix flatten functions
May 24, 2017
d5e8d74
Merge branch '2' of github.com:jashkenas/coffeescript
May 24, 2017
062fe62
Merge branch 'feature/uniform-hashbang-parsing'
May 24, 2017
c929ed9
refactor tests
May 31, 2017
b1acc4b
make argument processing less confusing
May 31, 2017
f3ea781
add basic test
May 31, 2017
200126f
Merge branch '2' into test/current-cli-optparse
May 31, 2017
7970e44
remove unused file
May 31, 2017
bc92ff3
compilation now hangs
May 31, 2017
7e0d9e0
remove unnecessary changes
Jun 2, 2017
0a05e0c
add tests!!!
Jun 2, 2017
3c49c8e
Merge branch '2' into feature/uniform-hashbang-parsing
Jun 2, 2017
0e1f27e
Merge branch 'test/current-cli-optparse' into feature/uniform-hashban…
Jun 2, 2017
42434b4
add/fix some tests
Jun 2, 2017
15eb624
clarify a test
Jun 2, 2017
bb9366c
Merge branch 'test/current-cli-optparse' into feature/uniform-hashban…
Jun 2, 2017
e1bcf84
fix helpers
Jun 9, 2017
7bc6591
fix opt parsing
Jun 9, 2017
7c4723d
fix infinite loop
Jun 9, 2017
768ada6
Merge remote-tracking branch 'upstream/2' into feature/uniform-hashba…
Jun 9, 2017
79c0e56
Merge remote-tracking branch 'upstream/2' into test/current-cli-optparse
Jun 9, 2017
ca7ad49
Merge branch 'test/current-cli-optparse' into feature/uniform-hashban…
Jun 9, 2017
daa5f4d
Merge remote-tracking branch 'upstream/2'
Jun 9, 2017
c75e2b1
Merge branch 'feature/uniform-hashbang-parsing'
Jun 9, 2017
23f31c6
Merge branch '2' of github.com:jashkenas/coffeescript
Jun 19, 2017
d495841
make rule building easier to read
Jun 19, 2017
bafa82f
add tests for flag overlap
Jun 19, 2017
9247444
revamp argument parsing again and add more thorough testing
Jun 19, 2017
b509b46
add tests, comment, clean unused method
Jun 19, 2017
31bbeb2
address review comments
Jun 20, 2017
7abe19c
Merge remote-tracking branch 'upstream/2'
Jun 21, 2017
3944d94
add test for direct invocation of shebang scripts
Jun 21, 2017
f41463d
move shebang parsing test to separate file and check for browser
Jun 21, 2017
356f3ad
remove TODO
Jun 21, 2017
7c17e23
example backwards compatible warnings
Jun 21, 2017
179687d
Merge remote-tracking branch 'upstream/2'
Jun 29, 2017
5b9b786
add correct tests for warning 1
Jun 29, 2017
8448a77
add tests for warnings
Jun 29, 2017
14df734
commit output js libs and update docs
Jun 29, 2017
b9291ae
respond to review comments
Jun 30, 2017
f306859
respond to review comments
Jul 7, 2017
4093574
Merge branch '2' of github.com:jashkenas/coffeescript
Jul 7, 2017
4856fd6
fix example output
Jul 7, 2017
f7e8c2b
Rewrite argument parsing documentation to be more concise; add it to …
GeoffreyBooth Jul 9, 2017
6fb80c1
Don’t mention deprecated syntax; clean up variable names
GeoffreyBooth Jul 9, 2017
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
38 changes: 32 additions & 6 deletions docs/v2/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -306,15 +306,15 @@
white-space: nowrap;
}

h2, h3 {
h2, h3, h4 {
margin-top: 1.3em;
margin-bottom: 0.6em;
font-family: 'Alegreya Sans';
}
h2 {
font-weight: 800;
}
h3, h2 time {
h3, h4, h2 time {
font-weight: 400;
}

Expand Down Expand Up @@ -734,6 +734,9 @@
<li class="nav-item">
<a href="#breaking-changes-literate-coffeescript" class="nav-link" data-action="sidebar-nav">Literate CoffeeScript Parsing</a>
</li>
<li class="nav-item">
<a href="#breaking-changes-argument-parsing-and-shebang-lines" class="nav-link" data-action="sidebar-nav">Argument Parsing and <code>#!</code> Lines</a>
</li>
</ul>
</li>
<li class="nav-item">
Expand Down Expand Up @@ -858,7 +861,7 @@ <h2>Overview</h2>
<section id="coffeescript-2">
<h2>CoffeeScript 2</h2>
<h3>What’s New In CoffeeScript 2?</h3>
<p>The biggest change in CoffeeScript 2 is that now the CoffeeScript compiler produces modern, ES2015+ JavaScript. A CoffeeScript <code>=&gt;</code> becomes an ES <code>=&gt;</code>, a CoffeeScript <code>class</code> becomes an ES <code>class</code> and so on. With the exception of modules (<code>import</code> and <code>export</code> statements), all the ES2015+ features that CoffeeScript supports can run natively in Node 7.6+, meaning that Node can run CoffeeScript’s output without any further processing required. You can <a href="http://coffeescript.org/v2/test.html">run the tests in your browser</a> to see if your browser can do the same; Chrome has supported all features since version 55.</p>
<p>The biggest change in CoffeeScript 2 is that now the CoffeeScript compiler produces modern, ES2015+ JavaScript. A CoffeeScript <code>=&gt;</code> becomes an ES <code>=&gt;</code>, a CoffeeScript <code>class</code> becomes an ES <code>class</code> and so on. With the exception of <a href="#modules">modules</a> (<code>import</code> and <code>export</code> statements) and <a href="#jsx">JSX</a>, all the ES2015+ features that CoffeeScript supports can run natively in Node 7.6+, meaning that Node can run CoffeeScript’s output without any further processing required. You can <a href="http://coffeescript.org/v2/test.html">run the tests in your browser</a> to see if your browser can do the same; Chrome has supported all features since version 55.</p>
<p>Support for ES2015+ syntax is important to ensure compatibility with frameworks that assume ES2015. Now that CoffeeScript compiles classes to the ES <code>class</code> keyword, it’s possible to <code>extend</code> an ES class; that wasn’t possible in CoffeeScript 1. Parity in how language features work is also important on its own; CoffeeScript “is just JavaScript,” and so things like <a href="#breaking-changes-default-values">function parameter default values</a> should behave the same in CoffeeScript as in JavaScript.</p>
<p>Many ES2015+ features have been backported to CoffeeScript 1.11 and 1.12, including <a href="#modules">modules</a>, <a href="#generator-iteration"><code>for…of</code></a>, and <a href="#tagged-template-literals">tagged template literals</a>. Major new features unique to CoffeeScript 2 are support for ES2017’s <a href="#async-functions">async functions</a> and for <a href="#jsx">JSX</a>. More details are in the <a href="#changelog">changelog</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>
Expand Down Expand Up @@ -3244,7 +3247,7 @@ <h2>JSX</h2>
</div>

</aside>
<p>Older plugins or forks of CoffeeScript supported JSX syntax and referred to it as CSX or CJSX. They also often used a <code>.cjsx</code> file extension, but this is no longer necessary; regalar <code>.coffee</code> will do.</p>
<p>Older plugins or forks of CoffeeScript supported JSX syntax and referred to it as CSX or CJSX. They also often used a <code>.cjsx</code> file extension, but this is no longer necessary; regular <code>.coffee</code> will do.</p>

</section>
</section>
Expand Down Expand Up @@ -3619,7 +3622,7 @@ <h3>Classes are compiled to ES2015 classes</h3>
<blockquote class="uneditable-code-block"><pre><code class="language-coffee"><span class="class"><span class="keyword">class</span> <span class="title">B</span> <span class="keyword">extends</span> <span class="title">A</span></span>
constructor: <span class="function">-&gt;</span> <span class="keyword">this</span> <span class="comment"># Throws a compiler error</span>
</code></pre>
</blockquote><p>ES2015 classes don’t allow bound (fat arrow) methods. The CoffeeScript compiler goes through some contortions to preserve support for them, but one thing that can’t be accomodated is calling a bound method before it is bound:</p>
</blockquote><p>ES2015 classes don’t allow bound (fat arrow) methods. The CoffeeScript compiler goes through some contortions to preserve support for them, but one thing that can’t be accommodated is calling a bound method before it is bound:</p>
<blockquote class="uneditable-code-block"><pre><code class="language-coffee"><span class="class"><span class="keyword">class</span> <span class="title">Base</span></span>
constructor: <span class="function">-&gt;</span>
@onClick() <span class="comment"># This works</span>
Expand Down Expand Up @@ -3787,7 +3790,7 @@ <h3><code>super</code> and <code>extends</code></h3>

</section>
<section id="breaking-changes-jsx-and-the-less-than-and-greater-than-operators">
<h3>JSX and the <code>&lt;</code> and <code>&gt;</code> Operators</h3>
<h3>JSX and the <code>&lt;</code> and <code>&gt;</code> operators</h3>
<p>With the addition of <a href="#jsx">JSX</a>, the <code>&lt;</code> and <code>&gt;</code> characters serve as both the “less than” and “greater than” operators and as the delimiters for XML tags, like <code>&lt;div&gt;</code>. For best results, in general you should always wrap the operators in spaces to distinguish them from XML tags: <code>i &lt; len</code>, not <code>i&lt;len</code>. The compiler tries to be forgiving when it can be sure what you intend, but always putting spaces around the “less than” and “greater than” operators will remove ambiguity.</p>

</section>
Expand All @@ -3797,6 +3800,29 @@ <h3>Literate CoffeeScript parsing</h3>
<p>Code blocks should also now maintain a consistent indentation level—so an indentation of one tab (or whatever you consider to be a tab stop, like 2 spaces or 4 spaces) should be treated as your code’s “left margin,” with all code in the file relative to that column.</p>
<p>Code blocks that you want to be part of the commentary, and not executed, must have at least one line (ideally the first line of the block) completely unindented.</p>

</section>
<section id="breaking-changes-argument-parsing-and-shebang-lines">
<h3>Argument parsing and shebang (<code>#!</code>) lines</h3>
<p>In CoffeeScript 1.x, <code>--</code> was required after the path and filename of the script to be run, but before any arguments passed to that script. This convention is now deprecated. So instead of:</p>
<blockquote class="uneditable-code-block"><pre><code class="language-bash">coffee [options] path/to/script.coffee -- [args]
</code></pre>
</blockquote><p>Now you would just type:</p>
<blockquote class="uneditable-code-block"><pre><code class="language-bash">coffee [options] path/to/script.coffee [args]
</code></pre>
</blockquote><p>The deprecated version will still work, but it will print a warning before running the script.</p>
<p>On non-Windows platforms, a <code>.coffee</code> file can be made executable by adding a shebang (<code>#!</code>) line at the top of the file and marking the file as executable. For example:</p>
<blockquote class="uneditable-code-block"><pre><code class="language-coffee"><span class="comment">#!/usr/bin/env coffee</span>

x = <span class="number">2</span> + <span class="number">2</span>
<span class="built_in">console</span>.log x
</code></pre>
</blockquote><p>If this were saved as <code>executable.coffee</code>, it could be made executable and run:</p>
<blockquote class="uneditable-code-block"><pre><code class="language-bash">▶ chmod +x ./executable.coffee
▶ ./executable.coffee
4
</code></pre>
</blockquote><p>In CoffeeScript 1.x, this used to fail when trying to pass arguments to the script. Some users on OS X worked around the problem by using <code>#!/usr/bin/env coffee --</code> as the first line of the file. That didn’t work on Linux, however, which cannot parse shebang lines with more than a single argument. While such scripts will still run on OS X, CoffeeScript will now display a warning before compiling or evaluating files that begin with a too-long shebang line. Now that CoffeeScript 2 supports passing arguments without needing <code>--</code>, we recommend simply changing the shebang lines in such scripts to just <code>#!/usr/bin/env coffee</code>.</p>

</section>
</section>
<section id="changelog">
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
### Argument parsing and shebang (`#!`) lines

In CoffeeScript 1.x, `--` was required after the path and filename of the script to be run, but before any arguments passed to that script. This convention is now deprecated. So instead of:

```bash
coffee [options] path/to/script.coffee -- [args]
```

Now you would just type:

```bash
coffee [options] path/to/script.coffee [args]
```

The deprecated version will still work, but it will print a warning before running the script.

On non-Windows platforms, a `.coffee` file can be made executable by adding a shebang (`#!`) line at the top of the file and marking the file as executable. For example:

```coffee
#!/usr/bin/env coffee

x = 2 + 2
console.log x
```

If this were saved as `executable.coffee`, it could be made executable and run:

```bash
▶ chmod +x ./executable.coffee
▶ ./executable.coffee
4
```

In CoffeeScript 1.x, this used to fail when trying to pass arguments to the script. Some users on OS X worked around the problem by using `#!/usr/bin/env coffee --` as the first line of the file. That didn’t work on Linux, however, which cannot parse shebang lines with more than a single argument. While such scripts will still run on OS X, CoffeeScript will now display a warning before compiling or evaluating files that begin with a too-long shebang line. Now that CoffeeScript 2 supports passing arguments without needing `--`, we recommend simply changing the shebang lines in such scripts to just `#!/usr/bin/env coffee`.
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
### JSX and the `<` and `>` Operators
### JSX and the `<` and `>` operators

With the addition of [JSX](#jsx), the `<` and `>` characters serve as both the “less than” and “greater than” operators and as the delimiters for XML tags, like `<div>`. For best results, in general you should always wrap the operators in spaces to distinguish them from XML tags: `i < len`, not `i<len`. The compiler tries to be forgiving when it can be sure what you intend, but always putting spaces around the “less than” and “greater than” operators will remove ambiguity.
2 changes: 1 addition & 1 deletion documentation/sections/coffeescript_2.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

### What’s New In CoffeeScript 2?

The biggest change in CoffeeScript 2 is that now the CoffeeScript compiler produces modern, ES2015+ JavaScript. A CoffeeScript `=>` becomes an ES `=>`, a CoffeeScript `class` becomes an ES `class` and so on. With the exception of modules (`import` and `export` statements), all the ES2015+ features that CoffeeScript supports can run natively in Node 7.6+, meaning that Node can run CoffeeScript’s output without any further processing required. You can [run the tests in your browser](http://coffeescript.org/v<%= majorVersion %>/test.html) to see if your browser can do the same; Chrome has supported all features since version 55.
The biggest change in CoffeeScript 2 is that now the CoffeeScript compiler produces modern, ES2015+ JavaScript. A CoffeeScript `=>` becomes an ES `=>`, a CoffeeScript `class` becomes an ES `class` and so on. With the exception of [modules](#modules) (`import` and `export` statements) and [JSX](#jsx), all the ES2015+ features that CoffeeScript supports can run natively in Node 7.6+, meaning that Node can run CoffeeScript’s output without any further processing required. You can [run the tests in your browser](http://coffeescript.org/v<%= majorVersion %>/test.html) to see if your browser can do the same; Chrome has supported all features since version 55.

Support for ES2015+ syntax is important to ensure compatibility with frameworks that assume ES2015. Now that CoffeeScript compiles classes to the ES `class` keyword, it’s possible to `extend` an ES class; that wasn’t possible in CoffeeScript 1. Parity in how language features work is also important on its own; CoffeeScript “is just JavaScript,” and so things like [function parameter default values](#breaking-changes-default-values) should behave the same in CoffeeScript as in JavaScript.

Expand Down
3 changes: 3 additions & 0 deletions documentation/v2/body.html
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,9 @@
<section id="breaking-changes-literate-coffeescript">
<%= htmlFor('breaking_changes_literate_coffeescript') %>
</section>
<section id="breaking-changes-argument-parsing-and-shebang-lines">
<%= htmlFor('breaking_changes_argument_parsing_and_shebang_lines') %>
</section>
</section>
<section id="changelog">
<%= htmlFor('changelog') %>
Expand Down
4 changes: 2 additions & 2 deletions documentation/v2/docs.css
Original file line number Diff line number Diff line change
Expand Up @@ -286,15 +286,15 @@ td code {
white-space: nowrap;
}

h2, h3 {
h2, h3, h4 {
margin-top: 1.3em;
margin-bottom: 0.6em;
font-family: 'Alegreya Sans';
}
h2 {
font-weight: 800;
}
h3, h2 time {
h3, h4, h2 time {
font-weight: 400;
}

Expand Down
3 changes: 3 additions & 0 deletions documentation/v2/sidebar.html
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,9 @@
<li class="nav-item">
<a href="#breaking-changes-literate-coffeescript" class="nav-link" data-action="sidebar-nav">Literate CoffeeScript Parsing</a>
</li>
<li class="nav-item">
<a href="#breaking-changes-argument-parsing-and-shebang-lines" class="nav-link" data-action="sidebar-nav">Argument Parsing and <code>#!</code> Lines</a>
</li>
</ul>
</li>
<li class="nav-item">
Expand Down
17 changes: 16 additions & 1 deletion lib/coffeescript/coffeescript.js

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

17 changes: 14 additions & 3 deletions lib/coffeescript/command.js

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

Loading