You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[CS2] Add #! support for executable scripts on Linux. (#3946)
* Add #! support for executable scripts on Linux.
Pass arguments to executable script unchanged if using "#!/usr/bin/env
coffee". (Previously, "./test.coffee -abck" would be turned into "-a -b -c -k",
for example.)
Fixes#1752.
* refactor option parsing
clean up parsing code and in the process fix oustanding bug where coffeescript
modified arguments meant for an executable script
* address comments
* intermediate save
* add note saying where OptionParser is used in coffee command
* add some more work
* fix flatten functions
* refactor tests
* make argument processing less confusing
* add basic test
* remove unused file
* compilation now hangs
* remove unnecessary changes
* add tests!!!
* add/fix some tests
* clarify a test
* fix helpers
* fix opt parsing
* fix infinite loop
* make rule building easier to read
* add tests for flag overlap
* revamp argument parsing again and add more thorough testing
* add tests, comment, clean unused method
* address review comments
* add test for direct invocation of shebang scripts
* move shebang parsing test to separate file and check for browser
* remove TODO
* example backwards compatible warnings
* add correct tests for warning 1
* add tests for warnings
* commit output js libs and update docs
* respond to review comments
also add tests for help text
* respond to review comments
* fix example output
* Rewrite argument parsing documentation to be more concise; add it to sidebar and body; add new output
* Don’t mention deprecated syntax; clean up variable names
<ahref="#breaking-changes-argument-parsing-and-shebang-lines" class="nav-link" data-action="sidebar-nav">Argument Parsing and <code>#!</code> Lines</a>
739
+
</li>
737
740
</ul>
738
741
</li>
739
742
<liclass="nav-item">
@@ -858,7 +861,7 @@ <h2>Overview</h2>
858
861
<sectionid="coffeescript-2">
859
862
<h2>CoffeeScript 2</h2>
860
863
<h3>What’s New In CoffeeScript 2?</h3>
861
-
<p>The biggest change in CoffeeScript 2 is that now the CoffeeScript compiler produces modern, ES2015+ JavaScript. A CoffeeScript <code>=></code> becomes an ES <code>=></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 <ahref="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>
864
+
<p>The biggest change in CoffeeScript 2 is that now the CoffeeScript compiler produces modern, ES2015+ JavaScript. A CoffeeScript <code>=></code> becomes an ES <code>=></code>, a CoffeeScript <code>class</code> becomes an ES <code>class</code> and so on. With the exception of <ahref="#modules">modules</a> (<code>import</code> and <code>export</code> statements) and <ahref="#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 <ahref="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>
862
865
<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 <ahref="#breaking-changes-default-values">function parameter default values</a> should behave the same in CoffeeScript as in JavaScript.</p>
863
866
<p>Many ES2015+ features have been backported to CoffeeScript 1.11 and 1.12, including <ahref="#modules">modules</a>, <ahref="#generator-iteration"><code>for…of</code></a>, and <ahref="#tagged-template-literals">tagged template literals</a>. Major new features unique to CoffeeScript 2 are support for ES2017’s <ahref="#async-functions">async functions</a> and for <ahref="#jsx">JSX</a>. More details are in the <ahref="#changelog">changelog</a>.</p>
864
867
<p>There are very few <ahref="#breaking-changes">breaking changes from CoffeeScript 1.x to 2</a>; we hope the upgrade process is smooth for most projects.</p>
@@ -3244,7 +3247,7 @@ <h2>JSX</h2>
3244
3247
</div>
3245
3248
3246
3249
</aside>
3247
-
<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>
3250
+
<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>
3248
3251
3249
3252
</section>
3250
3253
</section>
@@ -3619,7 +3622,7 @@ <h3>Classes are compiled to ES2015 classes</h3>
constructor: <spanclass="function">-></span><spanclass="keyword">this</span><spanclass="comment"># Throws a compiler error</span>
3621
3624
</code></pre>
3622
-
</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>
3625
+
</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>
<h3>JSX and the <code><</code> and <code>></code>Operators</h3>
3793
+
<h3>JSX and the <code><</code> and <code>></code>operators</h3>
3791
3794
<p>With the addition of <ahref="#jsx">JSX</a>, the <code><</code> and <code>></code> characters serve as both the “less than” and “greater than” operators and as the delimiters for XML tags, like <code><div></code>. For best results, in general you should always wrap the operators in spaces to distinguish them from XML tags: <code>i < len</code>, not <code>i<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>
<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>
3798
3801
<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>
<h3>Argument parsing and shebang (<code>#!</code>) lines</h3>
3806
+
<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><p>The deprecated version will still work, but it will print a warning before running the script.</p>
3813
+
<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><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>
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:
4
+
5
+
```bash
6
+
coffee [options] path/to/script.coffee -- [args]
7
+
```
8
+
9
+
Now you would just type:
10
+
11
+
```bash
12
+
coffee [options] path/to/script.coffee [args]
13
+
```
14
+
15
+
The deprecated version will still work, but it will print a warning before running the script.
16
+
17
+
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:
18
+
19
+
```coffee
20
+
#!/usr/bin/env coffee
21
+
22
+
x=2+2
23
+
console.log x
24
+
```
25
+
26
+
If this were saved as `executable.coffee`, it could be made executable and run:
27
+
28
+
```bash
29
+
▶ chmod +x ./executable.coffee
30
+
▶ ./executable.coffee
31
+
4
32
+
```
33
+
34
+
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`.
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.
Copy file name to clipboardExpand all lines: documentation/sections/coffeescript_2.md
+1-1Lines changed: 1 addition & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -2,7 +2,7 @@
2
2
3
3
### What’s New In CoffeeScript 2?
4
4
5
-
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.
5
+
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.
6
6
7
7
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.
0 commit comments