From 27caf62322a1175f3ec1f2e0ea00a31339a2d625 Mon Sep 17 00:00:00 2001 From: Geoffrey Booth Date: Sun, 2 Apr 2017 22:53:18 -0700 Subject: [PATCH] =?UTF-8?q?Merge=20discussion=20of=20CoffeeScript=E2=80=99?= =?UTF-8?q?s=20benefits=20into=20expanded=20CoffeeScript=202=20section=20a?= =?UTF-8?q?nd=20revised=20Contributing=20section?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/v2/index.html | 85 +++++++++++++++++++++- documentation/sections/coffeescript_2.md | 20 ++++- documentation/sections/contributing.md | 25 +++---- documentation/sections/why_coffeescript.md | 43 ----------- documentation/v2/body.html | 1 - documentation/v2/sidebar.html | 3 - 6 files changed, 111 insertions(+), 66 deletions(-) delete mode 100644 documentation/sections/why_coffeescript.md diff --git a/docs/v2/index.html b/docs/v2/index.html index ac134080..2d7a4155 100644 --- a/docs/v2/index.html +++ b/docs/v2/index.html @@ -607,6 +607,9 @@ textarea { + +
  • Source Maps — src/sourcemap
  • + +
    +

    Contributing

    Contributions are welcome! Feel free to fork the repo and submit a pull request.

    +

    Some features of ECMAScript are intentionally unsupported. Please review both the open and closed issues on GitHub to see if the feature you’re looking for has already been discussed. As a general rule, we don’t support ECMAScript syntax for features that aren’t yet finalized (at Stage 4 in the proposal approval process).

    +

    For more resources on adding to CoffeeScript, please see the Wiki, especially How The Parser Works.

    +

    There are several things you can do to increase your odds of having your pull request accepted:

    + +

    Of course, it’s entirely possible that you have a great addition, but it doesn’t fit within these constraints. Feel free to roll your own solution; you will have plenty of company.

    +
    diff --git a/documentation/sections/coffeescript_2.md b/documentation/sections/coffeescript_2.md index bb13903c..351bef88 100644 --- a/documentation/sections/coffeescript_2.md +++ b/documentation/sections/coffeescript_2.md @@ -1,5 +1,21 @@ ## CoffeeScript 2 -CoffeeScript 2 generates JavaScript that uses the latest ES2015+ features. It is your responsibility to ensure that your target JavaScript runtime(s) support all these features, or that you pass the output through another transpiler like [Babel](http://babeljs.io/), [Rollup](https://github.com/rollup/rollup) or [Traceur Compiler](https://github.com/google/traceur-compiler). In general, [CoffeeScript 2’s output is fully supported by Node.js 7+](http://node.green/), although async functions require the `--harmony` or `--harmony-async-await` flags; and ES2015 modules require an additional transpiler. Output JavaScript intended for browsers generally requires additional transpilation. +### Why CoffeeScript When There’s ES2015+? -If you’re looking for a single tool that takes CoffeeScript input and generates JavaScript output that runs in any JavaScript runtime, assuming you opt out of certain newer features, stick to the [CoffeeScript 1.x branch](v1/). CoffeeScript 2 [breaks compatibility](#breaking-changes) with certain CoffeeScript 1.x features in order to conform with the ES2015+ specifications, and generate more idiomatic output (a CoffeeScript `=>` becomes an ES `=>`; a CoffeeScript `class` becomes an ES `class`; and so on). +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 a cleaner, terser syntax that uses less punctuation and enforces indentation, to make code easier to read and reason about. Increased clarity leads to increased quality, and fewer bugs. This benefit of CoffeeScript remains, even in an ES2015+ world. + +### ES2015+ Output + +CoffeeScript 2 supports many of the latest ES2015+ features, output using ES2015+ syntax. If you’re looking for a single tool that takes CoffeeScript input and generates JavaScript output that runs in any JavaScript runtime, assuming you opt out of certain newer features, stick to the [CoffeeScript 1.x branch](v1/). CoffeeScript 2 [breaks compatibility](#breaking-changes) with certain CoffeeScript 1.x features in order to conform with the ES2015+ specifications, and generate more idiomatic output (a CoffeeScript `=>` becomes an ES `=>`; a CoffeeScript `class` becomes an ES `class`; and so on). + +Since the CoffeeScript 2 compiler outputs ES2015+ syntax, it is your responsibility to either ensure that your target JavaScript runtime(s) support all these features, or that you pass the output through another transpiler like [Babel](http://babeljs.io/), [Rollup](https://github.com/rollup/rollup) or [Traceur Compiler](https://github.com/google/traceur-compiler). In general, [CoffeeScript 2’s output is supported as is by Node.js 7.6+](http://node.green/), except for modules which require transpilation. + +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/). If you’re looking for a very minimal solution to get started, you can use [babel-preset-env](https://babeljs.io/docs/plugins/preset-env/) and the command line: + +> ```bash +npm install --global coffeescript@next +npm install --save-dev coffeescript@next babel-cli babel-preset-env +coffee -p *.coffee | babel --presets env > app.js +``` \ No newline at end of file diff --git a/documentation/sections/contributing.md b/documentation/sections/contributing.md index f5deeef8..51786be0 100644 --- a/documentation/sections/contributing.md +++ b/documentation/sections/contributing.md @@ -1,21 +1,16 @@ -## Contributing -Contributions are welcome, feel free to fork a copy and submit a pull request. +## Contributing -If there is a core part of ECMAScript you think we are missing, head on over to [CoffeeScript issues on GitHub](http://github.com/jashkenas/coffeescript/issues), and dig around in the open and closed issues. +Contributions are welcome! Feel free to fork [the repo](http://github.com/jashkenas/coffeescript) and submit a pull request. -For more resources on adding to CoffeeScript, please see [the Wiki](https://github.com/jashkenas/coffeescript/wiki/%5BHowto%5D-Hacking-on-the-CoffeeScript-Compiler) or [How The Parser Works](https://github.com/jashkenas/coffeescript/wiki/%5BHowTo%5D-How-parsing-works) if you are interested in learning how the parser works. +[Some features of ECMAScript are intentionally unsupported](#unsupported). Please review both the open and closed [issues on GitHub](http://github.com/jashkenas/coffeescript/issues) to see if the feature you’re looking for has already been discussed. As a general rule, we don’t support ECMAScript syntax for features that aren’t yet finalized (at Stage 4 in the proposal approval process). -There are several things you can do to increase your odds of having the pull request accepted: +For more resources on adding to CoffeeScript, please see [the Wiki](https://github.com/jashkenas/coffeescript/wiki/%5BHowto%5D-Hacking-on-the-CoffeeScript-Compiler), especially [How The Parser Works](https://github.com/jashkenas/coffeescript/wiki/%5BHowTo%5D-How-parsing-works). - * Create tests! Any pull request should probably include basic tests to verify you didn't break anything, or future changes won't break your code. - * Follow the CoffeeScript style guide - * Ensure any ECMAScript addition is mature (at Stage 4), with no further potential syntax changes. - * Adding only the features that help the community rather than a specific use case. +There are several things you can do to increase your odds of having your pull request accepted: -Of course, it's entirely possible that you have a great addition, but it doesn't fit directly with the CoffeeScript code base. + * Create tests! Any pull request should probably include basic tests to verify you didn’t break anything, or future changes won’t break your code. + * Follow the style of the rest of the CoffeeScript codebase. + * Ensure any ECMAScript syntax is mature (at Stage 4), with no further potential changes. + * Add only features that have broad utility, rather than a feature aimed at a specific use case or framework. -This might be the time to... - -## Roll Your Own - -You are of course, welcome to fork the language and add in the features you want. There are [quite a few](https://github.com/jashkenas/coffeescript/wiki/In-The-Wild) really interesting projects that have done so, and more are welcome. \ No newline at end of file +Of course, it’s entirely possible that you have a great addition, but it doesn’t fit within these constraints. Feel free to roll your own solution; you will have [plenty of company](https://github.com/jashkenas/coffeescript/wiki/In-The-Wild). diff --git a/documentation/sections/why_coffeescript.md b/documentation/sections/why_coffeescript.md deleted file mode 100644 index 47b8de7e..00000000 --- a/documentation/sections/why_coffeescript.md +++ /dev/null @@ -1,43 +0,0 @@ -## Why CoffeeScript? -There are a few things you should know about CoffeeScript. - -CoffeeScript is about: - - * Reducing complexity - * Keeping your code clean - * Being terse - * Removing as many 'Bad Parts' as possible - * Reducing code quality issues - * Increasing readability - * Being stable - * Bringing out the best from ECMAScript - -CoffeeScript is NOT about: - - * Having the latest XX/YY feature - * Implementing every aspect of ECMAScript, just because it's there. - * Trying to appease developers from other languages - -There are many style choices within the language, and they have been carefully thought out. Taking time out to understand how CoffeeScript works, and how to work well with it will help you write better, easier to read, safer and more reliable code. - -## Why not just use ECMAScript 7? - - -ECMAScript has adopted much of the syntax and ideas of CoffeeScript. Unfortunately it still exposes you to many of the 'Bad Parts' of the language. On top of that the ECMASCript syntax is cumulative, allowing a much larger spectrum of potential errors. - -ECMAScript 6/7 are standards, and you should probably know how to work with it. You might assume that working with ECMAScript 6 is more direct or cleaner. But using those newer features still requires a transpiler, for instance Babel. If you consider most front end targetted code still needs a build tool like Grunt, then you will find adding an extra step for CoffeeScript very trivial. - -You will find: - -* CoffeeScript has adopted the vast majority of stable ECMAScript features. -* CoffeeScript protects you by avoiding a wide spectrum of errors. -* You have consistent variable behavior without having to think about context and usage of every variable. -* You reduce cognitive load of the syntax and can get down to solving problems. -* Most parentheses are optional, making functional programming styles much cleaner. -* CoffeeScript forces indenting, which makes code much more readable, and eliminates many nesting errors. -* Most Parentheses go away and no more semicolan errors. -* CoffeeScript has an existential operator `?`, which makes checking for missing elements a breeze. -* CoffeeScript is fully interoperable with ECMAScript code. -* Cleaner syntax for yields, async, and unbound functions `() ->` - -You can learn CoffeeScript in a few hours, and you will be amazed at how much better your code will be. \ No newline at end of file diff --git a/documentation/v2/body.html b/documentation/v2/body.html index 5c404a89..5f7f51ac 100644 --- a/documentation/v2/body.html +++ b/documentation/v2/body.html @@ -16,7 +16,6 @@
    <%= htmlFor('introduction') %> <%= htmlFor('overview') %> - <%= htmlFor('why_coffeescript') %>
    <%= htmlFor('coffeescript_2') %> diff --git a/documentation/v2/sidebar.html b/documentation/v2/sidebar.html index eba9da8d..0326874c 100644 --- a/documentation/v2/sidebar.html +++ b/documentation/v2/sidebar.html @@ -3,9 +3,6 @@ -