mirror of
https://github.com/jashkenas/coffeescript.git
synced 2026-01-13 08:47:55 -05:00
Compare commits
302 Commits
2.0.0-beta
...
2.6.1
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ed6733d177 | ||
|
|
d572d744eb | ||
|
|
e82de9c0f6 | ||
|
|
f5073fa132 | ||
|
|
f9c3316aa5 | ||
|
|
ff13d85625 | ||
|
|
c4f1fe7132 | ||
|
|
b0946c3c60 | ||
|
|
b90bc2459a | ||
|
|
07f644c392 | ||
|
|
2fd9ee403c | ||
|
|
389ce89555 | ||
|
|
75d376f2ef | ||
|
|
3136bde928 | ||
|
|
26a7ba1659 | ||
|
|
9cef39d21a | ||
|
|
92ad04b9b1 | ||
|
|
6fe980e569 | ||
|
|
bb8df1e052 | ||
|
|
61d408f093 | ||
|
|
ba41b4417d | ||
|
|
33bbef963c | ||
|
|
c4f0c9ed06 | ||
|
|
8677a0dbc4 | ||
|
|
ee2a107f3c | ||
|
|
8fb5c1ba4f | ||
|
|
b2b2f97873 | ||
|
|
0045cb21ba | ||
|
|
a8273bf980 | ||
|
|
3e7c570679 | ||
|
|
a34c0c9502 | ||
|
|
2ab714b4fe | ||
|
|
56eec0bc4e | ||
|
|
f528e5e754 | ||
|
|
bdcb2c73af | ||
|
|
9b37f16f11 | ||
|
|
26351096a6 | ||
|
|
a091bb82f9 | ||
|
|
a6d4bf1982 | ||
|
|
0e51cdaccd | ||
|
|
d4b7bd3a1f | ||
|
|
559e735994 | ||
|
|
09caa217c2 | ||
|
|
a35df430db | ||
|
|
05d45e9b27 | ||
|
|
69521b97ce | ||
|
|
c7e538a624 | ||
|
|
44be72a4d9 | ||
|
|
9cfcf8623c | ||
|
|
25c23786af | ||
|
|
47bf5d962b | ||
|
|
a30e6807b1 | ||
|
|
d735c81da0 | ||
|
|
f56515b100 | ||
|
|
74d6635f95 | ||
|
|
e8d0deae78 | ||
|
|
95d6ec7492 | ||
|
|
09c95394e1 | ||
|
|
ddb5dac49d | ||
|
|
265b251a7d | ||
|
|
7539f7af2e | ||
|
|
2f27225e8c | ||
|
|
99ad0cc16c | ||
|
|
70c2c4706f | ||
|
|
9d1af43c91 | ||
|
|
c6fdde8834 | ||
|
|
0174ee082c | ||
|
|
82b7bd3a92 | ||
|
|
1f22c16bee | ||
|
|
f33d4dd4f1 | ||
|
|
9c913f86fa | ||
|
|
f0bb59790a | ||
|
|
391fcc4afa | ||
|
|
7b2fb18a0b | ||
|
|
5596a5c209 | ||
|
|
71750554c3 | ||
|
|
0574b664e8 | ||
|
|
ca0ac814b3 | ||
|
|
c0b3217766 | ||
|
|
12a5271489 | ||
|
|
f4fcf65750 | ||
|
|
92f69b2bca | ||
|
|
742224471f | ||
|
|
086430840e | ||
|
|
82f92fea97 | ||
|
|
d23919c430 | ||
|
|
ada35d8951 | ||
|
|
7e0eb6a92d | ||
|
|
28a1a1d304 | ||
|
|
0c2d3673d3 | ||
|
|
e6f6aa8c85 | ||
|
|
c09d8fbedb | ||
|
|
730a4bcdad | ||
|
|
7466c81414 | ||
|
|
b79ea321a3 | ||
|
|
ae2f72e15d | ||
|
|
f6d63776c3 | ||
|
|
b982b7cd0e | ||
|
|
0b5bac666f | ||
|
|
41b31c7293 | ||
|
|
eaeb77a527 | ||
|
|
ec034e2673 | ||
|
|
ff24e5ce52 | ||
|
|
4549f9a4c5 | ||
|
|
d0be6391c6 | ||
|
|
f70f4f09b7 | ||
|
|
3f5abb3c60 | ||
|
|
ca275c2a1c | ||
|
|
99b7826f1b | ||
|
|
806a442894 | ||
|
|
63ffe0aead | ||
|
|
74e0798f89 | ||
|
|
247b511c6a | ||
|
|
6a8e6a4078 | ||
|
|
42402da526 | ||
|
|
42622b15a9 | ||
|
|
1879af6585 | ||
|
|
a7b1fa51e7 | ||
|
|
38c8b2f35f | ||
|
|
4392d26985 | ||
|
|
2f82b75862 | ||
|
|
459814f58d | ||
|
|
088659f893 | ||
|
|
0e37130f2e | ||
|
|
fb539579c3 | ||
|
|
7c54532010 | ||
|
|
5d57ea785c | ||
|
|
94e29c9a95 | ||
|
|
fe7377aed5 | ||
|
|
e934a42e75 | ||
|
|
294bb4754e | ||
|
|
5eab5f1d22 | ||
|
|
8b775c95ad | ||
|
|
251700549a | ||
|
|
3fbf76e135 | ||
|
|
ca04dd6e47 | ||
|
|
a82f869453 | ||
|
|
f932206213 | ||
|
|
849dd53287 | ||
|
|
e03a87da04 | ||
|
|
29aa9b36fe | ||
|
|
c6472fa617 | ||
|
|
1bbbca6496 | ||
|
|
6b1e9bb82b | ||
|
|
eb22196850 | ||
|
|
3b1c49240b | ||
|
|
ea33c28f1b | ||
|
|
7b251f493d | ||
|
|
0be8c5d161 | ||
|
|
617a2d5b65 | ||
|
|
e1625a0d31 | ||
|
|
4c6cc8d060 | ||
|
|
e6153d9841 | ||
|
|
6e86b67818 | ||
|
|
b4dceaea67 | ||
|
|
d83b95bd39 | ||
|
|
4ba1be131c | ||
|
|
8dabec0f9b | ||
|
|
e679cbccf7 | ||
|
|
b18e91f936 | ||
|
|
c31a30d3fa | ||
|
|
99b2578aa7 | ||
|
|
ddfde6810c | ||
|
|
71350d67c4 | ||
|
|
13857a5d71 | ||
|
|
6225627579 | ||
|
|
c4245e50c2 | ||
|
|
6ce1d36acd | ||
|
|
b2669abecc | ||
|
|
db86dc4d8b | ||
|
|
98b2a69416 | ||
|
|
16b4448fe8 | ||
|
|
af82c1f41f | ||
|
|
3e089ca59d | ||
|
|
7f8b36a8bd | ||
|
|
812571843c | ||
|
|
8a25195442 | ||
|
|
70f6cb70e2 | ||
|
|
be702d67f3 | ||
|
|
68302e6da7 | ||
|
|
0e7677ad62 | ||
|
|
7cf739e2b6 | ||
|
|
41185ca7ac | ||
|
|
7dbdca8c54 | ||
|
|
8e66ae404e | ||
|
|
7beb631694 | ||
|
|
c2792e4840 | ||
|
|
d82272b6c2 | ||
|
|
fe7554828a | ||
|
|
708e57586c | ||
|
|
8061ecf0e2 | ||
|
|
6df8f5ff17 | ||
|
|
776e7e5328 | ||
|
|
871079b25c | ||
|
|
be2b24310f | ||
|
|
1f9cd4eaf7 | ||
|
|
47c491ffa1 | ||
|
|
195a46ab77 | ||
|
|
e5aa758dda | ||
|
|
001f97ac39 | ||
|
|
ce66a499de | ||
|
|
0268505119 | ||
|
|
5a43b2d7c5 | ||
|
|
820942c3d0 | ||
|
|
1869f3121d | ||
|
|
4c0363fb7c | ||
|
|
746b0c7cc6 | ||
|
|
b2fe7772c5 | ||
|
|
23479eb486 | ||
|
|
63b8543d73 | ||
|
|
7542a75ff8 | ||
|
|
0875039d52 | ||
|
|
e0833c29ce | ||
|
|
72ab6feb2f | ||
|
|
eb7009268d | ||
|
|
571e9df335 | ||
|
|
a73f66bc11 | ||
|
|
ba094126e2 | ||
|
|
794f65fbd7 | ||
|
|
0490eb9a3a | ||
|
|
9e80f6fa67 | ||
|
|
fc5ab1afa3 | ||
|
|
0aa77f157a | ||
|
|
1849f0db76 | ||
|
|
d86597dbad | ||
|
|
bf91781888 | ||
|
|
dcd6de9a77 | ||
|
|
70b510bcb7 | ||
|
|
84d596d534 | ||
|
|
c804087ec9 | ||
|
|
74bd537d6c | ||
|
|
0217ed5505 | ||
|
|
e53307b46b | ||
|
|
c8c8c167d1 | ||
|
|
c1283ead45 | ||
|
|
3ade25a32c | ||
|
|
7ea3ea92f3 | ||
|
|
a70f1a082e | ||
|
|
2ccbb6b91a | ||
|
|
e348026073 | ||
|
|
7c6f3788ca | ||
|
|
12fcbfc654 | ||
|
|
38f5963b85 | ||
|
|
ffbe51e374 | ||
|
|
926cb8463c | ||
|
|
b1286752b9 | ||
|
|
5eb9dded52 | ||
|
|
7f5ab7eb0d | ||
|
|
5bc85b8f6d | ||
|
|
81d1b511f0 | ||
|
|
2dc3f6c87a | ||
|
|
04959162c6 | ||
|
|
f14c7ffa3f | ||
|
|
64b8dd486a | ||
|
|
7864acabc3 | ||
|
|
9812d28748 | ||
|
|
555c22af58 | ||
|
|
3f4b03bcff | ||
|
|
a706a64a6d | ||
|
|
637fe305a6 | ||
|
|
bd824c73dd | ||
|
|
cbc695b831 | ||
|
|
f3375e798c | ||
|
|
e2308093e4 | ||
|
|
0dc4755920 | ||
|
|
6faa7f2b35 | ||
|
|
063c2d1f56 | ||
|
|
4d4e47bfb2 | ||
|
|
22fb31e317 | ||
|
|
a2037e799f | ||
|
|
694e69d872 | ||
|
|
bb2871fdde | ||
|
|
08e00331dd | ||
|
|
0b0a9ef2c4 | ||
|
|
9df1457c55 | ||
|
|
22f92f23ae | ||
|
|
cd516b954f | ||
|
|
27eff5ca77 | ||
|
|
5cbd25f5d4 | ||
|
|
eb127923a7 | ||
|
|
42da56deb1 | ||
|
|
81260bff7d | ||
|
|
35f784bcdf | ||
|
|
c17b6b8863 | ||
|
|
1965996933 | ||
|
|
a67dfae985 | ||
|
|
1cb733989c | ||
|
|
a2a2e769c3 | ||
|
|
19231dbcad | ||
|
|
aecc115c79 | ||
|
|
4c41831474 | ||
|
|
659f1b3c4c | ||
|
|
f51c1a150b | ||
|
|
970f31c292 | ||
|
|
d172405244 | ||
|
|
44ebfdb764 | ||
|
|
1b8f1af287 | ||
|
|
e7073bc5d9 | ||
|
|
63d3b699d7 | ||
|
|
458440e57b | ||
|
|
6cea181ff1 | ||
|
|
e3c2c0397a |
44
.github/workflows/continuous-integration.yml
vendored
Normal file
44
.github/workflows/continuous-integration.yml
vendored
Normal file
@@ -0,0 +1,44 @@
|
||||
# Based on https://github.com/actions/starter-workflows/blob/master/ci/node.js.yml
|
||||
|
||||
name: Build and Test
|
||||
|
||||
on: [push, pull_request]
|
||||
|
||||
jobs:
|
||||
ci:
|
||||
runs-on: ${{ matrix.operating-system }}
|
||||
|
||||
strategy:
|
||||
matrix:
|
||||
operating-system: [ubuntu-latest, macos-latest, windows-latest]
|
||||
node-version: [10.x, 12.x, 14.x, 16.x]
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: Use Node.js ${{ matrix.node-version }}
|
||||
uses: actions/setup-node@v2
|
||||
with:
|
||||
node-version: ${{ matrix.node-version }}
|
||||
|
||||
- run: npm ci
|
||||
|
||||
# Ensure that we can still build in the current version of Node
|
||||
- run: node ./bin/cake build:except-parser
|
||||
- run: node ./bin/cake build:parser
|
||||
# Build twice to ensure that the latest build of the compiler can still build itself
|
||||
- run: node ./bin/cake build:except-parser
|
||||
- run: node ./bin/cake build:parser
|
||||
# Build the browser compiler for the headless browser test
|
||||
- run: node ./bin/cake build:browser
|
||||
|
||||
# Check that the git diff is clean, to ensure that the updated build output was committed
|
||||
- run: git diff --exit-code
|
||||
|
||||
# Build test.html, so that test:browser uses the latest tests
|
||||
- run: node ./bin/cake doc:test
|
||||
|
||||
# Test
|
||||
- run: node ./bin/cake test
|
||||
- run: node ./bin/cake test:browser
|
||||
- run: node ./bin/cake test:browser:node
|
||||
- run: node ./bin/cake test:integrations
|
||||
1
.gitignore
vendored
1
.gitignore
vendored
@@ -9,3 +9,4 @@ parser.output
|
||||
/node_modules
|
||||
npm-debug.log*
|
||||
yarn.lock
|
||||
.DS_Store
|
||||
|
||||
46
CODE_OF_CONDUCT.md
Normal file
46
CODE_OF_CONDUCT.md
Normal file
@@ -0,0 +1,46 @@
|
||||
# Contributor Covenant Code of Conduct
|
||||
|
||||
## Our Pledge
|
||||
|
||||
In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation.
|
||||
|
||||
## Our Standards
|
||||
|
||||
Examples of behavior that contributes to creating a positive environment include:
|
||||
|
||||
* Using welcoming and inclusive language
|
||||
* Being respectful of differing viewpoints and experiences
|
||||
* Gracefully accepting constructive criticism
|
||||
* Focusing on what is best for the community
|
||||
* Showing empathy towards other community members
|
||||
|
||||
Examples of unacceptable behavior by participants include:
|
||||
|
||||
* The use of sexualized language or imagery and unwelcome sexual attention or advances
|
||||
* Trolling, insulting/derogatory comments, and personal or political attacks
|
||||
* Public or private harassment
|
||||
* Publishing others' private information, such as a physical or electronic address, without explicit permission
|
||||
* Other conduct which could reasonably be considered inappropriate in a professional setting
|
||||
|
||||
## Our Responsibilities
|
||||
|
||||
Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior.
|
||||
|
||||
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful.
|
||||
|
||||
## Scope
|
||||
|
||||
This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers.
|
||||
|
||||
## Enforcement
|
||||
|
||||
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at maintainers@coffeescript.org. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately.
|
||||
|
||||
Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership.
|
||||
|
||||
## Attribution
|
||||
|
||||
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version]
|
||||
|
||||
[homepage]: http://contributor-covenant.org
|
||||
[version]: http://contributor-covenant.org/version/1/4/
|
||||
@@ -6,4 +6,9 @@
|
||||
|
||||
* Use the same coding style as the rest of the [codebase](https://github.com/jashkenas/coffeescript/tree/master/src). If you’re just getting started with CoffeeScript, there’s a nice [style guide](https://github.com/polarmobile/coffeescript-style-guide).
|
||||
|
||||
* In your pull request, do not add documentation to `index.html` or re-build the minified `coffeescript.js` file. We’ll do those things before cutting a new release. You _should,_ however, commit the updated compiled JavaScript files in `lib`.
|
||||
* In your pull request, do not add documentation to `index.html` or re-build the minified `coffeescript.js` file. We’ll do those things before cutting a new release. You _should,_ however, commit the updated compiled JavaScript files in `lib`.
|
||||
|
||||
* To get started, read the guides in the wiki:
|
||||
* [Hacking on the CoffeeScript Compiler](https://github.com/jashkenas/coffeescript/wiki/%5BHowTo%5D-Hacking-on-the-CoffeeScript-Compiler)
|
||||
* [How parsing works](https://github.com/jashkenas/coffeescript/wiki/%5BHowTo%5D-How-parsing-works)
|
||||
* [Update the docs](https://github.com/jashkenas/coffeescript/wiki/%5BHowTo%5D-Update-the-docs)
|
||||
|
||||
274
Cakefile
274
Cakefile
@@ -19,9 +19,9 @@ unless process.env.NODE_DISABLE_COLORS
|
||||
header = """
|
||||
/**
|
||||
* CoffeeScript Compiler v#{CoffeeScript.VERSION}
|
||||
* http://coffeescript.org
|
||||
* https://coffeescript.org
|
||||
*
|
||||
* Copyright 2011, Jeremy Ashkenas
|
||||
* Copyright 2011-#{new Date().getFullYear()}, Jeremy Ashkenas
|
||||
* Released under the MIT License
|
||||
*/
|
||||
"""
|
||||
@@ -66,6 +66,25 @@ build = (callback) ->
|
||||
buildParser()
|
||||
buildExceptParser callback
|
||||
|
||||
transpile = (code, options = {}) ->
|
||||
options.minify = process.env.MINIFY isnt 'false'
|
||||
options.transform = process.env.TRANSFORM isnt 'false'
|
||||
options.sourceType ?= 'script'
|
||||
babel = require '@babel/core'
|
||||
presets = []
|
||||
# Exclude the `modules` plugin in order to not break the `}(this));`
|
||||
# at the end of the `build:browser` code block.
|
||||
presets.push ['@babel/env', {modules: no}] if options.transform
|
||||
presets.push ['minify', {mangle: no, evaluate: no, removeUndefined: no}] if options.minify
|
||||
babelOptions =
|
||||
presets: presets
|
||||
compact: options.minify
|
||||
minified: options.minify
|
||||
comments: not options.minify
|
||||
sourceType: options.sourceType
|
||||
{ code } = babel.transformSync code, babelOptions unless presets.length is 0
|
||||
code
|
||||
|
||||
testBuiltCode = (watch = no) ->
|
||||
csPath = './lib/coffeescript'
|
||||
csDir = path.dirname require.resolve csPath
|
||||
@@ -79,7 +98,7 @@ testBuiltCode = (watch = no) ->
|
||||
|
||||
buildAndTest = (includingParser = yes, harmony = no) ->
|
||||
process.stdout.write '\x1Bc' # Clear terminal screen.
|
||||
execSync 'git checkout lib/*', stdio: [0,1,2] # Reset the generated compiler.
|
||||
execSync 'git checkout lib/*', stdio: 'inherit' # Reset the generated compiler.
|
||||
|
||||
buildArgs = ['bin/cake']
|
||||
buildArgs.push if includingParser then 'build' else 'build:except-parser'
|
||||
@@ -126,13 +145,18 @@ task 'build:browser', 'merge the built scripts into a single file for use in a b
|
||||
return module.exports;
|
||||
})();
|
||||
"""
|
||||
# From here, we generate two outputs: a legacy script output for all browsers
|
||||
# and a module output for browsers that support `<script type="module">`.
|
||||
code = """
|
||||
var CoffeeScript = function() {
|
||||
function require(path){ return require[path]; }
|
||||
#{code}
|
||||
return require['./browser'];
|
||||
}();
|
||||
"""
|
||||
scriptCode = transpile """
|
||||
(function(root) {
|
||||
var CoffeeScript = function() {
|
||||
function require(path){ return require[path]; }
|
||||
#{code}
|
||||
return require['./browser'];
|
||||
}();
|
||||
#{code}
|
||||
|
||||
if (typeof define === 'function' && define.amd) {
|
||||
define(function() { return CoffeeScript; });
|
||||
@@ -141,27 +165,25 @@ task 'build:browser', 'merge the built scripts into a single file for use in a b
|
||||
}
|
||||
}(this));
|
||||
"""
|
||||
babel = require 'babel-core'
|
||||
presets = []
|
||||
# Exclude the `modules` plugin in order to not break the `}(this));`
|
||||
# at the end of the above code block.
|
||||
presets.push ['env', {modules: no}] unless process.env.TRANSFORM is 'false'
|
||||
babelOptions =
|
||||
presets: presets
|
||||
sourceType: 'script'
|
||||
{ code } = babel.transform code, babelOptions unless presets.length is 0
|
||||
# Running Babel twice due to https://github.com/babel/babili/issues/614.
|
||||
# Once that issue is fixed, move the `babili` preset back up into the
|
||||
# `presets` array and run Babel once with both presets together.
|
||||
presets = if process.env.MINIFY is 'false' then [] else ['babili']
|
||||
babelOptions =
|
||||
compact: process.env.MINIFY isnt 'false'
|
||||
presets: presets
|
||||
sourceType: 'script'
|
||||
{ code } = babel.transform code, babelOptions unless presets.length is 0
|
||||
outputFolder = "docs/v#{majorVersion}/browser-compiler"
|
||||
fs.mkdirSync outputFolder unless fs.existsSync outputFolder
|
||||
fs.writeFileSync "#{outputFolder}/coffeescript.js", header + '\n' + code
|
||||
moduleCode = transpile """
|
||||
#{code}
|
||||
|
||||
export default CoffeeScript;
|
||||
const { VERSION, compile, eval: evaluate, load, run, runScripts } = CoffeeScript;
|
||||
export { VERSION, compile, evaluate as eval, load, run, runScripts };
|
||||
""", {sourceType: 'module'}
|
||||
outputFolders = [
|
||||
"docs/v#{majorVersion}/browser-compiler-legacy"
|
||||
"docs/v#{majorVersion}/browser-compiler-modern"
|
||||
"lib/coffeescript-browser-compiler-legacy"
|
||||
"lib/coffeescript-browser-compiler-modern"
|
||||
]
|
||||
for outputFolder in outputFolders
|
||||
fs.mkdirSync outputFolder unless fs.existsSync outputFolder
|
||||
fs.writeFileSync "#{outputFolder}/coffeescript.js", """
|
||||
#{header}
|
||||
#{if outputFolder.includes('legacy') then scriptCode else moduleCode}
|
||||
"""
|
||||
|
||||
task 'build:browser:full', 'merge the built scripts into a single file for use in a browser, and test it', ->
|
||||
invoke 'build:browser'
|
||||
@@ -177,29 +199,22 @@ task 'build:watch:harmony', 'watch and continually rebuild the CoffeeScript comp
|
||||
|
||||
buildDocs = (watch = no) ->
|
||||
# Constants
|
||||
indexFile = 'documentation/index.html'
|
||||
versionedSourceFolder = "documentation/v#{majorVersion}"
|
||||
sectionsSourceFolder = 'documentation/sections'
|
||||
examplesSourceFolder = 'documentation/examples'
|
||||
outputFolder = "docs/v#{majorVersion}"
|
||||
indexFile = 'documentation/site/index.html'
|
||||
siteSourceFolder = "documentation/site"
|
||||
sectionsSourceFolder = 'documentation/sections'
|
||||
changelogSourceFolder = 'documentation/sections/changelog'
|
||||
examplesSourceFolder = 'documentation/examples'
|
||||
outputFolder = "docs/v#{majorVersion}"
|
||||
|
||||
# Helpers
|
||||
releaseHeader = (date, version, prevVersion) ->
|
||||
monthNames = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December']
|
||||
|
||||
formatDate = (date) ->
|
||||
date.replace /^(\d\d\d\d)-(\d\d)-(\d\d)$/, (match, $1, $2, $3) ->
|
||||
"#{monthNames[$2 - 1]} #{+$3}, #{$1}"
|
||||
|
||||
"""
|
||||
<div class="anchor" id="#{version}"></div>
|
||||
<h2 class="header">
|
||||
#{prevVersion and "<a href=\"https://github.com/jashkenas/coffeescript/compare/#{prevVersion}...#{version}\">#{version}</a>" or version}
|
||||
<span class="timestamp"> — <time datetime="#{date}">#{formatDate date}</time></span>
|
||||
</h2>
|
||||
<h3>#{prevVersion and "<a href=\"https://github.com/jashkenas/coffeescript/compare/#{prevVersion}...#{version}\">#{version}</a>" or version}
|
||||
<span class="timestamp"> — <time datetime="#{date}">#{date}</time></span>
|
||||
</h3>
|
||||
"""
|
||||
|
||||
codeFor = require "./documentation/v#{majorVersion}/code.coffee"
|
||||
codeFor = require "./documentation/site/code.coffee"
|
||||
|
||||
htmlFor = ->
|
||||
hljs = require 'highlight.js'
|
||||
@@ -207,11 +222,11 @@ buildDocs = (watch = no) ->
|
||||
markdownRenderer = require('markdown-it')
|
||||
html: yes
|
||||
typographer: yes
|
||||
highlight: (str, lang) ->
|
||||
highlight: (str, language) ->
|
||||
# From https://github.com/markdown-it/markdown-it#syntax-highlighting
|
||||
if lang and hljs.getLanguage(lang)
|
||||
if language and hljs.getLanguage(language)
|
||||
try
|
||||
return hljs.highlight(lang, str).value
|
||||
return hljs.highlight(str, { language }).value
|
||||
catch ex
|
||||
return '' # No syntax highlighting
|
||||
|
||||
@@ -227,7 +242,7 @@ buildDocs = (watch = no) ->
|
||||
"<blockquote class=\"uneditable-code-block\">#{defaultFence.apply @, arguments}</blockquote>"
|
||||
|
||||
(file, bookmark) ->
|
||||
md = fs.readFileSync "#{sectionsSourceFolder}/#{file}.md", 'utf-8'
|
||||
md = fs.readFileSync "#{sectionsSourceFolder}/#{file.replace /\//g, path.sep}.md", 'utf-8'
|
||||
md = md.replace /<%= releaseHeader %>/g, releaseHeader
|
||||
md = md.replace /<%= majorVersion %>/g, majorVersion
|
||||
md = md.replace /<%= fullVersion %>/g, CoffeeScript.VERSION
|
||||
@@ -236,9 +251,17 @@ buildDocs = (watch = no) ->
|
||||
codeFor: codeFor()
|
||||
releaseHeader: releaseHeader
|
||||
|
||||
includeScript = ->
|
||||
(file) ->
|
||||
file = "#{siteSourceFolder}/#{file}" unless '/' in file
|
||||
code = fs.readFileSync file, 'utf-8'
|
||||
code = CoffeeScript.compile code
|
||||
code = transpile code
|
||||
code
|
||||
|
||||
include = ->
|
||||
(file) ->
|
||||
file = "#{versionedSourceFolder}/#{file}" if file.indexOf('/') is -1
|
||||
file = "#{siteSourceFolder}/#{file}" unless '/' in file
|
||||
output = fs.readFileSync file, 'utf-8'
|
||||
if /\.html$/.test(file)
|
||||
render = _.template output
|
||||
@@ -249,6 +272,7 @@ buildDocs = (watch = no) ->
|
||||
htmlFor: htmlFor()
|
||||
codeFor: codeFor()
|
||||
include: include()
|
||||
includeScript: includeScript()
|
||||
output
|
||||
|
||||
# Task
|
||||
@@ -263,7 +287,7 @@ buildDocs = (watch = no) ->
|
||||
catch exception
|
||||
|
||||
if watch
|
||||
for target in [indexFile, versionedSourceFolder, examplesSourceFolder, sectionsSourceFolder]
|
||||
for target in [indexFile, siteSourceFolder, examplesSourceFolder, sectionsSourceFolder, changelogSourceFolder]
|
||||
fs.watch target, interval: 200, renderIndex
|
||||
log 'watching...', green
|
||||
|
||||
@@ -276,9 +300,9 @@ task 'doc:site:watch', 'watch and continually rebuild the documentation for the
|
||||
|
||||
buildDocTests = (watch = no) ->
|
||||
# Constants
|
||||
testFile = 'documentation/test.html'
|
||||
testFile = 'documentation/site/test.html'
|
||||
testsSourceFolder = 'test'
|
||||
outputFolder = "docs/v#{majorVersion}"
|
||||
outputFolder = "docs/v#{majorVersion}"
|
||||
|
||||
# Included in test.html
|
||||
testHelpers = fs.readFileSync('test/support/helpers.coffee', 'utf-8').replace /exports\./g, '@'
|
||||
@@ -326,7 +350,7 @@ task 'doc:test:watch', 'watch and continually rebuild the browser-based tests',
|
||||
|
||||
buildAnnotatedSource = (watch = no) ->
|
||||
do generateAnnotatedSource = ->
|
||||
exec "node_modules/docco/bin/docco src/*.*coffee --output docs/v#{majorVersion}/annotated-source", (err) -> throw err if err
|
||||
exec "cd src && ../node_modules/docco/bin/docco *.*coffee --output ../docs/v#{majorVersion}/annotated-source", (err) -> throw err if err
|
||||
log 'generated', green, "annotated source in docs/v#{majorVersion}/annotated-source/"
|
||||
|
||||
if watch
|
||||
@@ -344,11 +368,13 @@ task 'release', 'build and test the CoffeeScript source, and build the documenta
|
||||
execSync '''
|
||||
cake build:full
|
||||
cake build:browser
|
||||
cake doc:test
|
||||
cake test:browser:node
|
||||
cake test:browser
|
||||
cake test:integrations
|
||||
cake doc:site
|
||||
cake doc:test
|
||||
cake doc:source''', stdio: 'inherit'
|
||||
cake doc:source
|
||||
''', stdio: 'inherit'
|
||||
|
||||
|
||||
task 'bench', 'quick benchmark of compilation time', ->
|
||||
@@ -419,12 +445,6 @@ runTests = (CoffeeScript) ->
|
||||
catch err
|
||||
onFail description, fn, err
|
||||
|
||||
global.supportsAsync = try
|
||||
new Function('async () => {}')()
|
||||
yes
|
||||
catch
|
||||
no
|
||||
|
||||
helpers.extend global, require './test/support/helpers'
|
||||
|
||||
# When all the tests have run, collect and print errors.
|
||||
@@ -442,10 +462,22 @@ runTests = (CoffeeScript) ->
|
||||
console.log " #{source}" if source
|
||||
return
|
||||
|
||||
# Run every test in the `test` folder, recording failures.
|
||||
files = fs.readdirSync 'test'
|
||||
unless global.supportsAsync # Except for async tests, if async isn’t supported.
|
||||
files = files.filter (filename) -> filename isnt 'async.coffee'
|
||||
# Run every test in the `test` folder, recording failures, except for files
|
||||
# we’re skipping because the features to be tested are unsupported in the
|
||||
# current Node runtime.
|
||||
testFilesToSkip = []
|
||||
skipUnless = (featureDetect, filenames) ->
|
||||
unless (try new Function featureDetect)
|
||||
testFilesToSkip = testFilesToSkip.concat filenames
|
||||
skipUnless 'async () => {}', ['async.coffee', 'async_iterators.coffee']
|
||||
skipUnless 'async function* generator() { yield 42; }', ['async_iterators.coffee']
|
||||
skipUnless 'var a = 2 ** 2; a **= 3', ['exponentiation.coffee']
|
||||
skipUnless 'var {...a} = {}', ['object_rest_spread.coffee']
|
||||
skipUnless '/foo.bar/s.test("foo\tbar")', ['regex_dotall.coffee']
|
||||
skipUnless '1_2_3', ['numeric_literal_separators.coffee']
|
||||
skipUnless '1n', ['numbers_bigint.coffee']
|
||||
files = fs.readdirSync('test').filter (filename) ->
|
||||
filename not in testFilesToSkip
|
||||
|
||||
startTime = Date.now()
|
||||
for file in files when helpers.isCoffee file
|
||||
@@ -465,8 +497,66 @@ task 'test', 'run the CoffeeScript language test suite', ->
|
||||
runTests(CoffeeScript).catch -> process.exit 1
|
||||
|
||||
|
||||
task 'test:browser', 'run the test suite against the merged browser script', ->
|
||||
source = fs.readFileSync "docs/v#{majorVersion}/browser-compiler/coffeescript.js", 'utf-8'
|
||||
task 'test:browser', 'run the test suite against the modern browser compiler in a headless browser', ->
|
||||
# This test uses Puppeteer to launch headless Chrome to test the ES module
|
||||
# version of the browser compiler. There’s no reason to run this test in old
|
||||
# versions of Node (the runtime is the headless Chrome browser, not Node),
|
||||
# and Puppeteer 3 only supports Node >= 10.18.1, so limit this test to those
|
||||
# versions. The code below uses `Promise.prototype.finally` because the
|
||||
# CoffeeScript codebase currently maintains compatibility with Node 6, which
|
||||
# did not support `async`/`await` syntax. Even though this test doesn’t run
|
||||
# in Node 6, it needs to still _parse_ in Node 6 so that this file can load.
|
||||
[major, minor, build] = process.versions.node.split('.').map (n) -> parseInt(n, 10)
|
||||
return if major < 10 or (major is 10 and minor < 18) or (major is 10 and minor is 18 and build < 1)
|
||||
|
||||
# Create very simple web server to serve the two files we need.
|
||||
http = require 'http'
|
||||
serveFile = (res, fileToServe, mimeType) ->
|
||||
res.statusCode = 200
|
||||
res.setHeader 'Content-Type', mimeType
|
||||
fs.createReadStream(fileToServe).pipe res
|
||||
server = http.createServer (req, res) ->
|
||||
if req.url is '/'
|
||||
serveFile res, path.join(__dirname, 'docs', "v#{majorVersion}", 'test.html'), 'text/html'
|
||||
else if req.url is '/browser-compiler-modern/coffeescript.js'
|
||||
# The `text/javascript` MIME type is required for an ES module file to be
|
||||
# loaded in a browser.
|
||||
serveFile res, path.join(__dirname, 'docs', "v#{majorVersion}", 'browser-compiler-modern', 'coffeescript.js'), 'text/javascript'
|
||||
else
|
||||
res.statusCode = 404
|
||||
res.end()
|
||||
server.listen 8080
|
||||
|
||||
puppeteer = require 'puppeteer'
|
||||
browser = page = result = null
|
||||
puppeteer.launch()
|
||||
.then((browserHandle) ->
|
||||
browser = browserHandle
|
||||
browser.newPage()
|
||||
).then((pageHandle) ->
|
||||
page = pageHandle
|
||||
page.goto 'http://localhost:8080/'
|
||||
).then(->
|
||||
page.waitForSelector '#result',
|
||||
visible: yes
|
||||
polling: 'mutation'
|
||||
).then((element) ->
|
||||
page.evaluate ((el) => el.textContent), element
|
||||
).then((elementText) ->
|
||||
result = elementText
|
||||
).finally(->
|
||||
browser.close()
|
||||
).finally ->
|
||||
server.close()
|
||||
if result and not result.includes('failed')
|
||||
log result, green
|
||||
else
|
||||
log result, red
|
||||
process.exit 1
|
||||
|
||||
|
||||
task 'test:browser:node', 'run the test suite against the legacy browser compiler in Node', ->
|
||||
source = fs.readFileSync "lib/coffeescript-browser-compiler-legacy/coffeescript.js", 'utf-8'
|
||||
result = {}
|
||||
global.testingBrowser = yes
|
||||
(-> eval source).call result
|
||||
@@ -480,21 +570,35 @@ task 'test:integrations', 'test the module integrated with other libraries and e
|
||||
# can be built by such tools; if such a build succeeds, it verifies that no
|
||||
# Node modules are required as part of the compiler (as opposed to the tests)
|
||||
# and that therefore the compiler will run in a browser environment.
|
||||
# Webpack 5 requires Node >= 10.13.0.
|
||||
[major, minor] = process.versions.node.split('.').map (n) -> parseInt(n, 10)
|
||||
return if major < 10 or (major is 10 and minor < 13)
|
||||
tmpdir = os.tmpdir()
|
||||
try
|
||||
buildLog = execSync "./node_modules/webpack/bin/webpack.js
|
||||
--entry=./
|
||||
--output-library=CoffeeScript
|
||||
--output-library-target=commonjs2
|
||||
--output-path=#{tmpdir}
|
||||
--output-filename=coffeescript.js"
|
||||
catch exception
|
||||
console.error buildLog.toString()
|
||||
throw exception
|
||||
webpack = require 'webpack'
|
||||
webpack {
|
||||
entry: './'
|
||||
optimization:
|
||||
# Webpack’s minification causes the CoffeeScript module to fail some tests.
|
||||
minimize: off
|
||||
output:
|
||||
path: tmpdir
|
||||
filename: 'coffeescript.js'
|
||||
library: 'CoffeeScript'
|
||||
libraryTarget: 'commonjs2'
|
||||
}, (err, stats) ->
|
||||
if err or stats.hasErrors()
|
||||
if err
|
||||
console.error err.stack or err
|
||||
console.error err.details if err.details
|
||||
if stats.hasErrors()
|
||||
console.error error for error in stats.compilation.errors
|
||||
if stats.hasWarnings()
|
||||
console.warn warning for warning in stats.compilation.warnings
|
||||
process.exit 1
|
||||
|
||||
builtCompiler = path.join tmpdir, 'coffeescript.js'
|
||||
CoffeeScript = require builtCompiler
|
||||
global.testingBrowser = yes
|
||||
testResults = runTests CoffeeScript
|
||||
fs.unlinkSync builtCompiler
|
||||
process.exit 1 unless testResults
|
||||
builtCompiler = path.join tmpdir, 'coffeescript.js'
|
||||
{ CoffeeScript } = require builtCompiler
|
||||
global.testingBrowser = yes
|
||||
testResults = runTests CoffeeScript
|
||||
fs.unlinkSync builtCompiler
|
||||
process.exit 1 unless testResults
|
||||
|
||||
62
ISSUE_TEMPLATE.md
Normal file
62
ISSUE_TEMPLATE.md
Normal file
@@ -0,0 +1,62 @@
|
||||
<!---
|
||||
Thanks for filing an issue 😄! Before you submit, please read the following:
|
||||
|
||||
Search open/closed issues before submitting since someone might have asked the same thing before!
|
||||
Our issues history stretches back to 2009, so the odds are good that your topic has come up.
|
||||
|
||||
If you have a support request or question please use Stack Overflow:
|
||||
https://stackoverflow.com/questions/tagged/coffeescript
|
||||
|
||||
Issues on GitHub are only related to problems of the CoffeeScript compiler itself and we cannot answer
|
||||
support questions here.
|
||||
-->
|
||||
|
||||
Choose one: is this a bug report or feature request?
|
||||
|
||||
<!---
|
||||
Provide a general summary of the issue in the title above.
|
||||
|
||||
For bugs, please also preface your title with “Bug:”. For feature requests, please preface your title
|
||||
with “Proposal:”. Once your issue is reviewed, a maintainer will edit the title to refer to the part
|
||||
of the codebase most relevant to the issue (if applicable).
|
||||
|
||||
If your request is that CoffeeScript support a new feature recently arrived to JavaScript, please note
|
||||
that we generally only add features that have reached Stage 4 in the specification (in other words,
|
||||
the syntax is finalized and the feature is approved to be part of the next ES release). You can still
|
||||
open an issue, but it will likely be tagged with “[Awaiting Stage 4]” until the relevant ES feature is
|
||||
approved for release. See https://coffeescript.org/#contributing
|
||||
|
||||
There are also a handful of JavaScript features that CoffeeScript intentionally does not support.
|
||||
Please do not open issues regarding these. They’re listed in https://coffeescript.org/#unsupported
|
||||
-->
|
||||
|
||||
### Input Code
|
||||
<!--- If you're describing a bug, please let us know which sample code reproduces your problem. -->
|
||||
<!--- If you have link from https://coffeescript.org/#try or a standalone repo please include that! -->
|
||||
|
||||
```coffee
|
||||
your (code) => here
|
||||
```
|
||||
|
||||
### Expected Behavior
|
||||
<!--- If you’re describing a bug, tell us what should happen. -->
|
||||
<!--- If you’re suggesting a change/improvement, tell us how it should work. -->
|
||||
|
||||
### Current Behavior
|
||||
<!--- If describing a bug, tell us what happens instead of the expected behavior. -->
|
||||
<!--- If suggesting a change/improvement, explain the difference from current behavior. -->
|
||||
|
||||
### Possible Solution
|
||||
<!--- Not obligatory, but suggest a fix/reason for the bug, -->
|
||||
<!--- or ideas how to implement the addition or change. -->
|
||||
|
||||
### Context
|
||||
<!--- How has this issue affected you? What are you trying to accomplish? -->
|
||||
<!--- Providing context helps us come up with a solution that is most useful in the real world. -->
|
||||
|
||||
### Environment
|
||||
<!--- For bugs, please let us know what version of CoffeeScript you’re running: `coffee -v`. -->
|
||||
<!--- If you think it might be relevant, please also let us know your version of Node. -->
|
||||
|
||||
* CoffeeScript version:
|
||||
* Node.js version:
|
||||
2
LICENSE
2
LICENSE
@@ -1,4 +1,4 @@
|
||||
Copyright (c) 2009-2017 Jeremy Ashkenas
|
||||
Copyright (c) 2009-2018 Jeremy Ashkenas
|
||||
|
||||
Permission is hereby granted, free of charge, to any person
|
||||
obtaining a copy of this software and associated documentation
|
||||
|
||||
22
PULL_REQUEST_TEMPLATE.md
Normal file
22
PULL_REQUEST_TEMPLATE.md
Normal file
@@ -0,0 +1,22 @@
|
||||
<!--
|
||||
Before making a PR please make sure to read our contributing guidelines:
|
||||
https://coffeescript.org/#contributing
|
||||
|
||||
For issue references: Add a comma-separated list of a
|
||||
[closing word](https://help.github.com/articles/closing-issues-via-commit-messages/) followed by
|
||||
the ticket number fixed by the PR. It should be underlined in the preview if done correctly.
|
||||
|
||||
All new features require tests. All but the most trivial bug fixes should also have new or updated tests.
|
||||
|
||||
Ensure that all new code you add to the compiler can be run in the minimum version of Node listed in
|
||||
`package.json`. New tests can require newer Node runtimes, but you may need to ensure that such tests
|
||||
only run in supported runtimes; see `Cakefile` for examples of how to filter out certain tests in
|
||||
runtimes that don’t support them.
|
||||
|
||||
Please follow the code style of the rest of the CoffeeScript codebase. Write comments in complete
|
||||
sentences using Markdown, as the comments become the [annotated source](https://coffeescript.org/#annotated-source).
|
||||
For tests proving a bug is fixed, please mention the issue number in the test description (see examples
|
||||
in the codebase).
|
||||
|
||||
Describe your changes below in as much detail as possible.
|
||||
-->
|
||||
55
README.md
55
README.md
@@ -1,22 +1,29 @@
|
||||
{
|
||||
} } {
|
||||
{ { } }
|
||||
} }{ {
|
||||
{ }{ } } _____ __ __
|
||||
{ }{ }{ { } / ____| / _|/ _|
|
||||
.- { { } { }} -. | | ___ | |_| |_ ___ ___
|
||||
( { } { } { } } ) | | / _ \| _| _/ _ \/ _ \
|
||||
|`-..________ ..-'| | |___| (_) | | | || __/ __/
|
||||
| | \_____\___/|_| |_| \___|\___|
|
||||
| ;--.
|
||||
| (__ \ _____ _ _
|
||||
| | ) ) / ____| (_) | |
|
||||
| |/ / | (___ ___ _ __ _ _ __ | |_
|
||||
| ( / \___ \ / __| '__| | '_ \| __|
|
||||
| |/ ____) | (__| | | | |_) | |_
|
||||
| | |_____/ \___|_| |_| .__/ \__|
|
||||
`-.._________..-' | |
|
||||
|_|
|
||||
```
|
||||
@@@@@@@ @@@@ @@@@@
|
||||
@@@@@@@@@@ @@@ @@@ {
|
||||
@@@@ @@ @@@ @@@ } } {
|
||||
@@@@ @@@@@@@ @@@ @@@ @@@@@@ @@@@@@ { { } }
|
||||
@@@@ @@@ @@ @@@@@ @@@@@@ @@@ @@ @@@@ @@ } }{ {
|
||||
@@@@ @@@@ @@ @@@ @@@ @@@ @@@ @@@ @@@ { }{ } }
|
||||
@@@@ @@@@ @@ @@@ @@@ @@@@@@@@ @@@@@@@@ { }{ }{ { }
|
||||
@@@@@ @@@@ @@ @@@ @@@ @@@ @@@ { { } { } { } }
|
||||
@@@@@@@@@@ @@@@@@@@ @@@ @@@ @@@@@@@@ @@@@@@@@ { } { } { }
|
||||
@@@@@ @@@ @@@ @@@@@ @@@@@ @@@@@@ { } { } @@@@@@@
|
||||
@@@ @@@ @@@@@@@@@@@@@@@@@@@@@@@@@@@@
|
||||
@@@@@@ @@@ @@@ @@ @@@@@@@@@@@@@@@@@@@@@@@@@@
|
||||
@@@@ @@ @@@ @@@@ @@ @@@@@@@@@@@@@@@@@@@@@@@@
|
||||
@@@@ @@@ @@ @@@@ @@@ @@@@@@@@@@@@@@@@@@@@@
|
||||
@@@@@ @@@@@ @@ @@ @@@ @@@@@@@ @@@@@ @@@ @@@@@@@@@@@@@@@@@@
|
||||
@@@@@ @@@ @@@ @@@@@@@@ @@@@ @@@@ @@@@@@@ @@@ @@@@@@@@@@@@@@@@
|
||||
@@@@@ @@@ @@@@ @@@@ @@@ @@@ @@@ @@@@@@@@@@@@@@
|
||||
@@@@@ @@@@ @@@@ @@@@ @@@@ @@@@ @@@@ @@@@
|
||||
@@@ @@@@ @@@ @@@@ @@@@ @@@ @@@@ @@@@
|
||||
@@@ @@@@ @@@@ @@@@ @@@@ @@@@ @@@@ @@@@
|
||||
@@@@@@@@@ @@@@@@ @@@@ @@@@ @@@@@@@@@ @@@@
|
||||
@@@ @@@@
|
||||
@@@
|
||||
@@@
|
||||
```
|
||||
|
||||
CoffeeScript is a little language that compiles into JavaScript.
|
||||
|
||||
@@ -25,11 +32,13 @@ CoffeeScript is a little language that compiles into JavaScript.
|
||||
Once you have Node.js installed:
|
||||
|
||||
```shell
|
||||
# Install locally for a project:
|
||||
npm install --save-dev coffeescript
|
||||
|
||||
# Install globally to execute .coffee files anywhere:
|
||||
npm install --global coffeescript
|
||||
```
|
||||
|
||||
Leave off the `--global` if you don’t wish to install globally.
|
||||
|
||||
## Getting Started
|
||||
|
||||
Execute a script:
|
||||
@@ -44,7 +53,7 @@ Compile a script:
|
||||
coffee -c /path/to/script.coffee
|
||||
```
|
||||
|
||||
For documentation, usage, and examples, see: http://coffeescript.org/
|
||||
For documentation, usage, and examples, see: https://coffeescript.org/
|
||||
|
||||
To suggest a feature or report a bug: https://github.com/jashkenas/coffeescript/issues
|
||||
|
||||
@@ -52,6 +61,6 @@ If you’d like to chat, drop by #coffeescript on Freenode IRC.
|
||||
|
||||
The source repository: https://github.com/jashkenas/coffeescript.git
|
||||
|
||||
Changelog: http://coffeescript.org/#changelog
|
||||
Changelog: https://coffeescript.org/#changelog
|
||||
|
||||
Our lovely and talented contributors are listed here: https://github.com/jashkenas/coffeescript/contributors
|
||||
|
||||
7
bin/cake
7
bin/cake
@@ -1,5 +1,12 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
try {
|
||||
new Function('var {a} = {a: 1}')();
|
||||
} catch (error) {
|
||||
console.error('Your JavaScript runtime does not support some features used by the cake command. Please use Node 6 or later.');
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
var path = require('path');
|
||||
var fs = require('fs');
|
||||
|
||||
|
||||
@@ -1,5 +1,12 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
try {
|
||||
new Function('var {a} = {a: 1}')();
|
||||
} catch (error) {
|
||||
console.error('Your JavaScript runtime does not support some features used by the coffee command. Please use Node 6 or later.');
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
var path = require('path');
|
||||
var fs = require('fs');
|
||||
|
||||
|
||||
@@ -1 +1 @@
|
||||
coffeescript.org
|
||||
coffeescript.org
|
||||
1
docs/annotated-source
Symbolic link
1
docs/annotated-source
Symbolic link
@@ -0,0 +1 @@
|
||||
v2/annotated-source
|
||||
1
docs/announcing-coffeescript-2
Symbolic link
1
docs/announcing-coffeescript-2
Symbolic link
@@ -0,0 +1 @@
|
||||
v2/announcing-coffeescript-2
|
||||
1
docs/browser-compiler
Symbolic link
1
docs/browser-compiler
Symbolic link
@@ -0,0 +1 @@
|
||||
v2/browser-compiler-legacy
|
||||
1
docs/browser-compiler-legacy
Symbolic link
1
docs/browser-compiler-legacy
Symbolic link
@@ -0,0 +1 @@
|
||||
v2/browser-compiler-legacy
|
||||
1
docs/browser-compiler-modern
Symbolic link
1
docs/browser-compiler-modern
Symbolic link
@@ -0,0 +1 @@
|
||||
v2/browser-compiler-modern
|
||||
@@ -1 +1 @@
|
||||
v1/index.html
|
||||
v2/index.html
|
||||
@@ -1,5 +1,6 @@
|
||||
{
|
||||
"name": "",
|
||||
"name": "CoffeeScript",
|
||||
"description": "Unfancy JavaScript",
|
||||
"icons": [
|
||||
{
|
||||
"src": "\/android-chrome-192x192.png",
|
||||
|
||||
1
docs/test.html
Symbolic link
1
docs/test.html
Symbolic link
@@ -0,0 +1 @@
|
||||
v2/test.html
|
||||
@@ -555,7 +555,8 @@ pre .xml .cdata {
|
||||
<a href="#destructuring">Destructuring Assignment</a>
|
||||
<a href="#fat-arrow">Bound and Generator Functions</a>
|
||||
<a href="#embedded">Embedded JavaScript</a>
|
||||
<a href="#switch">Switch and Try/Catch</a>
|
||||
<a href="#switch">Switch/When/Else</a>
|
||||
<a href="#try-catch">Try/Catch/Finally</a>
|
||||
<a href="#comparisons">Chained Comparisons</a>
|
||||
<a href="#strings">String Interpolation, Block Strings, and Block Comments</a>
|
||||
<a href="#tagged-template-literals">Tagged Template Literals</a>
|
||||
@@ -594,18 +595,18 @@ pre .xml .cdata {
|
||||
Annotated Source
|
||||
</div>
|
||||
<div class="contents menu">
|
||||
<a href="/v1/annotated-source/grammar.html">Grammar Rules — src/grammar</a>
|
||||
<a href="/v1/annotated-source/lexer.html">Lexing Tokens — src/lexer</a>
|
||||
<a href="/v1/annotated-source/rewriter.html">The Rewriter — src/rewriter</a>
|
||||
<a href="/v1/annotated-source/nodes.html">The Syntax Tree — src/nodes</a>
|
||||
<a href="/v1/annotated-source/scope.html">Lexical Scope — src/scope</a>
|
||||
<a href="/v1/annotated-source/helpers.html">Helpers & Utility Functions — src/helpers</a>
|
||||
<a href="/v1/annotated-source/coffee-script.html">The CoffeeScript Module — src/coffee-script</a>
|
||||
<a href="/v1/annotated-source/cake.html">Cake & Cakefiles — src/cake</a>
|
||||
<a href="/v1/annotated-source/command.html">“coffee” Command-Line Utility — src/command</a>
|
||||
<a href="/v1/annotated-source/optparse.html">Option Parsing — src/optparse</a>
|
||||
<a href="/v1/annotated-source/repl.html">Interactive REPL — src/repl</a>
|
||||
<a href="/v1/annotated-source/sourcemap.html">Source Maps — src/sourcemap</a>
|
||||
<a href="annotated-source/grammar.html">Grammar Rules — src/grammar</a>
|
||||
<a href="annotated-source/lexer.html">Lexing Tokens — src/lexer</a>
|
||||
<a href="annotated-source/rewriter.html">The Rewriter — src/rewriter</a>
|
||||
<a href="annotated-source/nodes.html">The Syntax Tree — src/nodes</a>
|
||||
<a href="annotated-source/scope.html">Lexical Scope — src/scope</a>
|
||||
<a href="annotated-source/helpers.html">Helpers & Utility Functions — src/helpers</a>
|
||||
<a href="annotated-source/coffee-script.html">The CoffeeScript Module — src/coffee-script</a>
|
||||
<a href="annotated-source/cake.html">Cake & Cakefiles — src/cake</a>
|
||||
<a href="annotated-source/command.html">“coffee” Command-Line Utility — src/command</a>
|
||||
<a href="annotated-source/optparse.html">Option Parsing — src/optparse</a>
|
||||
<a href="annotated-source/repl.html">Interactive REPL — src/repl</a>
|
||||
<a href="annotated-source/sourcemap.html">Source Maps — src/sourcemap</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -615,10 +616,10 @@ pre .xml .cdata {
|
||||
<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>The CoffeeScript compiler goes to great lengths to generate output JavaScript that runs in every JavaScript runtime, but there are exceptions. Use <a href="#generator-functions">generator functions</a>, <a href="#generator-iteration"><code>for…from</code></a>, or <a href="#tagged-template-literals">tagged template literals</a> only if you know that your <a href="http://kangax.github.io/compat-table/es6/">target runtimes can support them</a>. If you use <a href="#modules">modules</a>, you will need to <a href="#modules-note">use an additional tool to resolve them</a>.</p>
|
||||
<p><strong>Latest Version:</strong> <a href="https://github.com/jashkenas/coffeescript/tarball/1.12.7">1.12.7</a></p>
|
||||
<p><strong>Latest 1.x Version:</strong> <a href="https://github.com/jashkenas/coffeescript/tarball/1.12.7">1.12.7</a></p>
|
||||
<blockquote class="uneditable-code-block"><pre><code class="language-bash">npm install -g coffeescript
|
||||
</code></pre>
|
||||
</blockquote><p><strong>CoffeeScript 2 is coming!</strong> It adds support for <a href="/v2/#classes">ES2015 classes</a>, <a href="/v2/#fat-arrow"><code>async</code>/<code>await</code></a>, <a href="/v2/#jsx">JSX</a>, <span class="nowrap"><a href="/v2/#splats">object rest/spread syntax</a></span>, and JavaScript generated using ES2015+ syntax. <a href="/v2/">Learn more</a>.</p>
|
||||
</blockquote><p><strong>Upgrade to CoffeeScript 2!</strong> It adds support for <a href="/#classes">ES2015 classes</a>, <a href="/#async-functions"><code>async</code>/<code>await</code></a>, <a href="/#jsx">JSX</a>, <span class="nowrap"><a href="/#splats">object rest/spread syntax</a></span>, and <a href="/#coffeescript-2">JavaScript generated using modern syntax</a>. <a href="/announcing-coffeescript-2/">Learn more</a>.</p>
|
||||
|
||||
<h2>Overview</h2>
|
||||
<p><em>CoffeeScript on the left, compiled JavaScript output on the right.</em></p>
|
||||
@@ -741,7 +742,7 @@ cubes = (function() {
|
||||
;alert(cubes);">run: cubes</div><br class='clear' /></div>
|
||||
<span class="bookmark" id="installation"></span>
|
||||
<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="/v1/browser-compiler/coffee-script.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. The <a href="browser-compiler/coffee-script.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>
|
||||
@@ -853,7 +854,7 @@ cubes = (function() {
|
||||
<h2>Language Reference</h2>
|
||||
<p><em>This reference is structured so that it can be read from top to bottom, if you like. Later sections use ideas and syntax previously introduced. Familiarity with JavaScript is assumed. In all of the following examples, the source CoffeeScript is provided on the left, and the direct compilation into JavaScript is on the right.</em></p>
|
||||
<p><em>Many of the examples can be run (where it makes sense) by pressing the <strong>run</strong> button on the right, and can be loaded into the “Try CoffeeScript” console by pressing the <strong>load</strong> button on the left.</em></p>
|
||||
<p>First, the basics: CoffeeScript uses significant whitespace to delimit blocks of code. You don’t need to use semicolons <code>;</code> to terminate expressions, ending the line will do just as well (although semicolons can still be used to fit multiple expressions onto a single line). Instead of using curly braces <code>{ }</code> to surround blocks of code in <a href="#literals">functions</a>, <a href="#conditionals">if-statements</a>, <a href="#switch">switch</a>, and <a href="#try">try/catch</a>, use indentation.</p>
|
||||
<p>First, the basics: CoffeeScript uses significant whitespace to delimit blocks of code. You don’t need to use semicolons <code>;</code> to terminate expressions, ending the line will do just as well (although semicolons can still be used to fit multiple expressions onto a single line). Instead of using curly braces <code>{ }</code> to surround blocks of code in <a href="#literals">functions</a>, <a href="#conditionals">if-statements</a>, <a href="#switch">switch</a>, and <a href="#try-catch">try/catch</a>, use indentation.</p>
|
||||
<p>You don’t need to use parentheses to invoke a function if you’re passing arguments. The implicit call wraps forward to the end of the line or block expression.<br>
|
||||
<code>console.log sys.inspect object</code> → <code>console.log(sys.inspect(object));</code></p>
|
||||
|
||||
@@ -2441,7 +2442,7 @@ task(<span class="string">'build:parser'</span>, <span class="string">'rebuild t
|
||||
dir = options.output || <span class="string">'lib'</span>;
|
||||
<span class="keyword">return</span> fs.writeFile(dir + <span class="string">"/parser.js"</span>, code);
|
||||
});
|
||||
</code></pre><script>window.example1 = "fs = require 'fs'\n\noption '-o', '--output [DIR]', 'directory for compiled code'\n\ntask 'build:parser', 'rebuild the Jison parser', (options) ->\n require 'jison'\n code = require('./lib/grammar').parser.generate()\n dir = options.output or 'lib'\n fs.writeFile \"#{dir}/parser.js\", code\n"</script><div class='minibutton load' onclick='javascript: loadConsole(example1);'>load</div><br class='clear' /></div><p>If you need to invoke one task before another — for example, running <code>build</code> before <code>test</code>, you can use the <code>invoke</code> function: <code>invoke 'build'</code>. Cake tasks are a minimal way to expose your CoffeeScript functions to the command line, so <a href="/v1/annotated-source/cake.html">don’t expect any fanciness built-in</a>. If you need dependencies, or async callbacks, it’s best to put them in your code itself — not the cake task.</p>
|
||||
</code></pre><script>window.example1 = "fs = require 'fs'\n\noption '-o', '--output [DIR]', 'directory for compiled code'\n\ntask 'build:parser', 'rebuild the Jison parser', (options) ->\n require 'jison'\n code = require('./lib/grammar').parser.generate()\n dir = options.output or 'lib'\n fs.writeFile \"#{dir}/parser.js\", code\n"</script><div class='minibutton load' onclick='javascript: loadConsole(example1);'>load</div><br class='clear' /></div><p>If you need to invoke one task before another — for example, running <code>build</code> before <code>test</code>, you can use the <code>invoke</code> function: <code>invoke 'build'</code>. Cake tasks are a minimal way to expose your CoffeeScript functions to the command line, so <a href="annotated-source/cake.html">don’t expect any fanciness built-in</a>. If you need dependencies, or async callbacks, it’s best to put them in your code itself — not the cake task.</p>
|
||||
|
||||
<span class="bookmark" id="source-maps"></span>
|
||||
<h2>Source Maps</h2>
|
||||
@@ -2450,7 +2451,7 @@ task(<span class="string">'build:parser'</span>, <span class="string">'rebuild t
|
||||
|
||||
<span class="bookmark" id="scripts"></span>
|
||||
<h2>“text/coffeescript” Script Tags</h2>
|
||||
<p>While it’s not recommended for serious use, CoffeeScripts may be included directly within the browser using <code><script type="text/coffeescript"></code> tags. The source includes a compressed and minified version of the compiler (<a href="/v1/browser-compiler/coffee-script.js">Download current version here, 51k when gzipped</a>) as <code>v1/browser-compiler/coffee-script.js</code>. Include this file on a page with inline CoffeeScript tags, and it will compile and evaluate them in order.</p>
|
||||
<p>While it’s not recommended for serious use, CoffeeScripts may be included directly within the browser using <code><script type="text/coffeescript"></code> tags. The source includes a compressed and minified version of the compiler (<a href="browser-compiler/coffee-script.js">Download current version here, 51k when gzipped</a>) as <code>docs/v1/browser-compiler/coffee-script.js</code>. Include this file on a page with inline CoffeeScript tags, and it will compile and evaluate them in order.</p>
|
||||
<p>In fact, the little bit of glue script that runs “Try CoffeeScript” above, as well as the jQuery for the menu, is implemented in just this way. View source and look at the bottom of the page to see the example. Including the script also gives you access to <code>CoffeeScript.compile()</code> so you can pop open Firebug and try compiling some strings.</p>
|
||||
<p>The usual caveats about CoffeeScript apply — your inline scripts will run within a closure wrapper, so if you want to expose global variables or functions, attach them to the <code>window</code> object.</p>
|
||||
|
||||
@@ -2501,7 +2502,7 @@ Use <code>bin/coffee</code> to test your changes,<br>
|
||||
<p><code>git checkout lib && bin/cake build:full</code> is a good command to run when you’re working on the core language. It’ll refresh the <code>lib</code> folder (in case you broke something), build your altered compiler, use that to rebuild itself (a good sanity test) and then run all of the tests. If they pass, there’s a good chance you’ve made a successful change.</p>
|
||||
</li>
|
||||
<li>
|
||||
<p><a href="/v1/test.html">Browser Tests</a><br>
|
||||
<p><a href="test.html">Browser Tests</a><br>
|
||||
Run CoffeeScript’s test suite in your current browser.</p>
|
||||
</li>
|
||||
<li>
|
||||
@@ -2592,7 +2593,7 @@ The CoffeeScript logo is available in SVG for use in presentations.</p>
|
||||
<li>The browser compiler can once again be built unminified via <code>MINIFY=false cake build:browser</code>.</li>
|
||||
<li>The error-prone patched version of <code>Error.prepareStackTrace</code> has been removed.</li>
|
||||
<li>Command completion in the REPL (pressing tab to get suggestions) has been fixed for Node 6.9.1+.</li>
|
||||
<li>The <a href="/v1/test.html">browser-based tests</a> now include all the tests as the Node-based version.</li>
|
||||
<li>The <a href="test.html">browser-based tests</a> now include all the tests as the Node-based version.</li>
|
||||
</ul>
|
||||
<div class="anchor" id="1.12.1"></div>
|
||||
<h2 class="header">
|
||||
@@ -2611,7 +2612,7 @@ The CoffeeScript logo is available in SVG for use in presentations.</p>
|
||||
<li>CoffeeScript now provides a <a href="#generator-iteration"><code>for…from</code></a> syntax for outputting ES2015 <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for...of"><code>for…of</code></a>. (Sorry they couldn’t match, but we came up with <code>for…of</code> first for something else.) This allows iterating over generators or any other iterable object. Note that using <code>for…from</code> in your code makes you responsible for ensuring that either your runtime supports <code>for…of</code> or that you transpile the output JavaScript further to a version your target runtime(s) support.</li>
|
||||
<li>Triple backticks (<code>```</code>) allow the creation of embedded JavaScript blocks where escaping single backticks is not required, which should improve interoperability with ES2015 template literals and with Markdown.</li>
|
||||
<li>Within single-backtick embedded JavaScript, backticks can now be escaped via <code>\`</code>.</li>
|
||||
<li>The browser tests now run in the browser again, and are accessible <a href="/v1/test.html">here</a> if you would like to test your browser.</li>
|
||||
<li>The browser tests now run in the browser again, and are accessible <a href="test.html">here</a> if you would like to test your browser.</li>
|
||||
<li>CoffeeScript-only keywords in ES2015 <code>import</code>s and <code>export</code>s are now ignored.</li>
|
||||
<li>The compiler now throws an error on trying to export an anonymous class.</li>
|
||||
<li>Bugfixes related to tokens and location data, for better source maps and improved compatibility with downstream tools.</li>
|
||||
@@ -3016,7 +3017,7 @@ used to parse as <code>result = (i for i in list)</code> by default … it now p
|
||||
<a href="https://github.com/jashkenas/coffeescript/compare/0.5.1...0.5.2">0.5.2</a>
|
||||
<span class="timestamp"> — <time datetime="2010-02-25">February 25, 2010</time></span>
|
||||
</h2><p>Added a compressed version of the compiler for inclusion in web pages as
|
||||
<code>/v1/browser-compiler/coffee-script.js</code>. It’ll automatically run any script tags with type <code>text/coffeescript</code> for you. Added a <code>--stdio</code> option to the <code>coffee</code> command, for piped-in compiles.</p>
|
||||
<code>browser-compiler/coffee-script.js</code>. It’ll automatically run any script tags with type <code>text/coffeescript</code> for you. Added a <code>--stdio</code> option to the <code>coffee</code> command, for piped-in compiles.</p>
|
||||
<div class="anchor" id="0.5.1"></div>
|
||||
<h2 class="header">
|
||||
<a href="https://github.com/jashkenas/coffeescript/compare/0.5.0...0.5.1">0.5.1</a>
|
||||
@@ -3222,7 +3223,7 @@ compileSource()
|
||||
</script>
|
||||
|
||||
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
|
||||
<script src="v1/browser-compiler/coffee-script.js"></script>
|
||||
<script src="browser-compiler/coffee-script.js"></script>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -112,8 +112,8 @@
|
||||
<li id="section-1">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-1">¶</a>
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-1">§</a>
|
||||
</div>
|
||||
<p>This <strong>Browser</strong> compatibility layer extends core CoffeeScript functions
|
||||
to make things work smoothly when compiling code directly in the browser.
|
||||
@@ -123,8 +123,8 @@ We add support for loading remote Coffee scripts via <strong>XHR</strong>, and
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>
|
||||
CoffeeScript = <span class="hljs-built_in">require</span> <span class="hljs-string">'./coffeescript'</span>
|
||||
compile = CoffeeScript.compile</pre></div></div>
|
||||
CoffeeScript = <span class="hljs-built_in">require</span> <span class="hljs-string">'./coffeescript'</span>
|
||||
{ compile } = CoffeeScript</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
@@ -132,16 +132,20 @@ compile = CoffeeScript.compile</pre></div></div>
|
||||
<li id="section-2">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-2">¶</a>
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-2">§</a>
|
||||
</div>
|
||||
<p>Use standard JavaScript <code>eval</code> to eval code.</p>
|
||||
<p>Use <code>window.eval</code> to evaluate code, rather than just <code>eval</code>, to run the
|
||||
script in a clean global scope rather than inheriting the scope of the
|
||||
CoffeeScript compiler. (So that <code>cake test:browser</code> also works in Node,
|
||||
use either <code>window.eval</code> or <code>global.eval</code> as appropriate).</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>CoffeeScript.eval = <span class="hljs-function"><span class="hljs-params">(code, options = {})</span> -></span>
|
||||
<div class="content"><div class='highlight'><pre>CoffeeScript.<span class="hljs-built_in">eval</span> = <span class="hljs-function"><span class="hljs-params">(code, options = {})</span> -></span>
|
||||
options.bare ?= <span class="hljs-literal">on</span>
|
||||
eval compile code, options</pre></div></div>
|
||||
globalRoot = <span class="hljs-keyword">if</span> window? <span class="hljs-keyword">then</span> window <span class="hljs-keyword">else</span> global
|
||||
globalRoot[<span class="hljs-string">'eval'</span>] compile code, options</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
@@ -149,8 +153,8 @@ compile = CoffeeScript.compile</pre></div></div>
|
||||
<li id="section-3">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-3">¶</a>
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-3">§</a>
|
||||
</div>
|
||||
<p>Running code does not provide access to this scope.</p>
|
||||
|
||||
@@ -159,7 +163,7 @@ compile = CoffeeScript.compile</pre></div></div>
|
||||
<div class="content"><div class='highlight'><pre>CoffeeScript.run = <span class="hljs-function"><span class="hljs-params">(code, options = {})</span> -></span>
|
||||
options.bare = <span class="hljs-literal">on</span>
|
||||
options.shiftLine = <span class="hljs-literal">on</span>
|
||||
Function(compile code, options)()</pre></div></div>
|
||||
<span class="hljs-built_in">Function</span>(compile code, options)()</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
@@ -167,15 +171,15 @@ compile = CoffeeScript.compile</pre></div></div>
|
||||
<li id="section-4">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-4">¶</a>
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-4">§</a>
|
||||
</div>
|
||||
<p>Export this more limited <code>CoffeeScript</code> than what is exported by
|
||||
<code>index.coffee</code>, which is intended for a Node environment.</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre><span class="hljs-built_in">module</span>.exports = CoffeeScript</pre></div></div>
|
||||
<div class="content"><div class='highlight'><pre>module.<span class="hljs-built_in">exports</span> = CoffeeScript</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
@@ -183,14 +187,14 @@ compile = CoffeeScript.compile</pre></div></div>
|
||||
<li id="section-5">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-5">¶</a>
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-5">§</a>
|
||||
</div>
|
||||
<p>If we’re not in a browser environment, we’re finished with the public API.</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre><span class="hljs-keyword">return</span> <span class="hljs-keyword">unless</span> <span class="hljs-built_in">window</span>?</pre></div></div>
|
||||
<div class="content"><div class='highlight'><pre><span class="hljs-keyword">return</span> <span class="hljs-keyword">unless</span> window?</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
@@ -198,8 +202,8 @@ compile = CoffeeScript.compile</pre></div></div>
|
||||
<li id="section-6">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-6">¶</a>
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-6">§</a>
|
||||
</div>
|
||||
<p>Include source maps where possible. If we’ve got a base64 encoder, a
|
||||
JSON serializer, and tools for escaping unicode characters, we’re good to go.
|
||||
@@ -207,7 +211,7 @@ Ported from <a href="https://developer.mozilla.org/en-US/docs/DOM/window.btoa">h
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre><span class="hljs-keyword">if</span> btoa? <span class="hljs-keyword">and</span> JSON?
|
||||
<div class="content"><div class='highlight'><pre><span class="hljs-keyword">if</span> btoa? <span class="hljs-keyword">and</span> <span class="hljs-built_in">JSON</span>?
|
||||
<span class="hljs-function"> <span class="hljs-title">compile</span> = <span class="hljs-params">(code, options = {})</span> -></span>
|
||||
options.inlineMap = <span class="hljs-literal">true</span>
|
||||
CoffeeScript.compile code, options</pre></div></div>
|
||||
@@ -218,8 +222,8 @@ Ported from <a href="https://developer.mozilla.org/en-US/docs/DOM/window.btoa">h
|
||||
<li id="section-7">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-7">¶</a>
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-7">§</a>
|
||||
</div>
|
||||
<p>Load a remote script from the current domain via XHR.</p>
|
||||
|
||||
@@ -227,19 +231,19 @@ Ported from <a href="https://developer.mozilla.org/en-US/docs/DOM/window.btoa">h
|
||||
|
||||
<div class="content"><div class='highlight'><pre>CoffeeScript.load = <span class="hljs-function"><span class="hljs-params">(url, callback, options = {}, hold = <span class="hljs-literal">false</span>)</span> -></span>
|
||||
options.sourceFiles = [url]
|
||||
xhr = <span class="hljs-keyword">if</span> <span class="hljs-built_in">window</span>.ActiveXObject
|
||||
<span class="hljs-keyword">new</span> <span class="hljs-built_in">window</span>.ActiveXObject(<span class="hljs-string">'Microsoft.XMLHTTP'</span>)
|
||||
xhr = <span class="hljs-keyword">if</span> window.ActiveXObject
|
||||
<span class="hljs-keyword">new</span> window.ActiveXObject(<span class="hljs-string">'Microsoft.XMLHTTP'</span>)
|
||||
<span class="hljs-keyword">else</span>
|
||||
<span class="hljs-keyword">new</span> <span class="hljs-built_in">window</span>.XMLHttpRequest()
|
||||
xhr.open <span class="hljs-string">'GET'</span>, url, <span class="hljs-literal">true</span>
|
||||
xhr.overrideMimeType <span class="hljs-string">'text/plain'</span> <span class="hljs-keyword">if</span> <span class="hljs-string">'overrideMimeType'</span> <span class="hljs-keyword">of</span> xhr
|
||||
<span class="hljs-keyword">new</span> window.XMLHttpRequest()
|
||||
xhr.open <span class="hljs-string">'GET'</span>, url, <span class="hljs-literal">true</span>
|
||||
xhr.overrideMimeType <span class="hljs-string">'text/plain'</span> <span class="hljs-keyword">if</span> <span class="hljs-string">'overrideMimeType'</span> <span class="hljs-keyword">of</span> xhr
|
||||
xhr.onreadystatechange = <span class="hljs-function">-></span>
|
||||
<span class="hljs-keyword">if</span> xhr.readyState <span class="hljs-keyword">is</span> <span class="hljs-number">4</span>
|
||||
<span class="hljs-keyword">if</span> xhr.status <span class="hljs-keyword">in</span> [<span class="hljs-number">0</span>, <span class="hljs-number">200</span>]
|
||||
param = [xhr.responseText, options]
|
||||
CoffeeScript.run param... <span class="hljs-keyword">unless</span> hold
|
||||
<span class="hljs-keyword">else</span>
|
||||
<span class="hljs-keyword">throw</span> <span class="hljs-keyword">new</span> Error <span class="hljs-string">"Could not load <span class="hljs-subst">#{url}</span>"</span>
|
||||
<span class="hljs-keyword">throw</span> <span class="hljs-keyword">new</span> <span class="hljs-built_in">Error</span> <span class="hljs-string">"Could not load <span class="hljs-subst">#{url}</span>"</span>
|
||||
callback param <span class="hljs-keyword">if</span> callback
|
||||
xhr.send <span class="hljs-literal">null</span></pre></div></div>
|
||||
|
||||
@@ -249,8 +253,8 @@ Ported from <a href="https://developer.mozilla.org/en-US/docs/DOM/window.btoa">h
|
||||
<li id="section-8">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-8">¶</a>
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-8">§</a>
|
||||
</div>
|
||||
<p>Activate CoffeeScript in the browser by having it compile and evaluate
|
||||
all script tags with a content-type of <code>text/coffeescript</code>.
|
||||
@@ -258,15 +262,15 @@ This happens on page load.</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre><span class="hljs-function"><span class="hljs-title">runScripts</span> = -></span>
|
||||
scripts = <span class="hljs-built_in">window</span>.<span class="hljs-built_in">document</span>.getElementsByTagName <span class="hljs-string">'script'</span>
|
||||
coffeetypes = [<span class="hljs-string">'text/coffeescript'</span>, <span class="hljs-string">'text/literate-coffeescript'</span>]
|
||||
<div class="content"><div class='highlight'><pre>CoffeeScript.runScripts = <span class="hljs-function">-></span>
|
||||
scripts = window.document.getElementsByTagName <span class="hljs-string">'script'</span>
|
||||
coffeetypes = [<span class="hljs-string">'text/coffeescript'</span>, <span class="hljs-string">'text/literate-coffeescript'</span>]
|
||||
coffees = (s <span class="hljs-keyword">for</span> s <span class="hljs-keyword">in</span> scripts <span class="hljs-keyword">when</span> s.type <span class="hljs-keyword">in</span> coffeetypes)
|
||||
index = <span class="hljs-number">0</span>
|
||||
<span class="hljs-function">
|
||||
<span class="hljs-title">execute</span> = -></span>
|
||||
param = coffees[index]
|
||||
<span class="hljs-keyword">if</span> param <span class="hljs-keyword">instanceof</span> Array
|
||||
<span class="hljs-keyword">if</span> param <span class="hljs-keyword">instanceof</span> <span class="hljs-built_in">Array</span>
|
||||
CoffeeScript.run param...
|
||||
index++
|
||||
execute()
|
||||
@@ -274,7 +278,7 @@ This happens on page load.</p>
|
||||
<span class="hljs-keyword">for</span> script, i <span class="hljs-keyword">in</span> coffees
|
||||
<span class="hljs-keyword">do</span> (script, i) ->
|
||||
options = literate: script.type <span class="hljs-keyword">is</span> coffeetypes[<span class="hljs-number">1</span>]
|
||||
source = script.src <span class="hljs-keyword">or</span> script.getAttribute(<span class="hljs-string">'data-src'</span>)
|
||||
source = script.src <span class="hljs-keyword">or</span> script.getAttribute(<span class="hljs-string">'data-src'</span>)
|
||||
<span class="hljs-keyword">if</span> source
|
||||
options.filename = source
|
||||
CoffeeScript.load source,
|
||||
@@ -291,8 +295,8 @@ This happens on page load.</p>
|
||||
<li id="section-9">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-9">¶</a>
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-9">§</a>
|
||||
</div>
|
||||
<p><code>options.filename</code> defines the filename the source map appears as
|
||||
in Developer Tools. If a script tag has an <code>id</code>, use that as the
|
||||
@@ -302,8 +306,8 @@ only one CoffeeScript script block to parse.</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre> options.filename = <span class="hljs-keyword">if</span> script.id <span class="hljs-keyword">and</span> script.id <span class="hljs-keyword">isnt</span> <span class="hljs-string">''</span> <span class="hljs-keyword">then</span> script.id <span class="hljs-keyword">else</span> <span class="hljs-string">"coffeescript<span class="hljs-subst">#{<span class="hljs-keyword">if</span> i <span class="hljs-keyword">isnt</span> <span class="hljs-number">0</span> <span class="hljs-keyword">then</span> i <span class="hljs-keyword">else</span> <span class="hljs-string">''</span>}</span>"</span>
|
||||
options.sourceFiles = [<span class="hljs-string">'embedded'</span>]
|
||||
<div class="content"><div class='highlight'><pre> options.filename = <span class="hljs-keyword">if</span> script.id <span class="hljs-keyword">and</span> script.id <span class="hljs-keyword">isnt</span> <span class="hljs-string">''</span> <span class="hljs-keyword">then</span> script.id <span class="hljs-keyword">else</span> <span class="hljs-string">"coffeescript<span class="hljs-subst">#{<span class="hljs-keyword">if</span> i <span class="hljs-keyword">isnt</span> <span class="hljs-number">0</span> <span class="hljs-keyword">then</span> i <span class="hljs-keyword">else</span> <span class="hljs-string">''</span>}</span>"</span>
|
||||
options.sourceFiles = [<span class="hljs-string">'embedded'</span>]
|
||||
coffees[i] = [script.innerHTML, options]
|
||||
|
||||
execute()</pre></div></div>
|
||||
@@ -314,17 +318,22 @@ only one CoffeeScript script block to parse.</p>
|
||||
<li id="section-10">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-10">¶</a>
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-10">§</a>
|
||||
</div>
|
||||
<p>Listen for window load, both in decent browsers and in IE.</p>
|
||||
<p>Listen for window load, both in decent browsers and in IE.
|
||||
Only attach this event handler on startup for the
|
||||
non-ES module version of the browser compiler, to preserve
|
||||
backward compatibility while letting the ES module version
|
||||
be importable without side effects.</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre><span class="hljs-keyword">if</span> <span class="hljs-built_in">window</span>.addEventListener
|
||||
<span class="hljs-built_in">window</span>.addEventListener <span class="hljs-string">'DOMContentLoaded'</span>, runScripts, <span class="hljs-literal">no</span>
|
||||
<span class="hljs-keyword">else</span>
|
||||
<span class="hljs-built_in">window</span>.attachEvent <span class="hljs-string">'onload'</span>, runScripts</pre></div></div>
|
||||
<div class="content"><div class='highlight'><pre><span class="hljs-keyword">if</span> this <span class="hljs-keyword">is</span> window
|
||||
<span class="hljs-keyword">if</span> window.addEventListener
|
||||
window.addEventListener <span class="hljs-string">'DOMContentLoaded'</span>, CoffeeScript.runScripts, <span class="hljs-literal">no</span>
|
||||
<span class="hljs-keyword">else</span>
|
||||
window.attachEvent <span class="hljs-string">'onload'</span>, CoffeeScript.runScripts</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
@@ -112,8 +112,8 @@
|
||||
<li id="section-1">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-1">¶</a>
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-1">§</a>
|
||||
</div>
|
||||
<p><code>cake</code> is a simplified version of <a href="http://www.gnu.org/software/make/">Make</a>
|
||||
(<a href="http://rake.rubyforge.org/">Rake</a>, <a href="https://github.com/280north/jake">Jake</a>)
|
||||
@@ -130,18 +130,18 @@ current directory’s Cakefile.</p>
|
||||
<li id="section-2">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-2">¶</a>
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-2">§</a>
|
||||
</div>
|
||||
<p>External dependencies.</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>fs = <span class="hljs-built_in">require</span> <span class="hljs-string">'fs'</span>
|
||||
path = <span class="hljs-built_in">require</span> <span class="hljs-string">'path'</span>
|
||||
helpers = <span class="hljs-built_in">require</span> <span class="hljs-string">'./helpers'</span>
|
||||
optparse = <span class="hljs-built_in">require</span> <span class="hljs-string">'./optparse'</span>
|
||||
CoffeeScript = <span class="hljs-built_in">require</span> <span class="hljs-string">'./'</span></pre></div></div>
|
||||
<div class="content"><div class='highlight'><pre>fs = <span class="hljs-built_in">require</span> <span class="hljs-string">'fs'</span>
|
||||
path = <span class="hljs-built_in">require</span> <span class="hljs-string">'path'</span>
|
||||
helpers = <span class="hljs-built_in">require</span> <span class="hljs-string">'./helpers'</span>
|
||||
optparse = <span class="hljs-built_in">require</span> <span class="hljs-string">'./optparse'</span>
|
||||
CoffeeScript = <span class="hljs-built_in">require</span> <span class="hljs-string">'./'</span></pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
@@ -149,8 +149,8 @@ CoffeeScript = <span class="hljs-built_in">require</span> <span class="hljs-stri
|
||||
<li id="section-3">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-3">¶</a>
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-3">§</a>
|
||||
</div>
|
||||
<p>Register .coffee extension</p>
|
||||
|
||||
@@ -164,8 +164,8 @@ CoffeeScript = <span class="hljs-built_in">require</span> <span class="hljs-stri
|
||||
<li id="section-4">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-4">¶</a>
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-4">§</a>
|
||||
</div>
|
||||
<p>Keep track of the list of defined tasks, the accepted options, and so on.</p>
|
||||
|
||||
@@ -182,14 +182,14 @@ oparse = <span class="hljs-literal">null</span></pre></div></div>
|
||||
<li id="section-5">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-5">¶</a>
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-5">§</a>
|
||||
</div>
|
||||
<p>Mixin the top-level Cake functions for Cakefiles to use directly.</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>helpers.extend <span class="hljs-built_in">global</span>,</pre></div></div>
|
||||
<div class="content"><div class='highlight'><pre>helpers.extend global,</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
@@ -197,8 +197,8 @@ oparse = <span class="hljs-literal">null</span></pre></div></div>
|
||||
<li id="section-6">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-6">¶</a>
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-6">§</a>
|
||||
</div>
|
||||
<p>Define a Cake task with a short name, an optional sentence description,
|
||||
and the function to run as the action itself.</p>
|
||||
@@ -215,8 +215,8 @@ and the function to run as the action itself.</p>
|
||||
<li id="section-7">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-7">¶</a>
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-7">§</a>
|
||||
</div>
|
||||
<p>Define an option that the Cakefile accepts. The parsed options hash,
|
||||
containing all of the command-line options passed, will be made available
|
||||
@@ -233,8 +233,8 @@ as the first argument to the action.</p>
|
||||
<li id="section-8">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-8">¶</a>
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-8">§</a>
|
||||
</div>
|
||||
<p>Invoke another task in the current Cakefile.</p>
|
||||
|
||||
@@ -250,8 +250,8 @@ as the first argument to the action.</p>
|
||||
<li id="section-9">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-9">¶</a>
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-9">§</a>
|
||||
</div>
|
||||
<p>Run <code>cake</code>. Executes all of the tasks you pass, in order. Note that Node’s
|
||||
asynchrony may cause tasks to execute in a different order than you’d expect.
|
||||
@@ -260,17 +260,17 @@ original directory name, when running Cake tasks from subdirectories.</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>exports.run = <span class="hljs-function">-></span>
|
||||
<span class="hljs-built_in">global</span>.__originalDirname = fs.realpathSync <span class="hljs-string">'.'</span>
|
||||
<div class="content"><div class='highlight'><pre><span class="hljs-built_in">exports</span>.run = <span class="hljs-function">-></span>
|
||||
global.__originalDirname = fs.realpathSync <span class="hljs-string">'.'</span>
|
||||
process.chdir cakefileDirectory __originalDirname
|
||||
args = process.argv[<span class="hljs-number">2.</span>.]
|
||||
CoffeeScript.run fs.readFileSync(<span class="hljs-string">'Cakefile'</span>).toString(), filename: <span class="hljs-string">'Cakefile'</span>
|
||||
CoffeeScript.run fs.readFileSync(<span class="hljs-string">'Cakefile'</span>).toString(), filename: <span class="hljs-string">'Cakefile'</span>
|
||||
oparse = <span class="hljs-keyword">new</span> optparse.OptionParser switches
|
||||
<span class="hljs-keyword">return</span> printTasks() <span class="hljs-keyword">unless</span> args.length
|
||||
<span class="hljs-keyword">try</span>
|
||||
options = oparse.parse(args)
|
||||
<span class="hljs-keyword">catch</span> e
|
||||
<span class="hljs-keyword">return</span> fatalError <span class="hljs-string">"<span class="hljs-subst">#{e}</span>"</span>
|
||||
<span class="hljs-keyword">return</span> fatalError <span class="hljs-string">"<span class="hljs-subst">#{e}</span>"</span>
|
||||
invoke arg <span class="hljs-keyword">for</span> arg <span class="hljs-keyword">in</span> options.arguments</pre></div></div>
|
||||
|
||||
</li>
|
||||
@@ -279,8 +279,8 @@ original directory name, when running Cake tasks from subdirectories.</p>
|
||||
<li id="section-10">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-10">¶</a>
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-10">§</a>
|
||||
</div>
|
||||
<p>Display the list of Cake tasks in a format similar to <code>rake -T</code></p>
|
||||
|
||||
@@ -288,14 +288,14 @@ original directory name, when running Cake tasks from subdirectories.</p>
|
||||
|
||||
<div class="content"><div class='highlight'><pre><span class="hljs-function"><span class="hljs-title">printTasks</span> = -></span>
|
||||
relative = path.relative <span class="hljs-keyword">or</span> path.resolve
|
||||
cakefilePath = path.join relative(__originalDirname, process.cwd()), <span class="hljs-string">'Cakefile'</span>
|
||||
<span class="hljs-built_in">console</span>.log <span class="hljs-string">"<span class="hljs-subst">#{cakefilePath}</span> defines the following tasks:\n"</span>
|
||||
cakefilePath = path.join relative(__originalDirname, process.cwd()), <span class="hljs-string">'Cakefile'</span>
|
||||
console.log <span class="hljs-string">"<span class="hljs-subst">#{cakefilePath}</span> defines the following tasks:\n"</span>
|
||||
<span class="hljs-keyword">for</span> name, task <span class="hljs-keyword">of</span> tasks
|
||||
spaces = <span class="hljs-number">20</span> - name.length
|
||||
spaces = <span class="hljs-keyword">if</span> spaces > <span class="hljs-number">0</span> <span class="hljs-keyword">then</span> Array(spaces + <span class="hljs-number">1</span>).join(<span class="hljs-string">' '</span>) <span class="hljs-keyword">else</span> <span class="hljs-string">''</span>
|
||||
desc = <span class="hljs-keyword">if</span> task.description <span class="hljs-keyword">then</span> <span class="hljs-string">"# <span class="hljs-subst">#{task.description}</span>"</span> <span class="hljs-keyword">else</span> <span class="hljs-string">''</span>
|
||||
<span class="hljs-built_in">console</span>.log <span class="hljs-string">"cake <span class="hljs-subst">#{name}</span><span class="hljs-subst">#{spaces}</span> <span class="hljs-subst">#{desc}</span>"</span>
|
||||
<span class="hljs-built_in">console</span>.log oparse.help() <span class="hljs-keyword">if</span> switches.length</pre></div></div>
|
||||
spaces = <span class="hljs-keyword">if</span> spaces > <span class="hljs-number">0</span> <span class="hljs-keyword">then</span> <span class="hljs-built_in">Array</span>(spaces + <span class="hljs-number">1</span>).join(<span class="hljs-string">' '</span>) <span class="hljs-keyword">else</span> <span class="hljs-string">''</span>
|
||||
desc = <span class="hljs-keyword">if</span> task.description <span class="hljs-keyword">then</span> <span class="hljs-string">"# <span class="hljs-subst">#{task.description}</span>"</span> <span class="hljs-keyword">else</span> <span class="hljs-string">''</span>
|
||||
console.log <span class="hljs-string">"cake <span class="hljs-subst">#{name}</span><span class="hljs-subst">#{spaces}</span> <span class="hljs-subst">#{desc}</span>"</span>
|
||||
console.log oparse.help() <span class="hljs-keyword">if</span> switches.length</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
@@ -303,19 +303,19 @@ original directory name, when running Cake tasks from subdirectories.</p>
|
||||
<li id="section-11">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-11">¶</a>
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-11">§</a>
|
||||
</div>
|
||||
<p>Print an error and exit when attempting to use an invalid task/option.</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre><span class="hljs-function"><span class="hljs-title">fatalError</span> = <span class="hljs-params">(message)</span> -></span>
|
||||
<span class="hljs-built_in">console</span>.error message + <span class="hljs-string">'\n'</span>
|
||||
<span class="hljs-built_in">console</span>.log <span class="hljs-string">'To see a list of all tasks/options, run "cake"'</span>
|
||||
console.error message + <span class="hljs-string">'\n'</span>
|
||||
console.log <span class="hljs-string">'To see a list of all tasks/options, run "cake"'</span>
|
||||
process.exit <span class="hljs-number">1</span>
|
||||
<span class="hljs-function">
|
||||
<span class="hljs-title">missingTask</span> = <span class="hljs-params">(task)</span> -></span> fatalError <span class="hljs-string">"No such task: <span class="hljs-subst">#{task}</span>"</span></pre></div></div>
|
||||
<span class="hljs-title">missingTask</span> = <span class="hljs-params">(task)</span> -></span> fatalError <span class="hljs-string">"No such task: <span class="hljs-subst">#{task}</span>"</span></pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
@@ -323,8 +323,8 @@ original directory name, when running Cake tasks from subdirectories.</p>
|
||||
<li id="section-12">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-12">¶</a>
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-12">§</a>
|
||||
</div>
|
||||
<p>When <code>cake</code> is invoked, search in the current and all parent directories
|
||||
to find the relevant Cakefile.</p>
|
||||
@@ -332,10 +332,10 @@ to find the relevant Cakefile.</p>
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre><span class="hljs-function"><span class="hljs-title">cakefileDirectory</span> = <span class="hljs-params">(dir)</span> -></span>
|
||||
<span class="hljs-keyword">return</span> dir <span class="hljs-keyword">if</span> fs.existsSync path.join dir, <span class="hljs-string">'Cakefile'</span>
|
||||
parent = path.normalize path.join dir, <span class="hljs-string">'..'</span>
|
||||
<span class="hljs-keyword">return</span> dir <span class="hljs-keyword">if</span> fs.existsSync path.join dir, <span class="hljs-string">'Cakefile'</span>
|
||||
parent = path.normalize path.join dir, <span class="hljs-string">'..'</span>
|
||||
<span class="hljs-keyword">return</span> cakefileDirectory parent <span class="hljs-keyword">unless</span> parent <span class="hljs-keyword">is</span> dir
|
||||
<span class="hljs-keyword">throw</span> <span class="hljs-keyword">new</span> Error <span class="hljs-string">"Cakefile not found in <span class="hljs-subst">#{process.cwd()}</span>"</span></pre></div></div>
|
||||
<span class="hljs-keyword">throw</span> <span class="hljs-keyword">new</span> <span class="hljs-built_in">Error</span> <span class="hljs-string">"Cakefile not found in <span class="hljs-subst">#{process.cwd()}</span>"</span></pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
@@ -112,8 +112,8 @@
|
||||
<li id="section-1">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-1">¶</a>
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-1">§</a>
|
||||
</div>
|
||||
<p>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
|
||||
@@ -123,10 +123,10 @@ source CoffeeScript into JavaScript.</p>
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>
|
||||
{Lexer} = <span class="hljs-built_in">require</span> <span class="hljs-string">'./lexer'</span>
|
||||
{parser} = <span class="hljs-built_in">require</span> <span class="hljs-string">'./parser'</span>
|
||||
helpers = <span class="hljs-built_in">require</span> <span class="hljs-string">'./helpers'</span>
|
||||
SourceMap = <span class="hljs-built_in">require</span> <span class="hljs-string">'./sourcemap'</span></pre></div></div>
|
||||
{Lexer} = <span class="hljs-built_in">require</span> <span class="hljs-string">'./lexer'</span>
|
||||
{parser} = <span class="hljs-built_in">require</span> <span class="hljs-string">'./parser'</span>
|
||||
helpers = <span class="hljs-built_in">require</span> <span class="hljs-string">'./helpers'</span>
|
||||
SourceMap = <span class="hljs-built_in">require</span> <span class="hljs-string">'./sourcemap'</span></pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
@@ -134,15 +134,15 @@ SourceMap = <span class="hljs-built_in">require</span> <span class="hljs-str
|
||||
<li id="section-2">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-2">¶</a>
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-2">§</a>
|
||||
</div>
|
||||
<p>Require <code>package.json</code>, which is two levels above this file, as this file is
|
||||
evaluated from <code>lib/coffeescript</code>.</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>packageJson = <span class="hljs-built_in">require</span> <span class="hljs-string">'../../package.json'</span></pre></div></div>
|
||||
<div class="content"><div class='highlight'><pre>packageJson = <span class="hljs-built_in">require</span> <span class="hljs-string">'../../package.json'</span></pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
@@ -150,16 +150,16 @@ evaluated from <code>lib/coffeescript</code>.</p>
|
||||
<li id="section-3">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-3">¶</a>
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-3">§</a>
|
||||
</div>
|
||||
<p>The current CoffeeScript version number.</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>exports.VERSION = packageJson.version
|
||||
<div class="content"><div class='highlight'><pre><span class="hljs-built_in">exports</span>.VERSION = packageJson.version
|
||||
|
||||
exports.FILE_EXTENSIONS = FILE_EXTENSIONS = [<span class="hljs-string">'.coffee'</span>, <span class="hljs-string">'.litcoffee'</span>, <span class="hljs-string">'.coffee.md'</span>]</pre></div></div>
|
||||
<span class="hljs-built_in">exports</span>.FILE_EXTENSIONS = FILE_EXTENSIONS = [<span class="hljs-string">'.coffee'</span>, <span class="hljs-string">'.litcoffee'</span>, <span class="hljs-string">'.coffee.md'</span>]</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
@@ -167,14 +167,14 @@ exports.FILE_EXTENSIONS = FILE_EXTENSIONS = [<span class="hljs-string">'.coffee'
|
||||
<li id="section-4">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-4">¶</a>
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-4">§</a>
|
||||
</div>
|
||||
<p>Expose helpers for testing.</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>exports.helpers = helpers</pre></div></div>
|
||||
<div class="content"><div class='highlight'><pre><span class="hljs-built_in">exports</span>.helpers = helpers</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
@@ -182,17 +182,17 @@ exports.FILE_EXTENSIONS = FILE_EXTENSIONS = [<span class="hljs-string">'.coffee'
|
||||
<li id="section-5">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-5">¶</a>
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-5">§</a>
|
||||
</div>
|
||||
<p>Function that allows for btoa in both nodejs and the browser.</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre><span class="hljs-function"><span class="hljs-title">base64encode</span> = <span class="hljs-params">(src)</span> -></span> <span class="hljs-keyword">switch</span>
|
||||
<span class="hljs-keyword">when</span> <span class="hljs-keyword">typeof</span> Buffer <span class="hljs-keyword">is</span> <span class="hljs-string">'function'</span>
|
||||
Buffer.<span class="hljs-keyword">from</span>(src).toString(<span class="hljs-string">'base64'</span>)
|
||||
<span class="hljs-keyword">when</span> <span class="hljs-keyword">typeof</span> btoa <span class="hljs-keyword">is</span> <span class="hljs-string">'function'</span></pre></div></div>
|
||||
<span class="hljs-keyword">when</span> <span class="hljs-keyword">typeof</span> Buffer <span class="hljs-keyword">is</span> <span class="hljs-string">'function'</span>
|
||||
Buffer.<span class="hljs-keyword">from</span>(src).toString(<span class="hljs-string">'base64'</span>)
|
||||
<span class="hljs-keyword">when</span> <span class="hljs-keyword">typeof</span> btoa <span class="hljs-keyword">is</span> <span class="hljs-string">'function'</span></pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
@@ -200,8 +200,8 @@ exports.FILE_EXTENSIONS = FILE_EXTENSIONS = [<span class="hljs-string">'.coffee'
|
||||
<li id="section-6">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-6">¶</a>
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-6">§</a>
|
||||
</div>
|
||||
<p>The contents of a <code><script></code> block are encoded via UTF-16, so if any extended
|
||||
characters are used in the block, btoa will fail as it maxes out at UTF-8.
|
||||
@@ -210,10 +210,10 @@ for the gory details, and for the solution implemented here.</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre> btoa encodeURIComponent(src).replace <span class="hljs-regexp">/%([0-9A-F]{2})/g</span>, <span class="hljs-function"><span class="hljs-params">(match, p1)</span> -></span>
|
||||
String.fromCharCode <span class="hljs-string">'0x'</span> + p1
|
||||
<div class="content"><div class='highlight'><pre> btoa <span class="hljs-built_in">encodeURIComponent</span>(src).replace <span class="hljs-regexp">/%([0-9A-F]{2})/g</span>, <span class="hljs-function"><span class="hljs-params">(match, p1)</span> -></span>
|
||||
<span class="hljs-built_in">String</span>.fromCharCode <span class="hljs-string">'0x'</span> + p1
|
||||
<span class="hljs-keyword">else</span>
|
||||
<span class="hljs-keyword">throw</span> <span class="hljs-keyword">new</span> Error(<span class="hljs-string">'Unable to base64 encode inline sourcemap.'</span>)</pre></div></div>
|
||||
<span class="hljs-keyword">throw</span> <span class="hljs-keyword">new</span> <span class="hljs-built_in">Error</span>(<span class="hljs-string">'Unable to base64 encode inline sourcemap.'</span>)</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
@@ -221,8 +221,8 @@ for the gory details, and for the solution implemented here.</p>
|
||||
<li id="section-7">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-7">¶</a>
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-7">§</a>
|
||||
</div>
|
||||
<p>Function wrapper to add source file information to SyntaxErrors thrown by the
|
||||
lexer/parser/compiler.</p>
|
||||
@@ -234,7 +234,7 @@ lexer/parser/compiler.</p>
|
||||
<span class="hljs-keyword">try</span>
|
||||
fn.call @, code, options
|
||||
<span class="hljs-keyword">catch</span> err
|
||||
<span class="hljs-keyword">throw</span> err <span class="hljs-keyword">if</span> <span class="hljs-keyword">typeof</span> code <span class="hljs-keyword">isnt</span> <span class="hljs-string">'string'</span> <span class="hljs-comment"># Support `CoffeeScript.nodes(tokens)`.</span>
|
||||
<span class="hljs-keyword">throw</span> err <span class="hljs-keyword">if</span> <span class="hljs-keyword">typeof</span> code <span class="hljs-keyword">isnt</span> <span class="hljs-string">'string'</span> <span class="hljs-comment"># Support `CoffeeScript.nodes(tokens)`.</span>
|
||||
<span class="hljs-keyword">throw</span> helpers.updateSyntaxError err, code, options.filename</pre></div></div>
|
||||
|
||||
</li>
|
||||
@@ -243,8 +243,8 @@ lexer/parser/compiler.</p>
|
||||
<li id="section-8">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-8">¶</a>
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-8">§</a>
|
||||
</div>
|
||||
<p>For each compiled file, save its source in memory in case we need to
|
||||
recompile it later. We might need to recompile if the first compilation
|
||||
@@ -264,8 +264,8 @@ it’s not likely to be used. Save in form of <code>filename</code>: [<code>(sou
|
||||
<li id="section-9">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-9">¶</a>
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-9">§</a>
|
||||
</div>
|
||||
<p>Also save source maps if generated, in form of <code>(source)</code>: [<code>(source map)</code>].</p>
|
||||
|
||||
@@ -279,8 +279,34 @@ it’s not likely to be used. Save in form of <code>filename</code>: [<code>(sou
|
||||
<li id="section-10">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-10">¶</a>
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-10">§</a>
|
||||
</div>
|
||||
<p>This is exported to enable an external module to implement caching of
|
||||
compilation results. When the compiled js source is loaded from cache, the
|
||||
original coffee code should be added with this method in order to enable the
|
||||
Error.prepareStackTrace below to correctly adjust the stack trace for the
|
||||
corresponding file (the source map will be generated on demand).</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre><span class="hljs-built_in">exports</span>.registerCompiled = registerCompiled = <span class="hljs-function"><span class="hljs-params">(filename, source, sourcemap)</span> -></span>
|
||||
|
||||
sources[filename] ?= []
|
||||
sources[filename].push source
|
||||
|
||||
<span class="hljs-keyword">if</span> sourcemap?
|
||||
sourceMaps[filename] ?= []
|
||||
sourceMaps[filename].push sourcemap</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-11">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-11">§</a>
|
||||
</div>
|
||||
<p>Compile CoffeeScript code to JavaScript, using the Coffee/Jison compiler.</p>
|
||||
<p>If <code>options.sourceMap</code> is specified, then <code>options.filename</code> must also be
|
||||
@@ -293,18 +319,31 @@ doing programmatic lookups.</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>exports.compile = compile = withPrettyErrors (code, options) ->
|
||||
{merge, extend} = helpers
|
||||
options = extend {}, options</pre></div></div>
|
||||
<div class="content"><div class='highlight'><pre><span class="hljs-built_in">exports</span>.compile = compile = withPrettyErrors (code, options = {}) -></pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-11">
|
||||
<li id="section-12">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-11">¶</a>
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-12">§</a>
|
||||
</div>
|
||||
<p>Clone <code>options</code>, to avoid mutating the <code>options</code> object passed in.</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre> options = <span class="hljs-built_in">Object</span>.assign {}, options</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-13">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-13">§</a>
|
||||
</div>
|
||||
<p>Always generate a source map if no filename is passed in, since without a
|
||||
a filename we have no way to retrieve this source later in the event that
|
||||
@@ -313,12 +352,10 @@ we need to recompile it to get a source map for <code>prepareStackTrace</code>.<
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre> generateSourceMap = options.sourceMap <span class="hljs-keyword">or</span> options.inlineMap <span class="hljs-keyword">or</span> <span class="hljs-keyword">not</span> options.filename?
|
||||
filename = options.filename <span class="hljs-keyword">or</span> <span class="hljs-string">'<anonymous>'</span>
|
||||
filename = options.filename <span class="hljs-keyword">or</span> <span class="hljs-string">'<anonymous>'</span>
|
||||
|
||||
checkShebangLine filename, code
|
||||
|
||||
sources[filename] ?= []
|
||||
sources[filename].push code
|
||||
map = <span class="hljs-keyword">new</span> SourceMap <span class="hljs-keyword">if</span> generateSourceMap
|
||||
|
||||
tokens = lexer.tokenize code, options</pre></div></div>
|
||||
@@ -326,11 +363,11 @@ we need to recompile it to get a source map for <code>prepareStackTrace</code>.<
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-12">
|
||||
<li id="section-14">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-12">¶</a>
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-14">§</a>
|
||||
</div>
|
||||
<p>Pass a list of referenced variables, so that generated variables won’t get
|
||||
the same name.</p>
|
||||
@@ -338,17 +375,17 @@ the same name.</p>
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre> options.referencedVars = (
|
||||
token[<span class="hljs-number">1</span>] <span class="hljs-keyword">for</span> token <span class="hljs-keyword">in</span> tokens <span class="hljs-keyword">when</span> token[<span class="hljs-number">0</span>] <span class="hljs-keyword">is</span> <span class="hljs-string">'IDENTIFIER'</span>
|
||||
token[<span class="hljs-number">1</span>] <span class="hljs-keyword">for</span> token <span class="hljs-keyword">in</span> tokens <span class="hljs-keyword">when</span> token[<span class="hljs-number">0</span>] <span class="hljs-keyword">is</span> <span class="hljs-string">'IDENTIFIER'</span>
|
||||
)</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-13">
|
||||
<li id="section-15">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-13">¶</a>
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-15">§</a>
|
||||
</div>
|
||||
<p>Check for import or export; if found, force bare mode.</p>
|
||||
|
||||
@@ -356,27 +393,61 @@ the same name.</p>
|
||||
|
||||
<div class="content"><div class='highlight'><pre> <span class="hljs-keyword">unless</span> options.bare? <span class="hljs-keyword">and</span> options.bare <span class="hljs-keyword">is</span> <span class="hljs-literal">yes</span>
|
||||
<span class="hljs-keyword">for</span> token <span class="hljs-keyword">in</span> tokens
|
||||
<span class="hljs-keyword">if</span> token[<span class="hljs-number">0</span>] <span class="hljs-keyword">in</span> [<span class="hljs-string">'IMPORT'</span>, <span class="hljs-string">'EXPORT'</span>]
|
||||
<span class="hljs-keyword">if</span> token[<span class="hljs-number">0</span>] <span class="hljs-keyword">in</span> [<span class="hljs-string">'IMPORT'</span>, <span class="hljs-string">'EXPORT'</span>]
|
||||
options.bare = <span class="hljs-literal">yes</span>
|
||||
<span class="hljs-keyword">break</span>
|
||||
|
||||
fragments = parser.parse(tokens).compileToFragments options
|
||||
nodes = parser.parse tokens</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-16">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-16">§</a>
|
||||
</div>
|
||||
<p>If all that was requested was a POJO representation of the nodes, e.g.
|
||||
the abstract syntax tree (AST), we can stop now and just return that
|
||||
(after fixing the location data for the root/<code>File</code>»<code>Program</code> node,
|
||||
which might’ve gotten misaligned from the original source due to the
|
||||
<code>clean</code> function in the lexer).</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre> <span class="hljs-keyword">if</span> options.ast
|
||||
nodes.allCommentTokens = helpers.extractAllCommentTokens tokens
|
||||
sourceCodeNumberOfLines = (code.match(<span class="hljs-regexp">/\r?\n/g</span>) <span class="hljs-keyword">or</span> <span class="hljs-string">''</span>).length + <span class="hljs-number">1</span>
|
||||
sourceCodeLastLine = <span class="hljs-regexp">/.*$/</span>.exec(code)[<span class="hljs-number">0</span>] <span class="hljs-comment"># `.*` matches all but line break characters.</span>
|
||||
ast = nodes.ast options
|
||||
range = [<span class="hljs-number">0</span>, code.length]
|
||||
ast.start = ast.program.start = range[<span class="hljs-number">0</span>]
|
||||
ast.end = ast.program.end = range[<span class="hljs-number">1</span>]
|
||||
ast.range = ast.program.range = range
|
||||
ast.loc.start = ast.program.loc.start = {line: <span class="hljs-number">1</span>, column: <span class="hljs-number">0</span>}
|
||||
ast.loc.end.line = ast.program.loc.end.line = sourceCodeNumberOfLines
|
||||
ast.loc.end.column = ast.program.loc.end.column = sourceCodeLastLine.length
|
||||
ast.tokens = tokens
|
||||
<span class="hljs-keyword">return</span> ast
|
||||
|
||||
fragments = nodes.compileToFragments options
|
||||
|
||||
currentLine = <span class="hljs-number">0</span>
|
||||
currentLine += <span class="hljs-number">1</span> <span class="hljs-keyword">if</span> options.header
|
||||
currentLine += <span class="hljs-number">1</span> <span class="hljs-keyword">if</span> options.shiftLine
|
||||
currentColumn = <span class="hljs-number">0</span>
|
||||
js = <span class="hljs-string">""</span>
|
||||
js = <span class="hljs-string">""</span>
|
||||
<span class="hljs-keyword">for</span> fragment <span class="hljs-keyword">in</span> fragments</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-14">
|
||||
<li id="section-17">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-14">¶</a>
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-17">§</a>
|
||||
</div>
|
||||
<p>Update the sourcemap with data from each fragment.</p>
|
||||
|
||||
@@ -387,11 +458,11 @@ the same name.</p>
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-15">
|
||||
<li id="section-18">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-15">¶</a>
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-18">§</a>
|
||||
</div>
|
||||
<p>Do not include empty, whitespace, or semicolon-only fragments.</p>
|
||||
|
||||
@@ -402,21 +473,21 @@ the same name.</p>
|
||||
[fragment.locationData.first_line, fragment.locationData.first_column]
|
||||
[currentLine, currentColumn]
|
||||
{noReplace: <span class="hljs-literal">true</span>})
|
||||
newLines = helpers.count fragment.code, <span class="hljs-string">"\n"</span>
|
||||
newLines = helpers.count fragment.code, <span class="hljs-string">"\n"</span>
|
||||
currentLine += newLines
|
||||
<span class="hljs-keyword">if</span> newLines
|
||||
currentColumn = fragment.code.length - (fragment.code.lastIndexOf(<span class="hljs-string">"\n"</span>) + <span class="hljs-number">1</span>)
|
||||
currentColumn = fragment.code.length - (fragment.code.lastIndexOf(<span class="hljs-string">"\n"</span>) + <span class="hljs-number">1</span>)
|
||||
<span class="hljs-keyword">else</span>
|
||||
currentColumn += fragment.code.length</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-16">
|
||||
<li id="section-19">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-16">¶</a>
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-19">§</a>
|
||||
</div>
|
||||
<p>Copy the code from each fragment into the final JavaScript.</p>
|
||||
|
||||
@@ -425,25 +496,85 @@ the same name.</p>
|
||||
<div class="content"><div class='highlight'><pre> js += fragment.code
|
||||
|
||||
<span class="hljs-keyword">if</span> options.header
|
||||
header = <span class="hljs-string">"Generated by CoffeeScript <span class="hljs-subst">#{@VERSION}</span>"</span>
|
||||
js = <span class="hljs-string">"// <span class="hljs-subst">#{header}</span>\n<span class="hljs-subst">#{js}</span>"</span>
|
||||
header = <span class="hljs-string">"Generated by CoffeeScript <span class="hljs-subst">#{@VERSION}</span>"</span>
|
||||
js = <span class="hljs-string">"// <span class="hljs-subst">#{header}</span>\n<span class="hljs-subst">#{js}</span>"</span>
|
||||
|
||||
<span class="hljs-keyword">if</span> generateSourceMap
|
||||
v3SourceMap = map.generate options, code
|
||||
sourceMaps[filename] ?= []
|
||||
sourceMaps[filename].push map
|
||||
|
||||
<span class="hljs-keyword">if</span> options.transpile
|
||||
<span class="hljs-keyword">if</span> <span class="hljs-keyword">typeof</span> options.transpile <span class="hljs-keyword">isnt</span> <span class="hljs-string">'object'</span></pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-20">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-20">§</a>
|
||||
</div>
|
||||
<p>This only happens if run via the Node API and <code>transpile</code> is set to
|
||||
something other than an object.</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre> <span class="hljs-keyword">throw</span> <span class="hljs-keyword">new</span> <span class="hljs-built_in">Error</span> <span class="hljs-string">'The transpile option must be given an object with options to pass to Babel'</span></pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-21">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-21">§</a>
|
||||
</div>
|
||||
<p>Get the reference to Babel that we have been passed if this compiler
|
||||
is run via the CLI or Node API.</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre> transpiler = options.transpile.transpile
|
||||
<span class="hljs-keyword">delete</span> options.transpile.transpile
|
||||
|
||||
transpilerOptions = <span class="hljs-built_in">Object</span>.assign {}, options.transpile</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-22">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-22">§</a>
|
||||
</div>
|
||||
<p>See <a href="https://github.com/babel/babel/issues/827#issuecomment-77573107">https://github.com/babel/babel/issues/827#issuecomment-77573107</a>:
|
||||
Babel can take a v3 source map object as input in <code>inputSourceMap</code>
|
||||
and it will return an <em>updated</em> v3 source map object in its output.</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre> <span class="hljs-keyword">if</span> v3SourceMap <span class="hljs-keyword">and</span> <span class="hljs-keyword">not</span> transpilerOptions.inputSourceMap?
|
||||
transpilerOptions.inputSourceMap = v3SourceMap
|
||||
transpilerOutput = transpiler js, transpilerOptions
|
||||
js = transpilerOutput.code
|
||||
<span class="hljs-keyword">if</span> v3SourceMap <span class="hljs-keyword">and</span> transpilerOutput.map
|
||||
v3SourceMap = transpilerOutput.map
|
||||
|
||||
<span class="hljs-keyword">if</span> options.inlineMap
|
||||
encoded = base64encode JSON.stringify v3SourceMap
|
||||
sourceMapDataURI = <span class="hljs-string">"//# sourceMappingURL=data:application/json;base64,<span class="hljs-subst">#{encoded}</span>"</span>
|
||||
sourceURL = <span class="hljs-string">"//# sourceURL=<span class="hljs-subst">#{options.filename ? <span class="hljs-string">'coffeescript'</span>}</span>"</span>
|
||||
js = <span class="hljs-string">"<span class="hljs-subst">#{js}</span>\n<span class="hljs-subst">#{sourceMapDataURI}</span>\n<span class="hljs-subst">#{sourceURL}</span>"</span>
|
||||
encoded = base64encode <span class="hljs-built_in">JSON</span>.stringify v3SourceMap
|
||||
sourceMapDataURI = <span class="hljs-string">"//# sourceMappingURL=data:application/json;base64,<span class="hljs-subst">#{encoded}</span>"</span>
|
||||
sourceURL = <span class="hljs-string">"//# sourceURL=<span class="hljs-subst">#{options.filename ? <span class="hljs-string">'coffeescript'</span>}</span>"</span>
|
||||
js = <span class="hljs-string">"<span class="hljs-subst">#{js}</span>\n<span class="hljs-subst">#{sourceMapDataURI}</span>\n<span class="hljs-subst">#{sourceURL}</span>"</span>
|
||||
|
||||
registerCompiled filename, code, map
|
||||
|
||||
<span class="hljs-keyword">if</span> options.sourceMap
|
||||
{
|
||||
js
|
||||
sourceMap: map
|
||||
v3SourceMap: JSON.stringify v3SourceMap, <span class="hljs-literal">null</span>, <span class="hljs-number">2</span>
|
||||
v3SourceMap: <span class="hljs-built_in">JSON</span>.stringify v3SourceMap, <span class="hljs-literal">null</span>, <span class="hljs-number">2</span>
|
||||
}
|
||||
<span class="hljs-keyword">else</span>
|
||||
js</pre></div></div>
|
||||
@@ -451,27 +582,27 @@ the same name.</p>
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-17">
|
||||
<li id="section-23">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-17">¶</a>
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-23">§</a>
|
||||
</div>
|
||||
<p>Tokenize a string of CoffeeScript code, and return the array of tokens.</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>exports.tokens = withPrettyErrors (code, options) ->
|
||||
<div class="content"><div class='highlight'><pre><span class="hljs-built_in">exports</span>.tokens = withPrettyErrors (code, options) ->
|
||||
lexer.tokenize code, options</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-18">
|
||||
<li id="section-24">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-18">¶</a>
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-24">§</a>
|
||||
</div>
|
||||
<p>Parse a string of CoffeeScript code or an array of lexed tokens, and
|
||||
return the AST. You can then compile it by calling <code>.compile()</code> on the root,
|
||||
@@ -479,20 +610,18 @@ or traverse it by using <code>.traverseChildren()</code> with a callback.</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>exports.nodes = withPrettyErrors (source, options) ->
|
||||
<span class="hljs-keyword">if</span> <span class="hljs-keyword">typeof</span> source <span class="hljs-keyword">is</span> <span class="hljs-string">'string'</span>
|
||||
parser.parse lexer.tokenize source, options
|
||||
<span class="hljs-keyword">else</span>
|
||||
parser.parse source</pre></div></div>
|
||||
<div class="content"><div class='highlight'><pre><span class="hljs-built_in">exports</span>.nodes = withPrettyErrors (source, options) ->
|
||||
source = lexer.tokenize source, options <span class="hljs-keyword">if</span> <span class="hljs-keyword">typeof</span> source <span class="hljs-keyword">is</span> <span class="hljs-string">'string'</span>
|
||||
parser.parse source</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-19">
|
||||
<li id="section-25">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-19">¶</a>
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-25">§</a>
|
||||
</div>
|
||||
<p>This file used to export these methods; leave stubs that throw warnings
|
||||
instead. These methods have been moved into <code>index.coffee</code> to provide
|
||||
@@ -502,17 +631,17 @@ environment.</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>exports.run = exports.eval = exports.register = <span class="hljs-function">-></span>
|
||||
<span class="hljs-keyword">throw</span> <span class="hljs-keyword">new</span> Error <span class="hljs-string">'require index.coffee, not this file'</span></pre></div></div>
|
||||
<div class="content"><div class='highlight'><pre><span class="hljs-built_in">exports</span>.run = <span class="hljs-built_in">exports</span>.<span class="hljs-built_in">eval</span> = <span class="hljs-built_in">exports</span>.register = <span class="hljs-function">-></span>
|
||||
<span class="hljs-keyword">throw</span> <span class="hljs-keyword">new</span> <span class="hljs-built_in">Error</span> <span class="hljs-string">'require index.coffee, not this file'</span></pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-20">
|
||||
<li id="section-26">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-20">¶</a>
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-26">§</a>
|
||||
</div>
|
||||
<p>Instantiate a Lexer for our use here.</p>
|
||||
|
||||
@@ -523,19 +652,23 @@ environment.</p>
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-21">
|
||||
<li id="section-27">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-21">¶</a>
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-27">§</a>
|
||||
</div>
|
||||
<p>The real Lexer produces a generic stream of tokens. This object provides a
|
||||
thin wrapper around it, compatible with the Jison API. We can then pass it
|
||||
directly as a “Jison lexer”.</p>
|
||||
directly as a “Jison lexer.”</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>parser.lexer =
|
||||
yylloc:
|
||||
range: []
|
||||
options:
|
||||
ranges: <span class="hljs-literal">yes</span>
|
||||
lex: <span class="hljs-function">-></span>
|
||||
token = parser.tokens[@pos++]
|
||||
<span class="hljs-keyword">if</span> token
|
||||
@@ -543,36 +676,36 @@ directly as a “Jison lexer”.</p>
|
||||
parser.errorToken = token.origin <span class="hljs-keyword">or</span> token
|
||||
@yylineno = @yylloc.first_line
|
||||
<span class="hljs-keyword">else</span>
|
||||
tag = <span class="hljs-string">''</span>
|
||||
tag = <span class="hljs-string">''</span>
|
||||
tag
|
||||
setInput: <span class="hljs-function"><span class="hljs-params">(tokens)</span> -></span>
|
||||
parser.tokens = tokens
|
||||
@pos = <span class="hljs-number">0</span>
|
||||
upcomingInput: <span class="hljs-function">-></span> <span class="hljs-string">''</span></pre></div></div>
|
||||
upcomingInput: <span class="hljs-function">-></span> <span class="hljs-string">''</span></pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-22">
|
||||
<li id="section-28">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-22">¶</a>
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-28">§</a>
|
||||
</div>
|
||||
<p>Make all the AST nodes visible to the parser.</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>parser.yy = <span class="hljs-built_in">require</span> <span class="hljs-string">'./nodes'</span></pre></div></div>
|
||||
<div class="content"><div class='highlight'><pre>parser.yy = <span class="hljs-built_in">require</span> <span class="hljs-string">'./nodes'</span></pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-23">
|
||||
<li id="section-29">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-23">¶</a>
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-29">§</a>
|
||||
</div>
|
||||
<p>Override Jison’s default error handling function.</p>
|
||||
|
||||
@@ -583,11 +716,11 @@ directly as a “Jison lexer”.</p>
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-24">
|
||||
<li id="section-30">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-24">¶</a>
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-30">§</a>
|
||||
</div>
|
||||
<p>Disregard Jison’s message, it contains redundant line number information.
|
||||
Disregard the token, we take its value directly from the lexer in case
|
||||
@@ -600,22 +733,22 @@ the error is caused by a generated token which might refer to its origin.</p>
|
||||
|
||||
errorText = <span class="hljs-keyword">switch</span>
|
||||
<span class="hljs-keyword">when</span> errorToken <span class="hljs-keyword">is</span> tokens[tokens.length - <span class="hljs-number">1</span>]
|
||||
<span class="hljs-string">'end of input'</span>
|
||||
<span class="hljs-keyword">when</span> errorTag <span class="hljs-keyword">in</span> [<span class="hljs-string">'INDENT'</span>, <span class="hljs-string">'OUTDENT'</span>]
|
||||
<span class="hljs-string">'indentation'</span>
|
||||
<span class="hljs-keyword">when</span> errorTag <span class="hljs-keyword">in</span> [<span class="hljs-string">'IDENTIFIER'</span>, <span class="hljs-string">'NUMBER'</span>, <span class="hljs-string">'INFINITY'</span>, <span class="hljs-string">'STRING'</span>, <span class="hljs-string">'STRING_START'</span>, <span class="hljs-string">'REGEX'</span>, <span class="hljs-string">'REGEX_START'</span>]
|
||||
errorTag.replace(<span class="hljs-regexp">/_START$/</span>, <span class="hljs-string">''</span>).toLowerCase()
|
||||
<span class="hljs-string">'end of input'</span>
|
||||
<span class="hljs-keyword">when</span> errorTag <span class="hljs-keyword">in</span> [<span class="hljs-string">'INDENT'</span>, <span class="hljs-string">'OUTDENT'</span>]
|
||||
<span class="hljs-string">'indentation'</span>
|
||||
<span class="hljs-keyword">when</span> errorTag <span class="hljs-keyword">in</span> [<span class="hljs-string">'IDENTIFIER'</span>, <span class="hljs-string">'NUMBER'</span>, <span class="hljs-string">'INFINITY'</span>, <span class="hljs-string">'STRING'</span>, <span class="hljs-string">'STRING_START'</span>, <span class="hljs-string">'REGEX'</span>, <span class="hljs-string">'REGEX_START'</span>]
|
||||
errorTag.replace(<span class="hljs-regexp">/_START$/</span>, <span class="hljs-string">''</span>).toLowerCase()
|
||||
<span class="hljs-keyword">else</span>
|
||||
helpers.nameWhitespaceCharacter errorText</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-25">
|
||||
<li id="section-31">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-25">¶</a>
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-31">§</a>
|
||||
</div>
|
||||
<p>The second argument has a <code>loc</code> property, which should have the location
|
||||
data for this token. Unfortunately, Jison seems to send an outdated <code>loc</code>
|
||||
@@ -624,16 +757,16 @@ from the lexer.</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre> helpers.throwSyntaxError <span class="hljs-string">"unexpected <span class="hljs-subst">#{errorText}</span>"</span>, errorLoc</pre></div></div>
|
||||
<div class="content"><div class='highlight'><pre> helpers.throwSyntaxError <span class="hljs-string">"unexpected <span class="hljs-subst">#{errorText}</span>"</span>, errorLoc</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-26">
|
||||
<li id="section-32">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-26">¶</a>
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-32">§</a>
|
||||
</div>
|
||||
<p>Based on <a href="http://v8.googlecode.com/svn/branches/bleeding_edge/src/messages.js">http://v8.googlecode.com/svn/branches/bleeding_edge/src/messages.js</a>
|
||||
Modified to handle sourceMap</p>
|
||||
@@ -642,18 +775,18 @@ Modified to handle sourceMap</p>
|
||||
|
||||
<div class="content"><div class='highlight'><pre><span class="hljs-function"><span class="hljs-title">formatSourcePosition</span> = <span class="hljs-params">(frame, getSourceMapping)</span> -></span>
|
||||
filename = <span class="hljs-literal">undefined</span>
|
||||
fileLocation = <span class="hljs-string">''</span>
|
||||
fileLocation = <span class="hljs-string">''</span>
|
||||
|
||||
<span class="hljs-keyword">if</span> frame.isNative()
|
||||
fileLocation = <span class="hljs-string">"native"</span>
|
||||
fileLocation = <span class="hljs-string">"native"</span>
|
||||
<span class="hljs-keyword">else</span>
|
||||
<span class="hljs-keyword">if</span> frame.isEval()
|
||||
filename = frame.getScriptNameOrSourceURL()
|
||||
fileLocation = <span class="hljs-string">"<span class="hljs-subst">#{frame.getEvalOrigin()}</span>, "</span> <span class="hljs-keyword">unless</span> filename
|
||||
fileLocation = <span class="hljs-string">"<span class="hljs-subst">#{frame.getEvalOrigin()}</span>, "</span> <span class="hljs-keyword">unless</span> filename
|
||||
<span class="hljs-keyword">else</span>
|
||||
filename = frame.getFileName()
|
||||
|
||||
filename <span class="hljs-keyword">or</span>= <span class="hljs-string">"<anonymous>"</span>
|
||||
filename <span class="hljs-keyword">or</span>= <span class="hljs-string">"<anonymous>"</span>
|
||||
|
||||
line = frame.getLineNumber()
|
||||
column = frame.getColumnNumber()</pre></div></div>
|
||||
@@ -661,11 +794,11 @@ Modified to handle sourceMap</p>
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-27">
|
||||
<li id="section-33">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-27">¶</a>
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-33">§</a>
|
||||
</div>
|
||||
<p>Check for a sourceMap position</p>
|
||||
|
||||
@@ -674,9 +807,9 @@ Modified to handle sourceMap</p>
|
||||
<div class="content"><div class='highlight'><pre> source = getSourceMapping filename, line, column
|
||||
fileLocation =
|
||||
<span class="hljs-keyword">if</span> source
|
||||
<span class="hljs-string">"<span class="hljs-subst">#{filename}</span>:<span class="hljs-subst">#{source[<span class="hljs-number">0</span>]}</span>:<span class="hljs-subst">#{source[<span class="hljs-number">1</span>]}</span>"</span>
|
||||
<span class="hljs-string">"<span class="hljs-subst">#{filename}</span>:<span class="hljs-subst">#{source[<span class="hljs-number">0</span>]}</span>:<span class="hljs-subst">#{source[<span class="hljs-number">1</span>]}</span>"</span>
|
||||
<span class="hljs-keyword">else</span>
|
||||
<span class="hljs-string">"<span class="hljs-subst">#{filename}</span>:<span class="hljs-subst">#{line}</span>:<span class="hljs-subst">#{column}</span>"</span>
|
||||
<span class="hljs-string">"<span class="hljs-subst">#{filename}</span>:<span class="hljs-subst">#{line}</span>:<span class="hljs-subst">#{column}</span>"</span>
|
||||
|
||||
functionName = frame.getFunctionName()
|
||||
isConstructor = frame.isConstructor()
|
||||
@@ -687,19 +820,19 @@ Modified to handle sourceMap</p>
|
||||
typeName = frame.getTypeName()
|
||||
|
||||
<span class="hljs-keyword">if</span> functionName
|
||||
tp = <span class="hljs-keyword">as</span> = <span class="hljs-string">''</span>
|
||||
tp = <span class="hljs-keyword">as</span> = <span class="hljs-string">''</span>
|
||||
<span class="hljs-keyword">if</span> typeName <span class="hljs-keyword">and</span> functionName.indexOf typeName
|
||||
tp = <span class="hljs-string">"<span class="hljs-subst">#{typeName}</span>."</span>
|
||||
<span class="hljs-keyword">if</span> methodName <span class="hljs-keyword">and</span> functionName.indexOf(<span class="hljs-string">".<span class="hljs-subst">#{methodName}</span>"</span>) <span class="hljs-keyword">isnt</span> functionName.length - methodName.length - <span class="hljs-number">1</span>
|
||||
<span class="hljs-keyword">as</span> = <span class="hljs-string">" [as <span class="hljs-subst">#{methodName}</span>]"</span>
|
||||
tp = <span class="hljs-string">"<span class="hljs-subst">#{typeName}</span>."</span>
|
||||
<span class="hljs-keyword">if</span> methodName <span class="hljs-keyword">and</span> functionName.indexOf(<span class="hljs-string">".<span class="hljs-subst">#{methodName}</span>"</span>) <span class="hljs-keyword">isnt</span> functionName.length - methodName.length - <span class="hljs-number">1</span>
|
||||
<span class="hljs-keyword">as</span> = <span class="hljs-string">" [as <span class="hljs-subst">#{methodName}</span>]"</span>
|
||||
|
||||
<span class="hljs-string">"<span class="hljs-subst">#{tp}</span><span class="hljs-subst">#{functionName}</span><span class="hljs-subst">#{<span class="hljs-keyword">as</span>}</span> (<span class="hljs-subst">#{fileLocation}</span>)"</span>
|
||||
<span class="hljs-string">"<span class="hljs-subst">#{tp}</span><span class="hljs-subst">#{functionName}</span><span class="hljs-subst">#{<span class="hljs-keyword">as</span>}</span> (<span class="hljs-subst">#{fileLocation}</span>)"</span>
|
||||
<span class="hljs-keyword">else</span>
|
||||
<span class="hljs-string">"<span class="hljs-subst">#{typeName}</span>.<span class="hljs-subst">#{methodName <span class="hljs-keyword">or</span> <span class="hljs-string">'<anonymous>'</span>}</span> (<span class="hljs-subst">#{fileLocation}</span>)"</span>
|
||||
<span class="hljs-string">"<span class="hljs-subst">#{typeName}</span>.<span class="hljs-subst">#{methodName <span class="hljs-keyword">or</span> <span class="hljs-string">'<anonymous>'</span>}</span> (<span class="hljs-subst">#{fileLocation}</span>)"</span>
|
||||
<span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> isConstructor
|
||||
<span class="hljs-string">"new <span class="hljs-subst">#{functionName <span class="hljs-keyword">or</span> <span class="hljs-string">'<anonymous>'</span>}</span> (<span class="hljs-subst">#{fileLocation}</span>)"</span>
|
||||
<span class="hljs-string">"new <span class="hljs-subst">#{functionName <span class="hljs-keyword">or</span> <span class="hljs-string">'<anonymous>'</span>}</span> (<span class="hljs-subst">#{fileLocation}</span>)"</span>
|
||||
<span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> functionName
|
||||
<span class="hljs-string">"<span class="hljs-subst">#{functionName}</span> (<span class="hljs-subst">#{fileLocation}</span>)"</span>
|
||||
<span class="hljs-string">"<span class="hljs-subst">#{functionName}</span> (<span class="hljs-subst">#{fileLocation}</span>)"</span>
|
||||
<span class="hljs-keyword">else</span>
|
||||
fileLocation
|
||||
<span class="hljs-function">
|
||||
@@ -708,30 +841,30 @@ Modified to handle sourceMap</p>
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-28">
|
||||
<li id="section-34">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-28">¶</a>
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-34">§</a>
|
||||
</div>
|
||||
<p>Skip files that we didn’t compile, like Node system files that appear in
|
||||
the stack trace, as they never have source maps.</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre> <span class="hljs-keyword">return</span> <span class="hljs-literal">null</span> <span class="hljs-keyword">unless</span> filename <span class="hljs-keyword">is</span> <span class="hljs-string">'<anonymous>'</span> <span class="hljs-keyword">or</span> filename.slice(filename.lastIndexOf(<span class="hljs-string">'.'</span>)) <span class="hljs-keyword">in</span> FILE_EXTENSIONS
|
||||
<div class="content"><div class='highlight'><pre> <span class="hljs-keyword">return</span> <span class="hljs-literal">null</span> <span class="hljs-keyword">unless</span> filename <span class="hljs-keyword">is</span> <span class="hljs-string">'<anonymous>'</span> <span class="hljs-keyword">or</span> filename.slice(filename.lastIndexOf(<span class="hljs-string">'.'</span>)) <span class="hljs-keyword">in</span> FILE_EXTENSIONS
|
||||
|
||||
<span class="hljs-keyword">if</span> filename <span class="hljs-keyword">isnt</span> <span class="hljs-string">'<anonymous>'</span> <span class="hljs-keyword">and</span> sourceMaps[filename]?
|
||||
<span class="hljs-keyword">if</span> filename <span class="hljs-keyword">isnt</span> <span class="hljs-string">'<anonymous>'</span> <span class="hljs-keyword">and</span> sourceMaps[filename]?
|
||||
<span class="hljs-keyword">return</span> sourceMaps[filename][sourceMaps[filename].length - <span class="hljs-number">1</span>]</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-29">
|
||||
<li id="section-35">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-29">¶</a>
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-35">§</a>
|
||||
</div>
|
||||
<p>CoffeeScript compiled in a browser or via <code>CoffeeScript.compile</code> or <code>.run</code>
|
||||
may get compiled with <code>options.filename</code> that’s missing, which becomes
|
||||
@@ -741,16 +874,16 @@ filename of the script file. See if we have a source map cached under
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre> <span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> sourceMaps[<span class="hljs-string">'<anonymous>'</span>]?</pre></div></div>
|
||||
<div class="content"><div class='highlight'><pre> <span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> sourceMaps[<span class="hljs-string">'<anonymous>'</span>]?</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-30">
|
||||
<li id="section-36">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-30">¶</a>
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-36">§</a>
|
||||
</div>
|
||||
<p>Work backwards from the most recent anonymous source maps, until we find
|
||||
one that works. This isn’t foolproof; there is a chance that multiple
|
||||
@@ -760,18 +893,18 @@ and it’s not foolproof either.</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre> <span class="hljs-keyword">for</span> map <span class="hljs-keyword">in</span> sourceMaps[<span class="hljs-string">'<anonymous>'</span>] <span class="hljs-keyword">by</span> <span class="hljs-number">-1</span>
|
||||
<div class="content"><div class='highlight'><pre> <span class="hljs-keyword">for</span> map <span class="hljs-keyword">in</span> sourceMaps[<span class="hljs-string">'<anonymous>'</span>] <span class="hljs-keyword">by</span> <span class="hljs-number">-1</span>
|
||||
sourceLocation = map.sourceLocation [line - <span class="hljs-number">1</span>, column - <span class="hljs-number">1</span>]
|
||||
<span class="hljs-keyword">return</span> map <span class="hljs-keyword">if</span> sourceLocation?[<span class="hljs-number">0</span>]? <span class="hljs-keyword">and</span> sourceLocation[<span class="hljs-number">1</span>]?</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-31">
|
||||
<li id="section-37">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-31">¶</a>
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-37">§</a>
|
||||
</div>
|
||||
<p>If all else fails, recompile this source to get a source map. We need the
|
||||
previous section (for <code><anonymous></code>) despite this option, because after it
|
||||
@@ -794,11 +927,11 @@ time the source map we want is the last one.</p>
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-32">
|
||||
<li id="section-38">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-32">¶</a>
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-38">§</a>
|
||||
</div>
|
||||
<p>Based on <a href="http://goo.gl/ZTx1p">michaelficarra/CoffeeScriptRedux</a>
|
||||
NodeJS / V8 have no support for transforming positions in stack traces using
|
||||
@@ -807,30 +940,30 @@ positions.</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>Error.prepareStackTrace = <span class="hljs-function"><span class="hljs-params">(err, stack)</span> -></span>
|
||||
<div class="content"><div class='highlight'><pre><span class="hljs-built_in">Error</span>.prepareStackTrace = <span class="hljs-function"><span class="hljs-params">(err, stack)</span> -></span>
|
||||
<span class="hljs-function"> <span class="hljs-title">getSourceMapping</span> = <span class="hljs-params">(filename, line, column)</span> -></span>
|
||||
sourceMap = getSourceMap filename, line, column
|
||||
answer = sourceMap.sourceLocation [line - <span class="hljs-number">1</span>, column - <span class="hljs-number">1</span>] <span class="hljs-keyword">if</span> sourceMap?
|
||||
<span class="hljs-keyword">if</span> answer? <span class="hljs-keyword">then</span> [answer[<span class="hljs-number">0</span>] + <span class="hljs-number">1</span>, answer[<span class="hljs-number">1</span>] + <span class="hljs-number">1</span>] <span class="hljs-keyword">else</span> <span class="hljs-literal">null</span>
|
||||
|
||||
frames = <span class="hljs-keyword">for</span> frame <span class="hljs-keyword">in</span> stack
|
||||
<span class="hljs-keyword">break</span> <span class="hljs-keyword">if</span> frame.getFunction() <span class="hljs-keyword">is</span> exports.run
|
||||
<span class="hljs-string">" at <span class="hljs-subst">#{formatSourcePosition frame, getSourceMapping}</span>"</span>
|
||||
<span class="hljs-keyword">break</span> <span class="hljs-keyword">if</span> frame.getFunction() <span class="hljs-keyword">is</span> <span class="hljs-built_in">exports</span>.run
|
||||
<span class="hljs-string">" at <span class="hljs-subst">#{formatSourcePosition frame, getSourceMapping}</span>"</span>
|
||||
|
||||
<span class="hljs-string">"<span class="hljs-subst">#{err.toString()}</span>\n<span class="hljs-subst">#{frames.join <span class="hljs-string">'\n'</span>}</span>\n"</span>
|
||||
<span class="hljs-string">"<span class="hljs-subst">#{err.toString()}</span>\n<span class="hljs-subst">#{frames.join <span class="hljs-string">'\n'</span>}</span>\n"</span>
|
||||
<span class="hljs-function">
|
||||
<span class="hljs-title">checkShebangLine</span> = <span class="hljs-params">(file, input)</span> -></span>
|
||||
firstLine = input.split(<span class="hljs-regexp">/$/m</span>)[<span class="hljs-number">0</span>]
|
||||
rest = firstLine?.match(<span class="hljs-regexp">/^#!\s*([^\s]+\s*)(.*)/</span>)
|
||||
args = rest?[<span class="hljs-number">2</span>]?.split(<span class="hljs-regexp">/\s/</span>).filter (s) -> s <span class="hljs-keyword">isnt</span> <span class="hljs-string">''</span>
|
||||
args = rest?[<span class="hljs-number">2</span>]?.split(<span class="hljs-regexp">/\s/</span>).filter (s) -> s <span class="hljs-keyword">isnt</span> <span class="hljs-string">''</span>
|
||||
<span class="hljs-keyword">if</span> args?.length > <span class="hljs-number">1</span>
|
||||
<span class="hljs-built_in">console</span>.error <span class="hljs-string">'''
|
||||
console.error <span class="hljs-string">'''
|
||||
The script to be run begins with a shebang line with more than one
|
||||
argument. This script will fail on platforms such as Linux which only
|
||||
allow a single argument.
|
||||
'''</span>
|
||||
<span class="hljs-built_in">console</span>.error <span class="hljs-string">"The shebang line was: '<span class="hljs-subst">#{firstLine}</span>' in file '<span class="hljs-subst">#{file}</span>'"</span>
|
||||
<span class="hljs-built_in">console</span>.error <span class="hljs-string">"The arguments were: <span class="hljs-subst">#{JSON.stringify args}</span>"</span></pre></div></div>
|
||||
'''</span>
|
||||
console.error <span class="hljs-string">"The shebang line was: '<span class="hljs-subst">#{firstLine}</span>' in file '<span class="hljs-subst">#{file}</span>'"</span>
|
||||
console.error <span class="hljs-string">"The arguments were: <span class="hljs-subst">#{<span class="hljs-built_in">JSON</span>.stringify args}</span>"</span></pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
@@ -112,8 +112,8 @@
|
||||
<li id="section-1">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-1">¶</a>
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-1">§</a>
|
||||
</div>
|
||||
<p>The <code>coffee</code> utility. Handles command-line compilation of CoffeeScript
|
||||
into various forms: saved into <code>.js</code> files or printed to stdout
|
||||
@@ -129,22 +129,22 @@ interactive REPL.</p>
|
||||
<li id="section-2">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-2">¶</a>
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-2">§</a>
|
||||
</div>
|
||||
<p>External dependencies.</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>fs = <span class="hljs-built_in">require</span> <span class="hljs-string">'fs'</span>
|
||||
path = <span class="hljs-built_in">require</span> <span class="hljs-string">'path'</span>
|
||||
helpers = <span class="hljs-built_in">require</span> <span class="hljs-string">'./helpers'</span>
|
||||
optparse = <span class="hljs-built_in">require</span> <span class="hljs-string">'./optparse'</span>
|
||||
CoffeeScript = <span class="hljs-built_in">require</span> <span class="hljs-string">'./'</span>
|
||||
{spawn, exec} = <span class="hljs-built_in">require</span> <span class="hljs-string">'child_process'</span>
|
||||
{EventEmitter} = <span class="hljs-built_in">require</span> <span class="hljs-string">'events'</span>
|
||||
<div class="content"><div class='highlight'><pre>fs = <span class="hljs-built_in">require</span> <span class="hljs-string">'fs'</span>
|
||||
path = <span class="hljs-built_in">require</span> <span class="hljs-string">'path'</span>
|
||||
helpers = <span class="hljs-built_in">require</span> <span class="hljs-string">'./helpers'</span>
|
||||
optparse = <span class="hljs-built_in">require</span> <span class="hljs-string">'./optparse'</span>
|
||||
CoffeeScript = <span class="hljs-built_in">require</span> <span class="hljs-string">'./'</span>
|
||||
{spawn, exec} = <span class="hljs-built_in">require</span> <span class="hljs-string">'child_process'</span>
|
||||
{EventEmitter} = <span class="hljs-built_in">require</span> <span class="hljs-string">'events'</span>
|
||||
|
||||
useWinPathSep = path.sep <span class="hljs-keyword">is</span> <span class="hljs-string">'\\'</span></pre></div></div>
|
||||
useWinPathSep = path.sep <span class="hljs-keyword">is</span> <span class="hljs-string">'\\'</span></pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
@@ -152,8 +152,8 @@ useWinPathSep = path.sep <span class="hljs-keyword">is</span> <span class="hljs
|
||||
<li id="section-3">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-3">¶</a>
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-3">§</a>
|
||||
</div>
|
||||
<p>Allow CoffeeScript to emit Node.js events.</p>
|
||||
|
||||
@@ -161,8 +161,8 @@ useWinPathSep = path.sep <span class="hljs-keyword">is</span> <span class="hljs
|
||||
|
||||
<div class="content"><div class='highlight'><pre>helpers.extend CoffeeScript, <span class="hljs-keyword">new</span> EventEmitter
|
||||
<span class="hljs-function">
|
||||
<span class="hljs-title">printLine</span> = <span class="hljs-params">(line)</span> -></span> process.stdout.write line + <span class="hljs-string">'\n'</span>
|
||||
<span class="hljs-function"><span class="hljs-title">printWarn</span> = <span class="hljs-params">(line)</span> -></span> process.stderr.write line + <span class="hljs-string">'\n'</span>
|
||||
<span class="hljs-title">printLine</span> = <span class="hljs-params">(line)</span> -></span> process.stdout.write line + <span class="hljs-string">'\n'</span>
|
||||
<span class="hljs-function"><span class="hljs-title">printWarn</span> = <span class="hljs-params">(line)</span> -></span> process.stderr.write line + <span class="hljs-string">'\n'</span>
|
||||
<span class="hljs-function">
|
||||
<span class="hljs-title">hidden</span> = <span class="hljs-params">(file)</span> -></span> <span class="hljs-regexp">/^\.|~$/</span>.test file</pre></div></div>
|
||||
|
||||
@@ -172,18 +172,18 @@ useWinPathSep = path.sep <span class="hljs-keyword">is</span> <span class="hljs
|
||||
<li id="section-4">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-4">¶</a>
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-4">§</a>
|
||||
</div>
|
||||
<p>The help banner that is printed in conjunction with <code>-h</code>/<code>--help</code>.</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>BANNER = <span class="hljs-string">'''
|
||||
<div class="content"><div class='highlight'><pre>BANNER = <span class="hljs-string">'''
|
||||
Usage: coffee [options] path/to/script.coffee [args]
|
||||
|
||||
If called without options, `coffee` will run your script.
|
||||
'''</span></pre></div></div>
|
||||
'''</span></pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
@@ -191,33 +191,35 @@ useWinPathSep = path.sep <span class="hljs-keyword">is</span> <span class="hljs
|
||||
<li id="section-5">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-5">¶</a>
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-5">§</a>
|
||||
</div>
|
||||
<p>The list of all the valid option flags that <code>coffee</code> knows how to handle.</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>SWITCHES = [
|
||||
[<span class="hljs-string">'-b'</span>, <span class="hljs-string">'--bare'</span>, <span class="hljs-string">'compile without a top-level function wrapper'</span>]
|
||||
[<span class="hljs-string">'-c'</span>, <span class="hljs-string">'--compile'</span>, <span class="hljs-string">'compile to JavaScript and save as .js files'</span>]
|
||||
[<span class="hljs-string">'-e'</span>, <span class="hljs-string">'--eval'</span>, <span class="hljs-string">'pass a string from the command line as input'</span>]
|
||||
[<span class="hljs-string">'-h'</span>, <span class="hljs-string">'--help'</span>, <span class="hljs-string">'display this help message'</span>]
|
||||
[<span class="hljs-string">'-i'</span>, <span class="hljs-string">'--interactive'</span>, <span class="hljs-string">'run an interactive CoffeeScript REPL'</span>]
|
||||
[<span class="hljs-string">'-j'</span>, <span class="hljs-string">'--join [FILE]'</span>, <span class="hljs-string">'concatenate the source CoffeeScript before compiling'</span>]
|
||||
[<span class="hljs-string">'-m'</span>, <span class="hljs-string">'--map'</span>, <span class="hljs-string">'generate source map and save as .js.map files'</span>]
|
||||
[<span class="hljs-string">'-M'</span>, <span class="hljs-string">'--inline-map'</span>, <span class="hljs-string">'generate source map and include it directly in output'</span>]
|
||||
[<span class="hljs-string">'-n'</span>, <span class="hljs-string">'--nodes'</span>, <span class="hljs-string">'print out the parse tree that the parser produces'</span>]
|
||||
[ <span class="hljs-string">'--nodejs [ARGS]'</span>, <span class="hljs-string">'pass options directly to the "node" binary'</span>]
|
||||
[ <span class="hljs-string">'--no-header'</span>, <span class="hljs-string">'suppress the "Generated by" header'</span>]
|
||||
[<span class="hljs-string">'-o'</span>, <span class="hljs-string">'--output [PATH]'</span>, <span class="hljs-string">'set the output path or path/filename for compiled JavaScript'</span>]
|
||||
[<span class="hljs-string">'-p'</span>, <span class="hljs-string">'--print'</span>, <span class="hljs-string">'print out the compiled JavaScript'</span>]
|
||||
[<span class="hljs-string">'-r'</span>, <span class="hljs-string">'--require [MODULE*]'</span>, <span class="hljs-string">'require the given module before eval or REPL'</span>]
|
||||
[<span class="hljs-string">'-s'</span>, <span class="hljs-string">'--stdio'</span>, <span class="hljs-string">'listen for and compile scripts over stdio'</span>]
|
||||
[<span class="hljs-string">'-l'</span>, <span class="hljs-string">'--literate'</span>, <span class="hljs-string">'treat stdio as literate style coffeescript'</span>]
|
||||
[<span class="hljs-string">'-t'</span>, <span class="hljs-string">'--tokens'</span>, <span class="hljs-string">'print out the tokens that the lexer/rewriter produce'</span>]
|
||||
[<span class="hljs-string">'-v'</span>, <span class="hljs-string">'--version'</span>, <span class="hljs-string">'display the version number'</span>]
|
||||
[<span class="hljs-string">'-w'</span>, <span class="hljs-string">'--watch'</span>, <span class="hljs-string">'watch scripts for changes and rerun commands'</span>]
|
||||
[ <span class="hljs-string">'--ast'</span>, <span class="hljs-string">'generate an abstract syntax tree of nodes'</span>]
|
||||
[<span class="hljs-string">'-b'</span>, <span class="hljs-string">'--bare'</span>, <span class="hljs-string">'compile without a top-level function wrapper'</span>]
|
||||
[<span class="hljs-string">'-c'</span>, <span class="hljs-string">'--compile'</span>, <span class="hljs-string">'compile to JavaScript and save as .js files'</span>]
|
||||
[<span class="hljs-string">'-e'</span>, <span class="hljs-string">'--eval'</span>, <span class="hljs-string">'pass a string from the command line as input'</span>]
|
||||
[<span class="hljs-string">'-h'</span>, <span class="hljs-string">'--help'</span>, <span class="hljs-string">'display this help message'</span>]
|
||||
[<span class="hljs-string">'-i'</span>, <span class="hljs-string">'--interactive'</span>, <span class="hljs-string">'run an interactive CoffeeScript REPL'</span>]
|
||||
[<span class="hljs-string">'-j'</span>, <span class="hljs-string">'--join [FILE]'</span>, <span class="hljs-string">'concatenate the source CoffeeScript before compiling'</span>]
|
||||
[<span class="hljs-string">'-l'</span>, <span class="hljs-string">'--literate'</span>, <span class="hljs-string">'treat stdio as literate style coffeescript'</span>]
|
||||
[<span class="hljs-string">'-m'</span>, <span class="hljs-string">'--map'</span>, <span class="hljs-string">'generate source map and save as .js.map files'</span>]
|
||||
[<span class="hljs-string">'-M'</span>, <span class="hljs-string">'--inline-map'</span>, <span class="hljs-string">'generate source map and include it directly in output'</span>]
|
||||
[<span class="hljs-string">'-n'</span>, <span class="hljs-string">'--nodes'</span>, <span class="hljs-string">'print out the parse tree that the parser produces'</span>]
|
||||
[ <span class="hljs-string">'--nodejs [ARGS]'</span>, <span class="hljs-string">'pass options directly to the "node" binary'</span>]
|
||||
[ <span class="hljs-string">'--no-header'</span>, <span class="hljs-string">'suppress the "Generated by" header'</span>]
|
||||
[<span class="hljs-string">'-o'</span>, <span class="hljs-string">'--output [PATH]'</span>, <span class="hljs-string">'set the output path or path/filename for compiled JavaScript'</span>]
|
||||
[<span class="hljs-string">'-p'</span>, <span class="hljs-string">'--print'</span>, <span class="hljs-string">'print out the compiled JavaScript'</span>]
|
||||
[<span class="hljs-string">'-r'</span>, <span class="hljs-string">'--require [MODULE*]'</span>, <span class="hljs-string">'require the given module before eval or REPL'</span>]
|
||||
[<span class="hljs-string">'-s'</span>, <span class="hljs-string">'--stdio'</span>, <span class="hljs-string">'listen for and compile scripts over stdio'</span>]
|
||||
[<span class="hljs-string">'-t'</span>, <span class="hljs-string">'--transpile'</span>, <span class="hljs-string">'pipe generated JavaScript through Babel'</span>]
|
||||
[ <span class="hljs-string">'--tokens'</span>, <span class="hljs-string">'print out the tokens that the lexer/rewriter produce'</span>]
|
||||
[<span class="hljs-string">'-v'</span>, <span class="hljs-string">'--version'</span>, <span class="hljs-string">'display the version number'</span>]
|
||||
[<span class="hljs-string">'-w'</span>, <span class="hljs-string">'--watch'</span>, <span class="hljs-string">'watch scripts for changes and rerun commands'</span>]
|
||||
]</pre></div></div>
|
||||
|
||||
</li>
|
||||
@@ -226,8 +228,8 @@ useWinPathSep = path.sep <span class="hljs-keyword">is</span> <span class="hljs
|
||||
<li id="section-6">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-6">¶</a>
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-6">§</a>
|
||||
</div>
|
||||
<p>Top-level objects shared by all the functions.</p>
|
||||
|
||||
@@ -240,7 +242,7 @@ notSources = {}
|
||||
watchedDirs = {}
|
||||
optionParser = <span class="hljs-literal">null</span>
|
||||
|
||||
exports.buildCSOptionParser = buildCSOptionParser = <span class="hljs-function">-></span>
|
||||
<span class="hljs-built_in">exports</span>.buildCSOptionParser = buildCSOptionParser = <span class="hljs-function">-></span>
|
||||
<span class="hljs-keyword">new</span> optparse.OptionParser SWITCHES, BANNER</pre></div></div>
|
||||
|
||||
</li>
|
||||
@@ -249,8 +251,8 @@ exports.buildCSOptionParser = buildCSOptionParser = <span class="hljs-function">
|
||||
<li id="section-7">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-7">¶</a>
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-7">§</a>
|
||||
</div>
|
||||
<p>Run <code>coffee</code> by parsing passed options and determining what action to take.
|
||||
Many flags cause us to divert before compiling anything. Flags passed after
|
||||
@@ -258,22 +260,22 @@ Many flags cause us to divert before compiling anything. Flags passed after
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>exports.run = <span class="hljs-function">-></span>
|
||||
<div class="content"><div class='highlight'><pre><span class="hljs-built_in">exports</span>.run = <span class="hljs-function">-></span>
|
||||
optionParser = buildCSOptionParser()
|
||||
<span class="hljs-keyword">try</span> parseOptions()
|
||||
<span class="hljs-keyword">catch</span> err
|
||||
<span class="hljs-built_in">console</span>.error <span class="hljs-string">"option parsing error: <span class="hljs-subst">#{err.message}</span>"</span>
|
||||
console.error <span class="hljs-string">"option parsing error: <span class="hljs-subst">#{err.message}</span>"</span>
|
||||
process.exit <span class="hljs-number">1</span>
|
||||
|
||||
<span class="hljs-keyword">if</span> (<span class="hljs-keyword">not</span> opts.doubleDashed) <span class="hljs-keyword">and</span> (opts.arguments[<span class="hljs-number">1</span>] <span class="hljs-keyword">is</span> <span class="hljs-string">'--'</span>)
|
||||
printWarn <span class="hljs-string">'''
|
||||
coffee was invoked with '--' as the second positional argument, which is
|
||||
now deprecated. To pass '--' as an argument to a script to run, put an
|
||||
additional '--' before the path to your script.
|
||||
<span class="hljs-keyword">if</span> (<span class="hljs-keyword">not</span> opts.doubleDashed) <span class="hljs-keyword">and</span> (opts.arguments[<span class="hljs-number">1</span>] <span class="hljs-keyword">is</span> <span class="hljs-string">'--'</span>)
|
||||
printWarn <span class="hljs-string">'''
|
||||
coffee was invoked with '--' as the second positional argument, which is
|
||||
now deprecated. To pass '--' as an argument to a script to run, put an
|
||||
additional '--' before the path to your script.
|
||||
|
||||
'--' will be removed from the argument list.
|
||||
'''</span>
|
||||
printWarn <span class="hljs-string">"The positional arguments were: <span class="hljs-subst">#{JSON.stringify opts.arguments}</span>"</span>
|
||||
'--' will be removed from the argument list.
|
||||
'''</span>
|
||||
printWarn <span class="hljs-string">"The positional arguments were: <span class="hljs-subst">#{<span class="hljs-built_in">JSON</span>.stringify opts.arguments}</span>"</span>
|
||||
opts.arguments = [opts.arguments[<span class="hljs-number">0</span>]].concat opts.arguments[<span class="hljs-number">2.</span>.]</pre></div></div>
|
||||
|
||||
</li>
|
||||
@@ -282,8 +284,8 @@ Many flags cause us to divert before compiling anything. Flags passed after
|
||||
<li id="section-8">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-8">¶</a>
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-8">§</a>
|
||||
</div>
|
||||
<p>Make the REPL <em>CLI</em> use the global context so as to (a) be consistent with the
|
||||
<code>node</code> REPL CLI and, therefore, (b) make packages that modify native prototypes
|
||||
@@ -294,21 +296,22 @@ Many flags cause us to divert before compiling anything. Flags passed after
|
||||
<div class="content"><div class='highlight'><pre> replCliOpts = useGlobal: <span class="hljs-literal">yes</span>
|
||||
opts.prelude = makePrelude opts.<span class="hljs-built_in">require</span> <span class="hljs-keyword">if</span> opts.<span class="hljs-built_in">require</span>
|
||||
replCliOpts.prelude = opts.prelude
|
||||
replCliOpts.transpile = opts.transpile
|
||||
<span class="hljs-keyword">return</span> forkNode() <span class="hljs-keyword">if</span> opts.nodejs
|
||||
<span class="hljs-keyword">return</span> usage() <span class="hljs-keyword">if</span> opts.help
|
||||
<span class="hljs-keyword">return</span> version() <span class="hljs-keyword">if</span> opts.version
|
||||
<span class="hljs-keyword">return</span> <span class="hljs-built_in">require</span>(<span class="hljs-string">'./repl'</span>).start(replCliOpts) <span class="hljs-keyword">if</span> opts.interactive
|
||||
<span class="hljs-keyword">return</span> <span class="hljs-built_in">require</span>(<span class="hljs-string">'./repl'</span>).start(replCliOpts) <span class="hljs-keyword">if</span> opts.interactive
|
||||
<span class="hljs-keyword">return</span> compileStdio() <span class="hljs-keyword">if</span> opts.stdio
|
||||
<span class="hljs-keyword">return</span> compileScript <span class="hljs-literal">null</span>, opts.arguments[<span class="hljs-number">0</span>] <span class="hljs-keyword">if</span> opts.eval
|
||||
<span class="hljs-keyword">return</span> <span class="hljs-built_in">require</span>(<span class="hljs-string">'./repl'</span>).start(replCliOpts) <span class="hljs-keyword">unless</span> opts.arguments.length
|
||||
<span class="hljs-keyword">return</span> compileScript <span class="hljs-literal">null</span>, opts.arguments[<span class="hljs-number">0</span>] <span class="hljs-keyword">if</span> opts.<span class="hljs-built_in">eval</span>
|
||||
<span class="hljs-keyword">return</span> <span class="hljs-built_in">require</span>(<span class="hljs-string">'./repl'</span>).start(replCliOpts) <span class="hljs-keyword">unless</span> opts.arguments.length
|
||||
literals = <span class="hljs-keyword">if</span> opts.run <span class="hljs-keyword">then</span> opts.arguments.splice <span class="hljs-number">1</span> <span class="hljs-keyword">else</span> []
|
||||
process.argv = process.argv[<span class="hljs-number">0.</span><span class="hljs-number">.1</span>].concat literals
|
||||
process.argv[<span class="hljs-number">0</span>] = <span class="hljs-string">'coffee'</span>
|
||||
process.argv[<span class="hljs-number">0</span>] = <span class="hljs-string">'coffee'</span>
|
||||
|
||||
<span class="hljs-keyword">if</span> opts.output
|
||||
outputBasename = path.basename opts.output
|
||||
<span class="hljs-keyword">if</span> <span class="hljs-string">'.'</span> <span class="hljs-keyword">in</span> outputBasename <span class="hljs-keyword">and</span>
|
||||
outputBasename <span class="hljs-keyword">not</span> <span class="hljs-keyword">in</span> [<span class="hljs-string">'.'</span>, <span class="hljs-string">'..'</span>] <span class="hljs-keyword">and</span>
|
||||
<span class="hljs-keyword">if</span> <span class="hljs-string">'.'</span> <span class="hljs-keyword">in</span> outputBasename <span class="hljs-keyword">and</span>
|
||||
outputBasename <span class="hljs-keyword">not</span> <span class="hljs-keyword">in</span> [<span class="hljs-string">'.'</span>, <span class="hljs-string">'..'</span>] <span class="hljs-keyword">and</span>
|
||||
<span class="hljs-keyword">not</span> helpers.ends(opts.output, path.sep)</pre></div></div>
|
||||
|
||||
</li>
|
||||
@@ -317,8 +320,8 @@ Many flags cause us to divert before compiling anything. Flags passed after
|
||||
<li id="section-9">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-9">¶</a>
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-9">§</a>
|
||||
</div>
|
||||
<p>An output filename was specified, e.g. <code>/dist/scripts.js</code>.</p>
|
||||
|
||||
@@ -334,8 +337,8 @@ Many flags cause us to divert before compiling anything. Flags passed after
|
||||
<li id="section-10">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-10">¶</a>
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-10">§</a>
|
||||
</div>
|
||||
<p>An output path was specified, e.g. <code>/dist</code>.</p>
|
||||
|
||||
@@ -346,11 +349,11 @@ Many flags cause us to divert before compiling anything. Flags passed after
|
||||
|
||||
<span class="hljs-keyword">if</span> opts.join
|
||||
opts.join = path.resolve opts.join
|
||||
<span class="hljs-built_in">console</span>.error <span class="hljs-string">'''
|
||||
console.error <span class="hljs-string">'''
|
||||
|
||||
The --join option is deprecated and will be removed in a future version.
|
||||
|
||||
If for some reason it's necessary to share local variables between files,
|
||||
If for some reason it's necessary to share local variables between files,
|
||||
replace...
|
||||
|
||||
$ coffee --compile --join bundle.js -- a.coffee b.coffee c.coffee
|
||||
@@ -359,17 +362,17 @@ Many flags cause us to divert before compiling anything. Flags passed after
|
||||
|
||||
$ cat a.coffee b.coffee c.coffee | coffee --compile --stdio > bundle.js
|
||||
|
||||
'''</span>
|
||||
'''</span>
|
||||
<span class="hljs-keyword">for</span> source <span class="hljs-keyword">in</span> opts.arguments
|
||||
source = path.resolve source
|
||||
compilePath source, <span class="hljs-literal">yes</span>, source
|
||||
<span class="hljs-function">
|
||||
<span class="hljs-title">makePrelude</span> = <span class="hljs-params">(requires)</span> -></span>
|
||||
requires.map (<span class="hljs-built_in">module</span>) ->
|
||||
[full, name, <span class="hljs-built_in">module</span>] = match <span class="hljs-keyword">if</span> match = <span class="hljs-built_in">module</span>.match(<span class="hljs-regexp">/^(.*)=(.*)$/</span>)
|
||||
name <span class="hljs-keyword">or</span>= helpers.baseFileName <span class="hljs-built_in">module</span>, <span class="hljs-literal">yes</span>, useWinPathSep
|
||||
<span class="hljs-string">"global['<span class="hljs-subst">#{name}</span>'] = require('<span class="hljs-subst">#{<span class="hljs-built_in">module</span>}</span>')"</span>
|
||||
.join <span class="hljs-string">';'</span></pre></div></div>
|
||||
requires.map (module) ->
|
||||
[full, name, module] = match <span class="hljs-keyword">if</span> match = module.match(<span class="hljs-regexp">/^(.*)=(.*)$/</span>)
|
||||
name <span class="hljs-keyword">or</span>= helpers.baseFileName module, <span class="hljs-literal">yes</span>, useWinPathSep
|
||||
<span class="hljs-string">"global['<span class="hljs-subst">#{name}</span>'] = require('<span class="hljs-subst">#{module}</span>')"</span>
|
||||
.join <span class="hljs-string">';'</span></pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
@@ -377,8 +380,8 @@ Many flags cause us to divert before compiling anything. Flags passed after
|
||||
<li id="section-11">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-11">¶</a>
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-11">§</a>
|
||||
</div>
|
||||
<p>Compile a path, which could be a script or a directory. If a directory
|
||||
is passed, recursively compile all ‘.coffee’, ‘.litcoffee’, and ‘.coffee.md’
|
||||
@@ -393,12 +396,12 @@ extension source files in it and all subdirectories.</p>
|
||||
<span class="hljs-keyword">try</span>
|
||||
stats = fs.statSync source
|
||||
<span class="hljs-keyword">catch</span> err
|
||||
<span class="hljs-keyword">if</span> err.code <span class="hljs-keyword">is</span> <span class="hljs-string">'ENOENT'</span>
|
||||
<span class="hljs-built_in">console</span>.error <span class="hljs-string">"File not found: <span class="hljs-subst">#{source}</span>"</span>
|
||||
<span class="hljs-keyword">if</span> err.code <span class="hljs-keyword">is</span> <span class="hljs-string">'ENOENT'</span>
|
||||
console.error <span class="hljs-string">"File not found: <span class="hljs-subst">#{source}</span>"</span>
|
||||
process.exit <span class="hljs-number">1</span>
|
||||
<span class="hljs-keyword">throw</span> err
|
||||
<span class="hljs-keyword">if</span> stats.isDirectory()
|
||||
<span class="hljs-keyword">if</span> path.basename(source) <span class="hljs-keyword">is</span> <span class="hljs-string">'node_modules'</span>
|
||||
<span class="hljs-keyword">if</span> path.basename(source) <span class="hljs-keyword">is</span> <span class="hljs-string">'node_modules'</span>
|
||||
notSources[source] = <span class="hljs-literal">yes</span>
|
||||
<span class="hljs-keyword">return</span>
|
||||
<span class="hljs-keyword">if</span> opts.run
|
||||
@@ -408,7 +411,7 @@ extension source files in it and all subdirectories.</p>
|
||||
<span class="hljs-keyword">try</span>
|
||||
files = fs.readdirSync source
|
||||
<span class="hljs-keyword">catch</span> err
|
||||
<span class="hljs-keyword">if</span> err.code <span class="hljs-keyword">is</span> <span class="hljs-string">'ENOENT'</span> <span class="hljs-keyword">then</span> <span class="hljs-keyword">return</span> <span class="hljs-keyword">else</span> <span class="hljs-keyword">throw</span> err
|
||||
<span class="hljs-keyword">if</span> err.code <span class="hljs-keyword">is</span> <span class="hljs-string">'ENOENT'</span> <span class="hljs-keyword">then</span> <span class="hljs-keyword">return</span> <span class="hljs-keyword">else</span> <span class="hljs-keyword">throw</span> err
|
||||
<span class="hljs-keyword">for</span> file <span class="hljs-keyword">in</span> files
|
||||
compilePath (path.join source, file), <span class="hljs-literal">no</span>, base
|
||||
<span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> topLevel <span class="hljs-keyword">or</span> helpers.isCoffee source
|
||||
@@ -419,19 +422,19 @@ extension source files in it and all subdirectories.</p>
|
||||
<span class="hljs-keyword">try</span>
|
||||
code = fs.readFileSync source
|
||||
<span class="hljs-keyword">catch</span> err
|
||||
<span class="hljs-keyword">if</span> err.code <span class="hljs-keyword">is</span> <span class="hljs-string">'ENOENT'</span> <span class="hljs-keyword">then</span> <span class="hljs-keyword">return</span> <span class="hljs-keyword">else</span> <span class="hljs-keyword">throw</span> err
|
||||
<span class="hljs-keyword">if</span> err.code <span class="hljs-keyword">is</span> <span class="hljs-string">'ENOENT'</span> <span class="hljs-keyword">then</span> <span class="hljs-keyword">return</span> <span class="hljs-keyword">else</span> <span class="hljs-keyword">throw</span> err
|
||||
compileScript source, code.toString(), base
|
||||
<span class="hljs-keyword">else</span>
|
||||
notSources[source] = <span class="hljs-literal">yes</span>
|
||||
<span class="hljs-function">
|
||||
<span class="hljs-title">findDirectoryIndex</span> = <span class="hljs-params">(source)</span> -></span>
|
||||
<span class="hljs-keyword">for</span> ext <span class="hljs-keyword">in</span> CoffeeScript.FILE_EXTENSIONS
|
||||
index = path.join source, <span class="hljs-string">"index<span class="hljs-subst">#{ext}</span>"</span>
|
||||
index = path.join source, <span class="hljs-string">"index<span class="hljs-subst">#{ext}</span>"</span>
|
||||
<span class="hljs-keyword">try</span>
|
||||
<span class="hljs-keyword">return</span> index <span class="hljs-keyword">if</span> (fs.statSync index).isFile()
|
||||
<span class="hljs-keyword">catch</span> err
|
||||
<span class="hljs-keyword">throw</span> err <span class="hljs-keyword">unless</span> err.code <span class="hljs-keyword">is</span> <span class="hljs-string">'ENOENT'</span>
|
||||
<span class="hljs-built_in">console</span>.error <span class="hljs-string">"Missing index.coffee or index.litcoffee in <span class="hljs-subst">#{source}</span>"</span>
|
||||
<span class="hljs-keyword">throw</span> err <span class="hljs-keyword">unless</span> err.code <span class="hljs-keyword">is</span> <span class="hljs-string">'ENOENT'</span>
|
||||
console.error <span class="hljs-string">"Missing index.coffee or index.litcoffee in <span class="hljs-subst">#{source}</span>"</span>
|
||||
process.exit <span class="hljs-number">1</span></pre></div></div>
|
||||
|
||||
</li>
|
||||
@@ -440,8 +443,8 @@ extension source files in it and all subdirectories.</p>
|
||||
<li id="section-12">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-12">¶</a>
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-12">§</a>
|
||||
</div>
|
||||
<p>Compile a single source script, containing the given code, according to the
|
||||
requested options. If evaluating the script directly, set <code>__filename</code>,
|
||||
@@ -453,14 +456,17 @@ requested options. If evaluating the script directly, set <code>__filename</code
|
||||
options = compileOptions file, base
|
||||
<span class="hljs-keyword">try</span>
|
||||
task = {file, input, options}
|
||||
CoffeeScript.emit <span class="hljs-string">'compile'</span>, task
|
||||
CoffeeScript.emit <span class="hljs-string">'compile'</span>, task
|
||||
<span class="hljs-keyword">if</span> opts.tokens
|
||||
printTokens CoffeeScript.tokens task.input, task.options
|
||||
<span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> opts.nodes
|
||||
printLine CoffeeScript.nodes(task.input, task.options).toString().trim()
|
||||
<span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> opts.ast
|
||||
compiled = CoffeeScript.compile task.input, task.options
|
||||
printLine <span class="hljs-built_in">JSON</span>.stringify(compiled, <span class="hljs-literal">null</span>, <span class="hljs-number">2</span>)
|
||||
<span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> opts.run
|
||||
CoffeeScript.register()
|
||||
CoffeeScript.eval opts.prelude, task.options <span class="hljs-keyword">if</span> opts.prelude
|
||||
CoffeeScript.<span class="hljs-built_in">eval</span> opts.prelude, task.options <span class="hljs-keyword">if</span> opts.prelude
|
||||
CoffeeScript.run task.input, task.options
|
||||
<span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> opts.join <span class="hljs-keyword">and</span> task.file <span class="hljs-keyword">isnt</span> opts.join
|
||||
task.input = helpers.invertLiterate task.input <span class="hljs-keyword">if</span> helpers.isLiterate file
|
||||
@@ -473,7 +479,7 @@ requested options. If evaluating the script directly, set <code>__filename</code
|
||||
task.output = compiled.js
|
||||
task.sourceMap = compiled.v3SourceMap
|
||||
|
||||
CoffeeScript.emit <span class="hljs-string">'success'</span>, task
|
||||
CoffeeScript.emit <span class="hljs-string">'success'</span>, task
|
||||
<span class="hljs-keyword">if</span> opts.<span class="hljs-built_in">print</span>
|
||||
printLine task.output.trim()
|
||||
<span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> opts.compile <span class="hljs-keyword">or</span> opts.map
|
||||
@@ -483,11 +489,11 @@ requested options. If evaluating the script directly, set <code>__filename</code
|
||||
options.jsPath
|
||||
writeJs base, task.file, task.output, saveTo, task.sourceMap
|
||||
<span class="hljs-keyword">catch</span> err
|
||||
CoffeeScript.emit <span class="hljs-string">'failure'</span>, err, task
|
||||
<span class="hljs-keyword">return</span> <span class="hljs-keyword">if</span> CoffeeScript.listeners(<span class="hljs-string">'failure'</span>).length
|
||||
message = err?.stack <span class="hljs-keyword">or</span> <span class="hljs-string">"<span class="hljs-subst">#{err}</span>"</span>
|
||||
CoffeeScript.emit <span class="hljs-string">'failure'</span>, err, task
|
||||
<span class="hljs-keyword">return</span> <span class="hljs-keyword">if</span> CoffeeScript.listeners(<span class="hljs-string">'failure'</span>).length
|
||||
message = err?.stack <span class="hljs-keyword">or</span> <span class="hljs-string">"<span class="hljs-subst">#{err}</span>"</span>
|
||||
<span class="hljs-keyword">if</span> opts.watch
|
||||
printLine message + <span class="hljs-string">'\x07'</span>
|
||||
printLine message + <span class="hljs-string">'\x07'</span>
|
||||
<span class="hljs-keyword">else</span>
|
||||
printWarn message
|
||||
process.exit <span class="hljs-number">1</span></pre></div></div>
|
||||
@@ -498,8 +504,8 @@ requested options. If evaluating the script directly, set <code>__filename</code
|
||||
<li id="section-13">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-13">¶</a>
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-13">§</a>
|
||||
</div>
|
||||
<p>Attach the appropriate listeners to compile scripts incoming over <strong>stdin</strong>,
|
||||
and write them back to <strong>stdout</strong>.</p>
|
||||
@@ -507,11 +513,14 @@ and write them back to <strong>stdout</strong>.</p>
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre><span class="hljs-function"><span class="hljs-title">compileStdio</span> = -></span>
|
||||
<span class="hljs-keyword">if</span> opts.map
|
||||
console.error <span class="hljs-string">'--stdio and --map cannot be used together'</span>
|
||||
process.exit <span class="hljs-number">1</span>
|
||||
buffers = []
|
||||
stdin = process.openStdin()
|
||||
stdin.<span class="hljs-literal">on</span> <span class="hljs-string">'data'</span>, <span class="hljs-function"><span class="hljs-params">(buffer)</span> -></span>
|
||||
stdin.<span class="hljs-literal">on</span> <span class="hljs-string">'data'</span>, <span class="hljs-function"><span class="hljs-params">(buffer)</span> -></span>
|
||||
buffers.push buffer <span class="hljs-keyword">if</span> buffer
|
||||
stdin.<span class="hljs-literal">on</span> <span class="hljs-string">'end'</span>, <span class="hljs-function">-></span>
|
||||
stdin.<span class="hljs-literal">on</span> <span class="hljs-string">'end'</span>, <span class="hljs-function">-></span>
|
||||
compileScript <span class="hljs-literal">null</span>, Buffer.concat(buffers).toString()</pre></div></div>
|
||||
|
||||
</li>
|
||||
@@ -520,8 +529,8 @@ and write them back to <strong>stdout</strong>.</p>
|
||||
<li id="section-14">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-14">¶</a>
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-14">§</a>
|
||||
</div>
|
||||
<p>If all of the source files are done being read, concatenate and compile
|
||||
them together.</p>
|
||||
@@ -532,9 +541,9 @@ them together.</p>
|
||||
<span class="hljs-function"><span class="hljs-title">compileJoin</span> = -></span>
|
||||
<span class="hljs-keyword">return</span> <span class="hljs-keyword">unless</span> opts.join
|
||||
<span class="hljs-keyword">unless</span> sourceCode.some(<span class="hljs-function"><span class="hljs-params">(code)</span> -></span> code <span class="hljs-keyword">is</span> <span class="hljs-literal">null</span>)
|
||||
clearTimeout joinTimeout
|
||||
<span class="hljs-built_in">clearTimeout</span> joinTimeout
|
||||
joinTimeout = wait <span class="hljs-number">100</span>, <span class="hljs-function">-></span>
|
||||
compileScript opts.join, sourceCode.join(<span class="hljs-string">'\n'</span>), opts.join</pre></div></div>
|
||||
compileScript opts.join, sourceCode.join(<span class="hljs-string">'\n'</span>), opts.join</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
@@ -542,8 +551,8 @@ them together.</p>
|
||||
<li id="section-15">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-15">¶</a>
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-15">§</a>
|
||||
</div>
|
||||
<p>Watch a source CoffeeScript file using <code>fs.watch</code>, recompiling it every
|
||||
time the file is updated. May be used in combination with other options,
|
||||
@@ -557,7 +566,7 @@ such as <code>--print</code>.</p>
|
||||
compileTimeout = <span class="hljs-literal">null</span>
|
||||
<span class="hljs-function">
|
||||
<span class="hljs-title">watchErr</span> = <span class="hljs-params">(err)</span> -></span>
|
||||
<span class="hljs-keyword">throw</span> err <span class="hljs-keyword">unless</span> err.code <span class="hljs-keyword">is</span> <span class="hljs-string">'ENOENT'</span>
|
||||
<span class="hljs-keyword">throw</span> err <span class="hljs-keyword">unless</span> err.code <span class="hljs-keyword">is</span> <span class="hljs-string">'ENOENT'</span>
|
||||
<span class="hljs-keyword">return</span> <span class="hljs-keyword">unless</span> source <span class="hljs-keyword">in</span> sources
|
||||
<span class="hljs-keyword">try</span>
|
||||
rewatch()
|
||||
@@ -567,7 +576,7 @@ such as <code>--print</code>.</p>
|
||||
compileJoin()
|
||||
<span class="hljs-function">
|
||||
<span class="hljs-title">compile</span> = -></span>
|
||||
clearTimeout compileTimeout
|
||||
<span class="hljs-built_in">clearTimeout</span> compileTimeout
|
||||
compileTimeout = wait <span class="hljs-number">25</span>, <span class="hljs-function">-></span>
|
||||
fs.stat source, <span class="hljs-function"><span class="hljs-params">(err, stats)</span> -></span>
|
||||
<span class="hljs-keyword">return</span> watchErr err <span class="hljs-keyword">if</span> err
|
||||
@@ -582,9 +591,9 @@ such as <code>--print</code>.</p>
|
||||
<span class="hljs-function">
|
||||
<span class="hljs-title">startWatcher</span> = -></span>
|
||||
watcher = fs.watch source
|
||||
.<span class="hljs-literal">on</span> <span class="hljs-string">'change'</span>, compile
|
||||
.<span class="hljs-literal">on</span> <span class="hljs-string">'error'</span>, <span class="hljs-function"><span class="hljs-params">(err)</span> -></span>
|
||||
<span class="hljs-keyword">throw</span> err <span class="hljs-keyword">unless</span> err.code <span class="hljs-keyword">is</span> <span class="hljs-string">'EPERM'</span>
|
||||
.<span class="hljs-literal">on</span> <span class="hljs-string">'change'</span>, compile
|
||||
.<span class="hljs-literal">on</span> <span class="hljs-string">'error'</span>, <span class="hljs-function"><span class="hljs-params">(err)</span> -></span>
|
||||
<span class="hljs-keyword">throw</span> err <span class="hljs-keyword">unless</span> err.code <span class="hljs-keyword">is</span> <span class="hljs-string">'EPERM'</span>
|
||||
removeSource source, base
|
||||
<span class="hljs-function">
|
||||
<span class="hljs-title">rewatch</span> = -></span>
|
||||
@@ -602,8 +611,8 @@ such as <code>--print</code>.</p>
|
||||
<li id="section-16">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-16">¶</a>
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-16">§</a>
|
||||
</div>
|
||||
<p>Watch a directory of files for new additions.</p>
|
||||
|
||||
@@ -615,16 +624,16 @@ such as <code>--print</code>.</p>
|
||||
<span class="hljs-function">
|
||||
<span class="hljs-title">startWatcher</span> = -></span>
|
||||
watcher = fs.watch source
|
||||
.<span class="hljs-literal">on</span> <span class="hljs-string">'error'</span>, <span class="hljs-function"><span class="hljs-params">(err)</span> -></span>
|
||||
<span class="hljs-keyword">throw</span> err <span class="hljs-keyword">unless</span> err.code <span class="hljs-keyword">is</span> <span class="hljs-string">'EPERM'</span>
|
||||
.<span class="hljs-literal">on</span> <span class="hljs-string">'error'</span>, <span class="hljs-function"><span class="hljs-params">(err)</span> -></span>
|
||||
<span class="hljs-keyword">throw</span> err <span class="hljs-keyword">unless</span> err.code <span class="hljs-keyword">is</span> <span class="hljs-string">'EPERM'</span>
|
||||
stopWatcher()
|
||||
.<span class="hljs-literal">on</span> <span class="hljs-string">'change'</span>, <span class="hljs-function">-></span>
|
||||
clearTimeout readdirTimeout
|
||||
.<span class="hljs-literal">on</span> <span class="hljs-string">'change'</span>, <span class="hljs-function">-></span>
|
||||
<span class="hljs-built_in">clearTimeout</span> readdirTimeout
|
||||
readdirTimeout = wait <span class="hljs-number">25</span>, <span class="hljs-function">-></span>
|
||||
<span class="hljs-keyword">try</span>
|
||||
files = fs.readdirSync source
|
||||
<span class="hljs-keyword">catch</span> err
|
||||
<span class="hljs-keyword">throw</span> err <span class="hljs-keyword">unless</span> err.code <span class="hljs-keyword">is</span> <span class="hljs-string">'ENOENT'</span>
|
||||
<span class="hljs-keyword">throw</span> err <span class="hljs-keyword">unless</span> err.code <span class="hljs-keyword">is</span> <span class="hljs-string">'ENOENT'</span>
|
||||
<span class="hljs-keyword">return</span> stopWatcher()
|
||||
<span class="hljs-keyword">for</span> file <span class="hljs-keyword">in</span> files
|
||||
compilePath (path.join source, file), <span class="hljs-literal">no</span>, base
|
||||
@@ -637,7 +646,7 @@ such as <code>--print</code>.</p>
|
||||
<span class="hljs-keyword">try</span>
|
||||
startWatcher()
|
||||
<span class="hljs-keyword">catch</span> err
|
||||
<span class="hljs-keyword">throw</span> err <span class="hljs-keyword">unless</span> err.code <span class="hljs-keyword">is</span> <span class="hljs-string">'ENOENT'</span>
|
||||
<span class="hljs-keyword">throw</span> err <span class="hljs-keyword">unless</span> err.code <span class="hljs-keyword">is</span> <span class="hljs-string">'ENOENT'</span>
|
||||
<span class="hljs-function">
|
||||
<span class="hljs-title">removeSourceDir</span> = <span class="hljs-params">(source, base)</span> -></span>
|
||||
<span class="hljs-keyword">delete</span> watchedDirs[source]
|
||||
@@ -653,8 +662,8 @@ such as <code>--print</code>.</p>
|
||||
<li id="section-17">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-17">¶</a>
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-17">§</a>
|
||||
</div>
|
||||
<p>Remove a file from our source list, and source code cache. Optionally remove
|
||||
the compiled JS version as well.</p>
|
||||
@@ -667,14 +676,14 @@ the compiled JS version as well.</p>
|
||||
sourceCode.splice index, <span class="hljs-number">1</span>
|
||||
<span class="hljs-keyword">unless</span> opts.join
|
||||
silentUnlink outputPath source, base
|
||||
silentUnlink outputPath source, base, <span class="hljs-string">'.js.map'</span>
|
||||
timeLog <span class="hljs-string">"removed <span class="hljs-subst">#{source}</span>"</span>
|
||||
silentUnlink outputPath source, base, <span class="hljs-string">'.js.map'</span>
|
||||
timeLog <span class="hljs-string">"removed <span class="hljs-subst">#{source}</span>"</span>
|
||||
<span class="hljs-function">
|
||||
<span class="hljs-title">silentUnlink</span> = <span class="hljs-params">(path)</span> -></span>
|
||||
<span class="hljs-keyword">try</span>
|
||||
fs.unlinkSync path
|
||||
<span class="hljs-keyword">catch</span> err
|
||||
<span class="hljs-keyword">throw</span> err <span class="hljs-keyword">unless</span> err.code <span class="hljs-keyword">in</span> [<span class="hljs-string">'ENOENT'</span>, <span class="hljs-string">'EPERM'</span>]</pre></div></div>
|
||||
<span class="hljs-keyword">throw</span> err <span class="hljs-keyword">unless</span> err.code <span class="hljs-keyword">in</span> [<span class="hljs-string">'ENOENT'</span>, <span class="hljs-string">'EPERM'</span>]</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
@@ -682,14 +691,14 @@ the compiled JS version as well.</p>
|
||||
<li id="section-18">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-18">¶</a>
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-18">§</a>
|
||||
</div>
|
||||
<p>Get the corresponding output JavaScript path for a source file.</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre><span class="hljs-function"><span class="hljs-title">outputPath</span> = <span class="hljs-params">(source, base, extension=<span class="hljs-string">".js"</span>)</span> -></span>
|
||||
<div class="content"><div class='highlight'><pre><span class="hljs-function"><span class="hljs-title">outputPath</span> = <span class="hljs-params">(source, base, extension=<span class="hljs-string">".js"</span>)</span> -></span>
|
||||
basename = helpers.baseFileName source, <span class="hljs-literal">yes</span>, useWinPathSep
|
||||
srcDir = path.dirname source
|
||||
dir = <span class="hljs-keyword">unless</span> opts.outputPath
|
||||
@@ -706,8 +715,8 @@ the compiled JS version as well.</p>
|
||||
<li id="section-19">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-19">¶</a>
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-19">§</a>
|
||||
</div>
|
||||
<p>Recursively mkdir, like <code>mkdir -p</code>.</p>
|
||||
|
||||
@@ -732,8 +741,8 @@ the compiled JS version as well.</p>
|
||||
<li id="section-20">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-20">¶</a>
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-20">§</a>
|
||||
</div>
|
||||
<p>Write out a JavaScript source file with the compiled code. By default, files
|
||||
are written out in <code>cwd</code> as <code>.js</code> files with the same name, but the output
|
||||
@@ -744,22 +753,22 @@ same directory as the <code>.js</code> file.</p>
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre><span class="hljs-function"><span class="hljs-title">writeJs</span> = <span class="hljs-params">(base, sourcePath, js, jsPath, generatedSourceMap = <span class="hljs-literal">null</span>)</span> -></span>
|
||||
sourceMapPath = outputPath sourcePath, base, <span class="hljs-string">".js.map"</span>
|
||||
sourceMapPath = <span class="hljs-string">"<span class="hljs-subst">#{jsPath}</span>.map"</span>
|
||||
jsDir = path.dirname jsPath
|
||||
<span class="hljs-function"> <span class="hljs-title">compile</span> = -></span>
|
||||
<span class="hljs-keyword">if</span> opts.compile
|
||||
js = <span class="hljs-string">' '</span> <span class="hljs-keyword">if</span> js.length <= <span class="hljs-number">0</span>
|
||||
<span class="hljs-keyword">if</span> generatedSourceMap <span class="hljs-keyword">then</span> js = <span class="hljs-string">"<span class="hljs-subst">#{js}</span>\n//# sourceMappingURL=<span class="hljs-subst">#{helpers.baseFileName sourceMapPath, <span class="hljs-literal">no</span>, useWinPathSep}</span>\n"</span>
|
||||
js = <span class="hljs-string">' '</span> <span class="hljs-keyword">if</span> js.length <= <span class="hljs-number">0</span>
|
||||
<span class="hljs-keyword">if</span> generatedSourceMap <span class="hljs-keyword">then</span> js = <span class="hljs-string">"<span class="hljs-subst">#{js}</span>\n//# sourceMappingURL=<span class="hljs-subst">#{helpers.baseFileName sourceMapPath, <span class="hljs-literal">no</span>, useWinPathSep}</span>\n"</span>
|
||||
fs.writeFile jsPath, js, <span class="hljs-function"><span class="hljs-params">(err)</span> -></span>
|
||||
<span class="hljs-keyword">if</span> err
|
||||
printLine err.message
|
||||
process.exit <span class="hljs-number">1</span>
|
||||
<span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> opts.compile <span class="hljs-keyword">and</span> opts.watch
|
||||
timeLog <span class="hljs-string">"compiled <span class="hljs-subst">#{sourcePath}</span>"</span>
|
||||
timeLog <span class="hljs-string">"compiled <span class="hljs-subst">#{sourcePath}</span>"</span>
|
||||
<span class="hljs-keyword">if</span> generatedSourceMap
|
||||
fs.writeFile sourceMapPath, generatedSourceMap, <span class="hljs-function"><span class="hljs-params">(err)</span> -></span>
|
||||
<span class="hljs-keyword">if</span> err
|
||||
printLine <span class="hljs-string">"Could not write source map: <span class="hljs-subst">#{err.message}</span>"</span>
|
||||
printLine <span class="hljs-string">"Could not write source map: <span class="hljs-subst">#{err.message}</span>"</span>
|
||||
process.exit <span class="hljs-number">1</span>
|
||||
fs.exists jsDir, <span class="hljs-function"><span class="hljs-params">(itExists)</span> -></span>
|
||||
<span class="hljs-keyword">if</span> itExists <span class="hljs-keyword">then</span> compile() <span class="hljs-keyword">else</span> mkdirp jsDir, compile</pre></div></div>
|
||||
@@ -770,14 +779,14 @@ same directory as the <code>.js</code> file.</p>
|
||||
<li id="section-21">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-21">¶</a>
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-21">§</a>
|
||||
</div>
|
||||
<p>Convenience for cleaner setTimeouts.</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre><span class="hljs-function"><span class="hljs-title">wait</span> = <span class="hljs-params">(milliseconds, func)</span> -></span> setTimeout func, milliseconds</pre></div></div>
|
||||
<div class="content"><div class='highlight'><pre><span class="hljs-function"><span class="hljs-title">wait</span> = <span class="hljs-params">(milliseconds, func)</span> -></span> <span class="hljs-built_in">setTimeout</span> func, milliseconds</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
@@ -785,15 +794,15 @@ same directory as the <code>.js</code> file.</p>
|
||||
<li id="section-22">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-22">¶</a>
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-22">§</a>
|
||||
</div>
|
||||
<p>When watching scripts, it’s useful to log changes with the timestamp.</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre><span class="hljs-function"><span class="hljs-title">timeLog</span> = <span class="hljs-params">(message)</span> -></span>
|
||||
<span class="hljs-built_in">console</span>.log <span class="hljs-string">"<span class="hljs-subst">#{(<span class="hljs-keyword">new</span> Date).toLocaleTimeString()}</span> - <span class="hljs-subst">#{message}</span>"</span></pre></div></div>
|
||||
console.log <span class="hljs-string">"<span class="hljs-subst">#{(<span class="hljs-keyword">new</span> <span class="hljs-built_in">Date</span>).toLocaleTimeString()}</span> - <span class="hljs-subst">#{message}</span>"</span></pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
@@ -801,8 +810,8 @@ same directory as the <code>.js</code> file.</p>
|
||||
<li id="section-23">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-23">¶</a>
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-23">§</a>
|
||||
</div>
|
||||
<p>Pretty-print a stream of tokens, sans location data.</p>
|
||||
|
||||
@@ -811,9 +820,9 @@ same directory as the <code>.js</code> file.</p>
|
||||
<div class="content"><div class='highlight'><pre><span class="hljs-function"><span class="hljs-title">printTokens</span> = <span class="hljs-params">(tokens)</span> -></span>
|
||||
strings = <span class="hljs-keyword">for</span> token <span class="hljs-keyword">in</span> tokens
|
||||
tag = token[<span class="hljs-number">0</span>]
|
||||
value = token[<span class="hljs-number">1</span>].toString().replace(<span class="hljs-regexp">/\n/</span>, <span class="hljs-string">'\\n'</span>)
|
||||
<span class="hljs-string">"[<span class="hljs-subst">#{tag}</span> <span class="hljs-subst">#{value}</span>]"</span>
|
||||
printLine strings.join(<span class="hljs-string">' '</span>)</pre></div></div>
|
||||
value = token[<span class="hljs-number">1</span>].toString().replace(<span class="hljs-regexp">/\n/</span>, <span class="hljs-string">'\\n'</span>)
|
||||
<span class="hljs-string">"[<span class="hljs-subst">#{tag}</span> <span class="hljs-subst">#{value}</span>]"</span>
|
||||
printLine strings.join(<span class="hljs-string">' '</span>)</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
@@ -821,8 +830,8 @@ same directory as the <code>.js</code> file.</p>
|
||||
<li id="section-24">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-24">¶</a>
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-24">§</a>
|
||||
</div>
|
||||
<p>Use the <a href="optparse.html">OptionParser module</a> to extract all options from
|
||||
<code>process.argv</code> that are specified in <code>SWITCHES</code>.</p>
|
||||
@@ -833,7 +842,7 @@ same directory as the <code>.js</code> file.</p>
|
||||
o = opts = optionParser.parse process.argv[<span class="hljs-number">2.</span>.]
|
||||
o.compile <span class="hljs-keyword">or</span>= !!o.output
|
||||
o.run = <span class="hljs-keyword">not</span> (o.compile <span class="hljs-keyword">or</span> o.<span class="hljs-built_in">print</span> <span class="hljs-keyword">or</span> o.map)
|
||||
o.<span class="hljs-built_in">print</span> = !! (o.<span class="hljs-built_in">print</span> <span class="hljs-keyword">or</span> (o.eval <span class="hljs-keyword">or</span> o.stdio <span class="hljs-keyword">and</span> o.compile))</pre></div></div>
|
||||
o.<span class="hljs-built_in">print</span> = !! (o.<span class="hljs-built_in">print</span> <span class="hljs-keyword">or</span> (o.<span class="hljs-built_in">eval</span> <span class="hljs-keyword">or</span> o.stdio <span class="hljs-keyword">and</span> o.compile))</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
@@ -841,22 +850,122 @@ same directory as the <code>.js</code> file.</p>
|
||||
<li id="section-25">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-25">¶</a>
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-25">§</a>
|
||||
</div>
|
||||
<p>The compile-time options to pass to the CoffeeScript compiler.</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre><span class="hljs-function"><span class="hljs-title">compileOptions</span> = <span class="hljs-params">(filename, base)</span> -></span>
|
||||
answer = {
|
||||
filename
|
||||
<span class="hljs-keyword">if</span> opts.transpile</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-26">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-26">§</a>
|
||||
</div>
|
||||
<p>The user has requested that the CoffeeScript compiler also transpile
|
||||
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-keyword">try</span>
|
||||
<span class="hljs-built_in">require</span> <span class="hljs-string">'babel-core'</span>
|
||||
<span class="hljs-keyword">catch</span></pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-27">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-27">§</a>
|
||||
</div>
|
||||
<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">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>
|
||||
console.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 https://coffeescript.org/#transpilation
|
||||
'''</span>
|
||||
<span class="hljs-keyword">else</span>
|
||||
console.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 https://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>
|
||||
|
||||
|
||||
<li id="section-28">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-28">§</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>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre> opts.transpile.transpile = CoffeeScript.transpile</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-29">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-29">§</a>
|
||||
</div>
|
||||
<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> <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>
|
||||
|
||||
answer =
|
||||
filename: filename
|
||||
literate: opts.literate <span class="hljs-keyword">or</span> helpers.isLiterate(filename)
|
||||
bare: opts.bare
|
||||
header: opts.compile <span class="hljs-keyword">and</span> <span class="hljs-keyword">not</span> opts[<span class="hljs-string">'no-header'</span>]
|
||||
header: opts.compile <span class="hljs-keyword">and</span> <span class="hljs-keyword">not</span> opts[<span class="hljs-string">'no-header'</span>]
|
||||
transpile: opts.transpile
|
||||
sourceMap: opts.map
|
||||
inlineMap: opts[<span class="hljs-string">'inline-map'</span>]
|
||||
}
|
||||
inlineMap: opts[<span class="hljs-string">'inline-map'</span>]
|
||||
ast: opts.ast
|
||||
|
||||
<span class="hljs-keyword">if</span> filename
|
||||
<span class="hljs-keyword">if</span> base
|
||||
cwd = process.cwd()
|
||||
@@ -870,19 +979,19 @@ same directory as the <code>.js</code> file.</p>
|
||||
}
|
||||
<span class="hljs-keyword">else</span>
|
||||
answer = helpers.merge answer,
|
||||
sourceRoot: <span class="hljs-string">""</span>
|
||||
sourceRoot: <span class="hljs-string">""</span>
|
||||
sourceFiles: [helpers.baseFileName filename, <span class="hljs-literal">no</span>, useWinPathSep]
|
||||
generatedFile: helpers.baseFileName(filename, <span class="hljs-literal">yes</span>, useWinPathSep) + <span class="hljs-string">".js"</span>
|
||||
generatedFile: helpers.baseFileName(filename, <span class="hljs-literal">yes</span>, useWinPathSep) + <span class="hljs-string">".js"</span>
|
||||
answer</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-26">
|
||||
<li id="section-30">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-26">¶</a>
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-30">§</a>
|
||||
</div>
|
||||
<p>Start up a new Node.js instance with the arguments in <code>--nodejs</code> passed to
|
||||
the <code>node</code> binary, preserving the other options.</p>
|
||||
@@ -892,24 +1001,24 @@ the <code>node</code> binary, preserving the other options.</p>
|
||||
<div class="content"><div class='highlight'><pre><span class="hljs-function"><span class="hljs-title">forkNode</span> = -></span>
|
||||
nodeArgs = opts.nodejs.split <span class="hljs-regexp">/\s+/</span>
|
||||
args = process.argv[<span class="hljs-number">1.</span>.]
|
||||
args.splice args.indexOf(<span class="hljs-string">'--nodejs'</span>), <span class="hljs-number">2</span>
|
||||
args.splice args.indexOf(<span class="hljs-string">'--nodejs'</span>), <span class="hljs-number">2</span>
|
||||
p = spawn process.execPath, nodeArgs.concat(args),
|
||||
cwd: process.cwd()
|
||||
env: process.env
|
||||
stdio: [<span class="hljs-number">0</span>, <span class="hljs-number">1</span>, <span class="hljs-number">2</span>]
|
||||
<span class="hljs-keyword">for</span> signal <span class="hljs-keyword">in</span> [<span class="hljs-string">'SIGINT'</span>, <span class="hljs-string">'SIGTERM'</span>]
|
||||
<span class="hljs-keyword">for</span> signal <span class="hljs-keyword">in</span> [<span class="hljs-string">'SIGINT'</span>, <span class="hljs-string">'SIGTERM'</span>]
|
||||
process.<span class="hljs-literal">on</span> signal, <span class="hljs-keyword">do</span> (signal) ->
|
||||
-> p.kill signal
|
||||
p.<span class="hljs-literal">on</span> <span class="hljs-string">'exit'</span>, <span class="hljs-function"><span class="hljs-params">(code)</span> -></span> process.exit code</pre></div></div>
|
||||
p.<span class="hljs-literal">on</span> <span class="hljs-string">'exit'</span>, <span class="hljs-function"><span class="hljs-params">(code)</span> -></span> process.exit code</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-27">
|
||||
<li id="section-31">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-27">¶</a>
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-31">§</a>
|
||||
</div>
|
||||
<p>Print the <code>--help</code> usage message and exit. Deprecated switches are not
|
||||
shown.</p>
|
||||
@@ -922,18 +1031,18 @@ shown.</p>
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-28">
|
||||
<li id="section-32">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-28">¶</a>
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-32">§</a>
|
||||
</div>
|
||||
<p>Print the <code>--version</code> message and exit.</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre><span class="hljs-function"><span class="hljs-title">version</span> = -></span>
|
||||
printLine <span class="hljs-string">"CoffeeScript version <span class="hljs-subst">#{CoffeeScript.VERSION}</span>"</span></pre></div></div>
|
||||
printLine <span class="hljs-string">"CoffeeScript version <span class="hljs-subst">#{CoffeeScript.VERSION}</span>"</span></pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
@@ -213,7 +213,7 @@ ul.sections > li > div {
|
||||
|
||||
/*---------------------- Low resolutions (> 320px) ---------------------*/
|
||||
@media only screen and (min-width: 320px) {
|
||||
.pilwrap { display: none; }
|
||||
.sswrap { display: none; }
|
||||
|
||||
ul.sections > li > div {
|
||||
display: block;
|
||||
@@ -330,12 +330,12 @@ ul.sections > li > div {
|
||||
box-shadow: none;
|
||||
}
|
||||
|
||||
.pilwrap {
|
||||
.sswrap {
|
||||
position: relative;
|
||||
display: inline;
|
||||
}
|
||||
|
||||
.pilcrow {
|
||||
.ss {
|
||||
font: 12px Arial;
|
||||
text-decoration: none;
|
||||
color: #454545;
|
||||
@@ -345,14 +345,14 @@ ul.sections > li > div {
|
||||
opacity: 0;
|
||||
-webkit-transition: opacity 0.2s linear;
|
||||
}
|
||||
.for-h1 .pilcrow {
|
||||
.for-h1 .ss {
|
||||
top: 47px;
|
||||
}
|
||||
.for-h2 .pilcrow, .for-h3 .pilcrow, .for-h4 .pilcrow {
|
||||
.for-h2 .ss, .for-h3 .ss, .for-h4 .ss {
|
||||
top: 35px;
|
||||
}
|
||||
|
||||
ul.sections > li > div.annotation:hover .pilcrow {
|
||||
ul.sections > li > div.annotation:hover .ss {
|
||||
opacity: 1;
|
||||
}
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -112,8 +112,8 @@
|
||||
<li id="section-1">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-1">¶</a>
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-1">§</a>
|
||||
</div>
|
||||
<p>This file contains the common helper functions that we’d like to share among
|
||||
the <strong>Lexer</strong>, <strong>Rewriter</strong>, and the <strong>Nodes</strong>. Merge objects, flatten
|
||||
@@ -127,14 +127,14 @@ arrays, count characters, that sort of thing.</p>
|
||||
<li id="section-2">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-2">¶</a>
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-2">§</a>
|
||||
</div>
|
||||
<p>Peek at the beginning of a given string to see if it matches a sequence.</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>exports.starts = <span class="hljs-function"><span class="hljs-params">(string, literal, start)</span> -></span>
|
||||
<div class="content"><div class='highlight'><pre><span class="hljs-built_in">exports</span>.starts = <span class="hljs-function"><span class="hljs-params">(string, literal, start)</span> -></span>
|
||||
literal <span class="hljs-keyword">is</span> string.substr start, literal.length</pre></div></div>
|
||||
|
||||
</li>
|
||||
@@ -143,14 +143,14 @@ arrays, count characters, that sort of thing.</p>
|
||||
<li id="section-3">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-3">¶</a>
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-3">§</a>
|
||||
</div>
|
||||
<p>Peek at the end of a given string to see if it matches a sequence.</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>exports.ends = <span class="hljs-function"><span class="hljs-params">(string, literal, back)</span> -></span>
|
||||
<div class="content"><div class='highlight'><pre><span class="hljs-built_in">exports</span>.ends = <span class="hljs-function"><span class="hljs-params">(string, literal, back)</span> -></span>
|
||||
len = literal.length
|
||||
literal <span class="hljs-keyword">is</span> string.substr string.length - len - (back <span class="hljs-keyword">or</span> <span class="hljs-number">0</span>), len</pre></div></div>
|
||||
|
||||
@@ -160,14 +160,14 @@ arrays, count characters, that sort of thing.</p>
|
||||
<li id="section-4">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-4">¶</a>
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-4">§</a>
|
||||
</div>
|
||||
<p>Repeat a string <code>n</code> times.</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>exports.repeat = repeat = <span class="hljs-function"><span class="hljs-params">(str, n)</span> -></span></pre></div></div>
|
||||
<div class="content"><div class='highlight'><pre><span class="hljs-built_in">exports</span>.repeat = repeat = <span class="hljs-function"><span class="hljs-params">(str, n)</span> -></span></pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
@@ -175,14 +175,14 @@ arrays, count characters, that sort of thing.</p>
|
||||
<li id="section-5">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-5">¶</a>
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-5">§</a>
|
||||
</div>
|
||||
<p>Use clever algorithm to have O(log(n)) string concatenation operations.</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre> res = <span class="hljs-string">''</span>
|
||||
<div class="content"><div class='highlight'><pre> res = <span class="hljs-string">''</span>
|
||||
<span class="hljs-keyword">while</span> n > <span class="hljs-number">0</span>
|
||||
res += str <span class="hljs-keyword">if</span> n & <span class="hljs-number">1</span>
|
||||
n >>>= <span class="hljs-number">1</span>
|
||||
@@ -195,14 +195,14 @@ arrays, count characters, that sort of thing.</p>
|
||||
<li id="section-6">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-6">¶</a>
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-6">§</a>
|
||||
</div>
|
||||
<p>Trim out all falsy values from an array.</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>exports.compact = <span class="hljs-function"><span class="hljs-params">(array)</span> -></span>
|
||||
<div class="content"><div class='highlight'><pre><span class="hljs-built_in">exports</span>.compact = <span class="hljs-function"><span class="hljs-params">(array)</span> -></span>
|
||||
item <span class="hljs-keyword">for</span> item <span class="hljs-keyword">in</span> array <span class="hljs-keyword">when</span> item</pre></div></div>
|
||||
|
||||
</li>
|
||||
@@ -211,14 +211,14 @@ arrays, count characters, that sort of thing.</p>
|
||||
<li id="section-7">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-7">¶</a>
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-7">§</a>
|
||||
</div>
|
||||
<p>Count the number of occurrences of a string in a string.</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>exports.count = <span class="hljs-function"><span class="hljs-params">(string, substr)</span> -></span>
|
||||
<div class="content"><div class='highlight'><pre><span class="hljs-built_in">exports</span>.count = <span class="hljs-function"><span class="hljs-params">(string, substr)</span> -></span>
|
||||
num = pos = <span class="hljs-number">0</span>
|
||||
<span class="hljs-keyword">return</span> <span class="hljs-number">1</span>/<span class="hljs-number">0</span> <span class="hljs-keyword">unless</span> substr.length
|
||||
num++ <span class="hljs-keyword">while</span> pos = <span class="hljs-number">1</span> + string.indexOf substr, pos
|
||||
@@ -230,8 +230,8 @@ arrays, count characters, that sort of thing.</p>
|
||||
<li id="section-8">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-8">¶</a>
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-8">§</a>
|
||||
</div>
|
||||
<p>Merge objects, returning a fresh copy with attributes from both sides.
|
||||
Used every time <code>Base#compile</code> is called, to allow properties in the
|
||||
@@ -239,7 +239,7 @@ options hash to propagate down the tree without polluting other branches.</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>exports.merge = <span class="hljs-function"><span class="hljs-params">(options, overrides)</span> -></span>
|
||||
<div class="content"><div class='highlight'><pre><span class="hljs-built_in">exports</span>.merge = <span class="hljs-function"><span class="hljs-params">(options, overrides)</span> -></span>
|
||||
extend (extend {}, options), overrides</pre></div></div>
|
||||
|
||||
</li>
|
||||
@@ -248,14 +248,14 @@ options hash to propagate down the tree without polluting other branches.</p>
|
||||
<li id="section-9">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-9">¶</a>
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-9">§</a>
|
||||
</div>
|
||||
<p>Extend a source object with the properties of another object (shallow copy).</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>extend = exports.extend = <span class="hljs-function"><span class="hljs-params">(object, properties)</span> -></span>
|
||||
<div class="content"><div class='highlight'><pre>extend = <span class="hljs-built_in">exports</span>.extend = <span class="hljs-function"><span class="hljs-params">(object, properties)</span> -></span>
|
||||
<span class="hljs-keyword">for</span> key, val <span class="hljs-keyword">of</span> properties
|
||||
object[key] = val
|
||||
object</pre></div></div>
|
||||
@@ -266,18 +266,18 @@ options hash to propagate down the tree without polluting other branches.</p>
|
||||
<li id="section-10">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-10">¶</a>
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-10">§</a>
|
||||
</div>
|
||||
<p>Return a flattened version of an array.
|
||||
Handy for getting a list of <code>children</code> from the nodes.</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>exports.flatten = flatten = <span class="hljs-function"><span class="hljs-params">(array)</span> -></span>
|
||||
<div class="content"><div class='highlight'><pre><span class="hljs-built_in">exports</span>.flatten = flatten = <span class="hljs-function"><span class="hljs-params">(array)</span> -></span>
|
||||
flattened = []
|
||||
<span class="hljs-keyword">for</span> element <span class="hljs-keyword">in</span> array
|
||||
<span class="hljs-keyword">if</span> <span class="hljs-string">'[object Array]'</span> <span class="hljs-keyword">is</span> Object::toString.call element
|
||||
<span class="hljs-keyword">if</span> <span class="hljs-string">'[object Array]'</span> <span class="hljs-keyword">is</span> Object::toString.call element
|
||||
flattened = flattened.concat flatten element
|
||||
<span class="hljs-keyword">else</span>
|
||||
flattened.push element
|
||||
@@ -289,15 +289,15 @@ Handy for getting a list of <code>children</code> from the nodes.</p>
|
||||
<li id="section-11">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-11">¶</a>
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-11">§</a>
|
||||
</div>
|
||||
<p>Delete a key from an object, returning the value. Useful when a node is
|
||||
looking for a particular method in an options hash.</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>exports.del = <span class="hljs-function"><span class="hljs-params">(obj, key)</span> -></span>
|
||||
<div class="content"><div class='highlight'><pre><span class="hljs-built_in">exports</span>.del = <span class="hljs-function"><span class="hljs-params">(obj, key)</span> -></span>
|
||||
val = obj[key]
|
||||
<span class="hljs-keyword">delete</span> obj[key]
|
||||
val</pre></div></div>
|
||||
@@ -308,15 +308,15 @@ looking for a particular method in an options hash.</p>
|
||||
<li id="section-12">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-12">¶</a>
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-12">§</a>
|
||||
</div>
|
||||
<p>Typical Array::some</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>exports.some = Array::some ? (fn) ->
|
||||
<span class="hljs-keyword">return</span> <span class="hljs-literal">true</span> <span class="hljs-keyword">for</span> e <span class="hljs-keyword">in</span> <span class="hljs-keyword">this</span> <span class="hljs-keyword">when</span> fn e
|
||||
<div class="content"><div class='highlight'><pre><span class="hljs-built_in">exports</span>.some = Array::some ? (fn) ->
|
||||
<span class="hljs-keyword">return</span> <span class="hljs-literal">true</span> <span class="hljs-keyword">for</span> e <span class="hljs-keyword">in</span> this <span class="hljs-keyword">when</span> fn e
|
||||
<span class="hljs-literal">false</span></pre></div></div>
|
||||
|
||||
</li>
|
||||
@@ -325,8 +325,8 @@ looking for a particular method in an options hash.</p>
|
||||
<li id="section-13">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-13">¶</a>
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-13">§</a>
|
||||
</div>
|
||||
<p>Helper function for extracting code from Literate CoffeeScript by stripping
|
||||
out all non-code blocks, producing a string of CoffeeScript code that can
|
||||
@@ -334,7 +334,7 @@ be compiled “normally.”</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>exports.invertLiterate = <span class="hljs-function"><span class="hljs-params">(code)</span> -></span>
|
||||
<div class="content"><div class='highlight'><pre><span class="hljs-built_in">exports</span>.invertLiterate = <span class="hljs-function"><span class="hljs-params">(code)</span> -></span>
|
||||
out = []
|
||||
blankLine = <span class="hljs-regexp">/^\s*$/</span>
|
||||
indented = <span class="hljs-regexp">/^[\t ]/</span>
|
||||
@@ -347,19 +347,19 @@ be compiled “normally.”</p>
|
||||
[\ \t] <span class="hljs-comment"># followed by a space or a tab.</span>
|
||||
///</span>
|
||||
insideComment = <span class="hljs-literal">no</span>
|
||||
<span class="hljs-keyword">for</span> line <span class="hljs-keyword">in</span> code.split(<span class="hljs-string">'\n'</span>)
|
||||
<span class="hljs-keyword">for</span> line <span class="hljs-keyword">in</span> code.split(<span class="hljs-string">'\n'</span>)
|
||||
<span class="hljs-keyword">if</span> blankLine.test(line)
|
||||
insideComment = <span class="hljs-literal">no</span>
|
||||
out.push line
|
||||
<span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> insideComment <span class="hljs-keyword">or</span> listItemStart.test(line)
|
||||
insideComment = <span class="hljs-literal">yes</span>
|
||||
out.push <span class="hljs-string">"# <span class="hljs-subst">#{line}</span>"</span>
|
||||
out.push <span class="hljs-string">"# <span class="hljs-subst">#{line}</span>"</span>
|
||||
<span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> <span class="hljs-keyword">not</span> insideComment <span class="hljs-keyword">and</span> indented.test(line)
|
||||
out.push line
|
||||
<span class="hljs-keyword">else</span>
|
||||
insideComment = <span class="hljs-literal">yes</span>
|
||||
out.push <span class="hljs-string">"# <span class="hljs-subst">#{line}</span>"</span>
|
||||
out.join <span class="hljs-string">'\n'</span></pre></div></div>
|
||||
out.push <span class="hljs-string">"# <span class="hljs-subst">#{line}</span>"</span>
|
||||
out.join <span class="hljs-string">'\n'</span></pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
@@ -367,8 +367,8 @@ be compiled “normally.”</p>
|
||||
<li id="section-14">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-14">¶</a>
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-14">§</a>
|
||||
</div>
|
||||
<p>Merge two jison-style location data objects together.
|
||||
If <code>last</code> is not provided, this will simply return <code>first</code>.</p>
|
||||
@@ -383,9 +383,12 @@ If <code>last</code> is not provided, this will simply return <code>first</code>
|
||||
first_column: first.first_column
|
||||
last_line: last.last_line
|
||||
last_column: last.last_column
|
||||
<span class="hljs-function">
|
||||
<span class="hljs-title">buildLocationHash</span> = <span class="hljs-params">(loc)</span> -></span>
|
||||
<span class="hljs-string">"<span class="hljs-subst">#{loc.first_line}</span>x<span class="hljs-subst">#{loc.first_column}</span>-<span class="hljs-subst">#{loc.last_line}</span>x<span class="hljs-subst">#{loc.last_column}</span>"</span></pre></div></div>
|
||||
last_line_exclusive: last.last_line_exclusive
|
||||
last_column_exclusive: last.last_column_exclusive
|
||||
range: [
|
||||
first.range[<span class="hljs-number">0</span>]
|
||||
last.range[<span class="hljs-number">1</span>]
|
||||
]</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
@@ -393,17 +396,22 @@ If <code>last</code> is not provided, this will simply return <code>first</code>
|
||||
<li id="section-15">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-15">¶</a>
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-15">§</a>
|
||||
</div>
|
||||
<p>This returns a function which takes an object as a parameter, and if that
|
||||
object is an AST node, updates that object’s locationData.
|
||||
The object is returned either way.</p>
|
||||
<p>Build a list of all comments attached to tokens.</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>exports.addDataToNode = <span class="hljs-function"><span class="hljs-params">(parserState, first, last)</span> -></span>
|
||||
(obj) -></pre></div></div>
|
||||
<div class="content"><div class='highlight'><pre><span class="hljs-built_in">exports</span>.extractAllCommentTokens = <span class="hljs-function"><span class="hljs-params">(tokens)</span> -></span>
|
||||
allCommentsObj = {}
|
||||
<span class="hljs-keyword">for</span> token <span class="hljs-keyword">in</span> tokens <span class="hljs-keyword">when</span> token.comments
|
||||
<span class="hljs-keyword">for</span> comment <span class="hljs-keyword">in</span> token.comments
|
||||
commentKey = comment.locationData.range[<span class="hljs-number">0</span>]
|
||||
allCommentsObj[commentKey] = comment
|
||||
sortedKeys = <span class="hljs-built_in">Object</span>.keys(allCommentsObj).sort (a, b) -> a - b
|
||||
<span class="hljs-keyword">for</span> key <span class="hljs-keyword">in</span> sortedKeys
|
||||
allCommentsObj[key]</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
@@ -411,15 +419,18 @@ The object is returned either way.</p>
|
||||
<li id="section-16">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-16">¶</a>
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-16">§</a>
|
||||
</div>
|
||||
<p>Add location data</p>
|
||||
<p>Get a lookup hash for a token based on its location data.
|
||||
Multiple tokens might have the same location hash, but using exclusive
|
||||
location data distinguishes e.g. zero-length generated tokens from
|
||||
actual source tokens.</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre> <span class="hljs-keyword">if</span> obj?.updateLocationDataIfMissing? <span class="hljs-keyword">and</span> first?
|
||||
obj.updateLocationDataIfMissing buildLocationData(first, last)</pre></div></div>
|
||||
<div class="content"><div class='highlight'><pre><span class="hljs-function"><span class="hljs-title">buildLocationHash</span> = <span class="hljs-params">(loc)</span> -></span>
|
||||
<span class="hljs-string">"<span class="hljs-subst">#{loc.range[<span class="hljs-number">0</span>]}</span>-<span class="hljs-subst">#{loc.range[<span class="hljs-number">1</span>]}</span>"</span></pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
@@ -427,33 +438,18 @@ The object is returned either way.</p>
|
||||
<li id="section-17">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-17">¶</a>
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-17">§</a>
|
||||
</div>
|
||||
<p>Add comments data</p>
|
||||
<p>Build a dictionary of extra token properties organized by tokens’ locations
|
||||
used as lookup hashes.</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre> <span class="hljs-keyword">unless</span> parserState.tokenComments
|
||||
parserState.tokenComments = {}
|
||||
<span class="hljs-keyword">for</span> token <span class="hljs-keyword">in</span> parserState.parser.tokens <span class="hljs-keyword">when</span> token.comments
|
||||
tokenHash = buildLocationHash token[<span class="hljs-number">2</span>]
|
||||
<span class="hljs-keyword">unless</span> parserState.tokenComments[tokenHash]?
|
||||
parserState.tokenComments[tokenHash] = token.comments
|
||||
<span class="hljs-keyword">else</span>
|
||||
parserState.tokenComments[tokenHash].push token.comments...
|
||||
|
||||
<span class="hljs-keyword">if</span> obj.locationData?
|
||||
objHash = buildLocationHash obj.locationData
|
||||
<span class="hljs-keyword">if</span> parserState.tokenComments[objHash]?
|
||||
attachCommentsToNode parserState.tokenComments[objHash], obj
|
||||
|
||||
obj
|
||||
|
||||
exports.attachCommentsToNode = attachCommentsToNode = <span class="hljs-function"><span class="hljs-params">(comments, node)</span> -></span>
|
||||
<span class="hljs-keyword">return</span> <span class="hljs-keyword">if</span> <span class="hljs-keyword">not</span> comments? <span class="hljs-keyword">or</span> comments.length <span class="hljs-keyword">is</span> <span class="hljs-number">0</span>
|
||||
node.comments ?= []
|
||||
node.comments.push comments...</pre></div></div>
|
||||
<div class="content"><div class='highlight'><pre><span class="hljs-built_in">exports</span>.buildTokenDataDictionary = buildTokenDataDictionary = <span class="hljs-function"><span class="hljs-params">(tokens)</span> -></span>
|
||||
tokenData = {}
|
||||
<span class="hljs-keyword">for</span> token <span class="hljs-keyword">in</span> tokens <span class="hljs-keyword">when</span> token.comments
|
||||
tokenHash = buildLocationHash token[<span class="hljs-number">2</span>]</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
@@ -461,23 +457,17 @@ exports.attachCommentsToNode = attachCommentsToNode = <span class="hljs-function
|
||||
<li id="section-18">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-18">¶</a>
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-18">§</a>
|
||||
</div>
|
||||
<p>Convert jison location data to a string.
|
||||
<code>obj</code> can be a token, or a locationData.</p>
|
||||
<p>Multiple tokens might have the same location hash, such as the generated
|
||||
<code>JS</code> tokens added at the start or end of the token stream to hold
|
||||
comments that start or end a file.</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>exports.locationDataToString = <span class="hljs-function"><span class="hljs-params">(obj)</span> -></span>
|
||||
<span class="hljs-keyword">if</span> (<span class="hljs-string">"2"</span> <span class="hljs-keyword">of</span> obj) <span class="hljs-keyword">and</span> (<span class="hljs-string">"first_line"</span> <span class="hljs-keyword">of</span> obj[<span class="hljs-number">2</span>]) <span class="hljs-keyword">then</span> locationData = obj[<span class="hljs-number">2</span>]
|
||||
<span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> <span class="hljs-string">"first_line"</span> <span class="hljs-keyword">of</span> obj <span class="hljs-keyword">then</span> locationData = obj
|
||||
|
||||
<span class="hljs-keyword">if</span> locationData
|
||||
<span class="hljs-string">"<span class="hljs-subst">#{locationData.first_line + <span class="hljs-number">1</span>}</span>:<span class="hljs-subst">#{locationData.first_column + <span class="hljs-number">1</span>}</span>-"</span> +
|
||||
<span class="hljs-string">"<span class="hljs-subst">#{locationData.last_line + <span class="hljs-number">1</span>}</span>:<span class="hljs-subst">#{locationData.last_column + <span class="hljs-number">1</span>}</span>"</span>
|
||||
<span class="hljs-keyword">else</span>
|
||||
<span class="hljs-string">"No location data"</span></pre></div></div>
|
||||
<div class="content"><div class='highlight'><pre> tokenData[tokenHash] ?= {}
|
||||
<span class="hljs-keyword">if</span> token.comments <span class="hljs-comment"># `comments` is always an array.</span></pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
@@ -485,22 +475,18 @@ exports.attachCommentsToNode = attachCommentsToNode = <span class="hljs-function
|
||||
<li id="section-19">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-19">¶</a>
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-19">§</a>
|
||||
</div>
|
||||
<p>A <code>.coffee.md</code> compatible version of <code>basename</code>, that returns the file sans-extension.</p>
|
||||
<p>For “overlapping” tokens, that is tokens with the same location data
|
||||
and therefore matching <code>tokenHash</code>es, merge the comments from both/all
|
||||
tokens together into one array, even if there are duplicate comments;
|
||||
they will get sorted out later.</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>exports.baseFileName = <span class="hljs-function"><span class="hljs-params">(file, stripExt = <span class="hljs-literal">no</span>, useWinPathSep = <span class="hljs-literal">no</span>)</span> -></span>
|
||||
pathSep = <span class="hljs-keyword">if</span> useWinPathSep <span class="hljs-keyword">then</span> <span class="hljs-regexp">/\\|\//</span> <span class="hljs-keyword">else</span> <span class="hljs-regexp">/\//</span>
|
||||
parts = file.split(pathSep)
|
||||
file = parts[parts.length - <span class="hljs-number">1</span>]
|
||||
<span class="hljs-keyword">return</span> file <span class="hljs-keyword">unless</span> stripExt <span class="hljs-keyword">and</span> file.indexOf(<span class="hljs-string">'.'</span>) >= <span class="hljs-number">0</span>
|
||||
parts = file.split(<span class="hljs-string">'.'</span>)
|
||||
parts.pop()
|
||||
parts.pop() <span class="hljs-keyword">if</span> parts[parts.length - <span class="hljs-number">1</span>] <span class="hljs-keyword">is</span> <span class="hljs-string">'coffee'</span> <span class="hljs-keyword">and</span> parts.length > <span class="hljs-number">1</span>
|
||||
parts.join(<span class="hljs-string">'.'</span>)</pre></div></div>
|
||||
<div class="content"><div class='highlight'><pre> (tokenData[tokenHash].comments ?= []).push token.comments...
|
||||
tokenData</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
@@ -508,14 +494,17 @@ exports.attachCommentsToNode = attachCommentsToNode = <span class="hljs-function
|
||||
<li id="section-20">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-20">¶</a>
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-20">§</a>
|
||||
</div>
|
||||
<p>Determine if a filename represents a CoffeeScript file.</p>
|
||||
<p>This returns a function which takes an object as a parameter, and if that
|
||||
object is an AST node, updates that object’s locationData.
|
||||
The object is returned either way.</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>exports.isCoffee = <span class="hljs-function"><span class="hljs-params">(file)</span> -></span> <span class="hljs-regexp">/\.((lit)?coffee|coffee\.md)$/</span>.test file</pre></div></div>
|
||||
<div class="content"><div class='highlight'><pre><span class="hljs-built_in">exports</span>.addDataToNode = <span class="hljs-function"><span class="hljs-params">(parserState, firstLocationData, firstValue, lastLocationData, lastValue, forceUpdateLocation = <span class="hljs-literal">yes</span>)</span> -></span>
|
||||
(obj) -></pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
@@ -523,14 +512,18 @@ exports.attachCommentsToNode = attachCommentsToNode = <span class="hljs-function
|
||||
<li id="section-21">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-21">¶</a>
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-21">§</a>
|
||||
</div>
|
||||
<p>Determine if a filename represents a Literate CoffeeScript file.</p>
|
||||
<p>Add location data.</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>exports.isLiterate = <span class="hljs-function"><span class="hljs-params">(file)</span> -></span> <span class="hljs-regexp">/\.(litcoffee|coffee\.md)$/</span>.test file</pre></div></div>
|
||||
<div class="content"><div class='highlight'><pre> locationData = buildLocationData(firstValue?.locationData ? firstLocationData, lastValue?.locationData ? lastLocationData)
|
||||
<span class="hljs-keyword">if</span> obj?.updateLocationDataIfMissing? <span class="hljs-keyword">and</span> firstLocationData?
|
||||
obj.updateLocationDataIfMissing locationData, forceUpdateLocation
|
||||
<span class="hljs-keyword">else</span>
|
||||
obj.locationData = locationData</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
@@ -538,8 +531,111 @@ exports.attachCommentsToNode = attachCommentsToNode = <span class="hljs-function
|
||||
<li id="section-22">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-22">¶</a>
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-22">§</a>
|
||||
</div>
|
||||
<p>Add comments, building the dictionary of token data if it hasn’t been
|
||||
built yet.</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre> parserState.tokenData ?= buildTokenDataDictionary parserState.parser.tokens
|
||||
<span class="hljs-keyword">if</span> obj.locationData?
|
||||
objHash = buildLocationHash obj.locationData
|
||||
<span class="hljs-keyword">if</span> parserState.tokenData[objHash]?.comments?
|
||||
attachCommentsToNode parserState.tokenData[objHash].comments, obj
|
||||
obj
|
||||
|
||||
<span class="hljs-built_in">exports</span>.attachCommentsToNode = attachCommentsToNode = <span class="hljs-function"><span class="hljs-params">(comments, node)</span> -></span>
|
||||
<span class="hljs-keyword">return</span> <span class="hljs-keyword">if</span> <span class="hljs-keyword">not</span> comments? <span class="hljs-keyword">or</span> comments.length <span class="hljs-keyword">is</span> <span class="hljs-number">0</span>
|
||||
node.comments ?= []
|
||||
node.comments.push comments...</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-23">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-23">§</a>
|
||||
</div>
|
||||
<p>Convert jison location data to a string.
|
||||
<code>obj</code> can be a token, or a locationData.</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre><span class="hljs-built_in">exports</span>.locationDataToString = <span class="hljs-function"><span class="hljs-params">(obj)</span> -></span>
|
||||
<span class="hljs-keyword">if</span> (<span class="hljs-string">"2"</span> <span class="hljs-keyword">of</span> obj) <span class="hljs-keyword">and</span> (<span class="hljs-string">"first_line"</span> <span class="hljs-keyword">of</span> obj[<span class="hljs-number">2</span>]) <span class="hljs-keyword">then</span> locationData = obj[<span class="hljs-number">2</span>]
|
||||
<span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> <span class="hljs-string">"first_line"</span> <span class="hljs-keyword">of</span> obj <span class="hljs-keyword">then</span> locationData = obj
|
||||
|
||||
<span class="hljs-keyword">if</span> locationData
|
||||
<span class="hljs-string">"<span class="hljs-subst">#{locationData.first_line + <span class="hljs-number">1</span>}</span>:<span class="hljs-subst">#{locationData.first_column + <span class="hljs-number">1</span>}</span>-"</span> +
|
||||
<span class="hljs-string">"<span class="hljs-subst">#{locationData.last_line + <span class="hljs-number">1</span>}</span>:<span class="hljs-subst">#{locationData.last_column + <span class="hljs-number">1</span>}</span>"</span>
|
||||
<span class="hljs-keyword">else</span>
|
||||
<span class="hljs-string">"No location data"</span></pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-24">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-24">§</a>
|
||||
</div>
|
||||
<p>A <code>.coffee.md</code> compatible version of <code>basename</code>, that returns the file sans-extension.</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre><span class="hljs-built_in">exports</span>.baseFileName = <span class="hljs-function"><span class="hljs-params">(file, stripExt = <span class="hljs-literal">no</span>, useWinPathSep = <span class="hljs-literal">no</span>)</span> -></span>
|
||||
pathSep = <span class="hljs-keyword">if</span> useWinPathSep <span class="hljs-keyword">then</span> <span class="hljs-regexp">/\\|\//</span> <span class="hljs-keyword">else</span> <span class="hljs-regexp">/\//</span>
|
||||
parts = file.split(pathSep)
|
||||
file = parts[parts.length - <span class="hljs-number">1</span>]
|
||||
<span class="hljs-keyword">return</span> file <span class="hljs-keyword">unless</span> stripExt <span class="hljs-keyword">and</span> file.indexOf(<span class="hljs-string">'.'</span>) >= <span class="hljs-number">0</span>
|
||||
parts = file.split(<span class="hljs-string">'.'</span>)
|
||||
parts.pop()
|
||||
parts.pop() <span class="hljs-keyword">if</span> parts[parts.length - <span class="hljs-number">1</span>] <span class="hljs-keyword">is</span> <span class="hljs-string">'coffee'</span> <span class="hljs-keyword">and</span> parts.length > <span class="hljs-number">1</span>
|
||||
parts.join(<span class="hljs-string">'.'</span>)</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-25">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-25">§</a>
|
||||
</div>
|
||||
<p>Determine if a filename represents a CoffeeScript file.</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre><span class="hljs-built_in">exports</span>.isCoffee = <span class="hljs-function"><span class="hljs-params">(file)</span> -></span> <span class="hljs-regexp">/\.((lit)?coffee|coffee\.md)$/</span>.test file</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-26">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-26">§</a>
|
||||
</div>
|
||||
<p>Determine if a filename represents a Literate CoffeeScript file.</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre><span class="hljs-built_in">exports</span>.isLiterate = <span class="hljs-function"><span class="hljs-params">(file)</span> -></span> <span class="hljs-regexp">/\.(litcoffee|coffee\.md)$/</span>.test file</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-27">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-27">§</a>
|
||||
</div>
|
||||
<p>Throws a SyntaxError from a given location.
|
||||
The error’s <code>toString</code> will return an error message following the “standard”
|
||||
@@ -548,19 +644,19 @@ marker showing where the error is.</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>exports.throwSyntaxError = <span class="hljs-function"><span class="hljs-params">(message, location)</span> -></span>
|
||||
error = <span class="hljs-keyword">new</span> SyntaxError message
|
||||
<div class="content"><div class='highlight'><pre><span class="hljs-built_in">exports</span>.throwSyntaxError = <span class="hljs-function"><span class="hljs-params">(message, location)</span> -></span>
|
||||
error = <span class="hljs-keyword">new</span> <span class="hljs-built_in">SyntaxError</span> message
|
||||
error.location = location
|
||||
error.toString = syntaxErrorToString</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-23">
|
||||
<li id="section-28">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-23">¶</a>
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-28">§</a>
|
||||
</div>
|
||||
<p>Instead of showing the compiler’s stacktrace, show our custom error message
|
||||
(this is useful when the error bubbles up in Node.js applications that
|
||||
@@ -575,27 +671,27 @@ compile CoffeeScript for example).</p>
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-24">
|
||||
<li id="section-29">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-24">¶</a>
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-29">§</a>
|
||||
</div>
|
||||
<p>Update a compiler SyntaxError with source code information if it didn’t have
|
||||
it already.</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>exports.updateSyntaxError = <span class="hljs-function"><span class="hljs-params">(error, code, filename)</span> -></span></pre></div></div>
|
||||
<div class="content"><div class='highlight'><pre><span class="hljs-built_in">exports</span>.updateSyntaxError = <span class="hljs-function"><span class="hljs-params">(error, code, filename)</span> -></span></pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-25">
|
||||
<li id="section-30">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-25">¶</a>
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-30">§</a>
|
||||
</div>
|
||||
<p>Avoid screwing up the <code>stack</code> property of other errors (i.e. possible bugs).</p>
|
||||
|
||||
@@ -614,34 +710,34 @@ it already.</p>
|
||||
last_line ?= first_line
|
||||
last_column ?= first_column
|
||||
|
||||
filename = @filename <span class="hljs-keyword">or</span> <span class="hljs-string">'[stdin]'</span>
|
||||
codeLine = @code.split(<span class="hljs-string">'\n'</span>)[first_line]
|
||||
filename = @filename <span class="hljs-keyword">or</span> <span class="hljs-string">'[stdin]'</span>
|
||||
codeLine = @code.split(<span class="hljs-string">'\n'</span>)[first_line]
|
||||
start = first_column</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-26">
|
||||
<li id="section-31">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-26">¶</a>
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-31">§</a>
|
||||
</div>
|
||||
<p>Show only the first line on multi-line errors.</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre> end = <span class="hljs-keyword">if</span> first_line <span class="hljs-keyword">is</span> last_line <span class="hljs-keyword">then</span> last_column + <span class="hljs-number">1</span> <span class="hljs-keyword">else</span> codeLine.length
|
||||
marker = codeLine[...start].replace(<span class="hljs-regexp">/[^\s]/g</span>, <span class="hljs-string">' '</span>) + repeat(<span class="hljs-string">'^'</span>, end - start)</pre></div></div>
|
||||
marker = codeLine[...start].replace(<span class="hljs-regexp">/[^\s]/g</span>, <span class="hljs-string">' '</span>) + repeat(<span class="hljs-string">'^'</span>, end - start)</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-27">
|
||||
<li id="section-32">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-27">¶</a>
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-32">§</a>
|
||||
</div>
|
||||
<p>Check to see if we’re running on a color-enabled TTY.</p>
|
||||
|
||||
@@ -651,23 +747,99 @@ it already.</p>
|
||||
colorsEnabled = process.stdout?.isTTY <span class="hljs-keyword">and</span> <span class="hljs-keyword">not</span> process.env?.NODE_DISABLE_COLORS
|
||||
|
||||
<span class="hljs-keyword">if</span> @colorful ? colorsEnabled
|
||||
<span class="hljs-function"> <span class="hljs-title">colorize</span> = <span class="hljs-params">(str)</span> -></span> <span class="hljs-string">"\x1B[1;31m<span class="hljs-subst">#{str}</span>\x1B[0m"</span>
|
||||
<span class="hljs-function"> <span class="hljs-title">colorize</span> = <span class="hljs-params">(str)</span> -></span> <span class="hljs-string">"\x1B[1;31m<span class="hljs-subst">#{str}</span>\x1B[0m"</span>
|
||||
codeLine = codeLine[...start] + colorize(codeLine[start...end]) + codeLine[end..]
|
||||
marker = colorize marker
|
||||
|
||||
<span class="hljs-string">"""
|
||||
<span class="hljs-string">"""
|
||||
<span class="hljs-subst">#{filename}</span>:<span class="hljs-subst">#{first_line + <span class="hljs-number">1</span>}</span>:<span class="hljs-subst">#{first_column + <span class="hljs-number">1</span>}</span>: error: <span class="hljs-subst">#{@message}</span>
|
||||
<span class="hljs-subst">#{codeLine}</span>
|
||||
<span class="hljs-subst">#{marker}</span>
|
||||
"""</span>
|
||||
"""</span>
|
||||
|
||||
exports.nameWhitespaceCharacter = <span class="hljs-function"><span class="hljs-params">(string)</span> -></span>
|
||||
<span class="hljs-built_in">exports</span>.nameWhitespaceCharacter = <span class="hljs-function"><span class="hljs-params">(string)</span> -></span>
|
||||
<span class="hljs-keyword">switch</span> string
|
||||
<span class="hljs-keyword">when</span> <span class="hljs-string">' '</span> <span class="hljs-keyword">then</span> <span class="hljs-string">'space'</span>
|
||||
<span class="hljs-keyword">when</span> <span class="hljs-string">'\n'</span> <span class="hljs-keyword">then</span> <span class="hljs-string">'newline'</span>
|
||||
<span class="hljs-keyword">when</span> <span class="hljs-string">'\r'</span> <span class="hljs-keyword">then</span> <span class="hljs-string">'carriage return'</span>
|
||||
<span class="hljs-keyword">when</span> <span class="hljs-string">'\t'</span> <span class="hljs-keyword">then</span> <span class="hljs-string">'tab'</span>
|
||||
<span class="hljs-keyword">else</span> string</pre></div></div>
|
||||
<span class="hljs-keyword">when</span> <span class="hljs-string">' '</span> <span class="hljs-keyword">then</span> <span class="hljs-string">'space'</span>
|
||||
<span class="hljs-keyword">when</span> <span class="hljs-string">'\n'</span> <span class="hljs-keyword">then</span> <span class="hljs-string">'newline'</span>
|
||||
<span class="hljs-keyword">when</span> <span class="hljs-string">'\r'</span> <span class="hljs-keyword">then</span> <span class="hljs-string">'carriage return'</span>
|
||||
<span class="hljs-keyword">when</span> <span class="hljs-string">'\t'</span> <span class="hljs-keyword">then</span> <span class="hljs-string">'tab'</span>
|
||||
<span class="hljs-keyword">else</span> string
|
||||
|
||||
<span class="hljs-built_in">exports</span>.parseNumber = <span class="hljs-function"><span class="hljs-params">(string)</span> -></span>
|
||||
<span class="hljs-keyword">return</span> <span class="hljs-literal">NaN</span> <span class="hljs-keyword">unless</span> string?
|
||||
|
||||
base = <span class="hljs-keyword">switch</span> string.charAt <span class="hljs-number">1</span>
|
||||
<span class="hljs-keyword">when</span> <span class="hljs-string">'b'</span> <span class="hljs-keyword">then</span> <span class="hljs-number">2</span>
|
||||
<span class="hljs-keyword">when</span> <span class="hljs-string">'o'</span> <span class="hljs-keyword">then</span> <span class="hljs-number">8</span>
|
||||
<span class="hljs-keyword">when</span> <span class="hljs-string">'x'</span> <span class="hljs-keyword">then</span> <span class="hljs-number">16</span>
|
||||
<span class="hljs-keyword">else</span> <span class="hljs-literal">null</span>
|
||||
|
||||
<span class="hljs-keyword">if</span> base?
|
||||
<span class="hljs-built_in">parseInt</span> string[<span class="hljs-number">2.</span>.].replace(<span class="hljs-regexp">/_/g</span>, <span class="hljs-string">''</span>), base
|
||||
<span class="hljs-keyword">else</span>
|
||||
<span class="hljs-built_in">parseFloat</span> string.replace(<span class="hljs-regexp">/_/g</span>, <span class="hljs-string">''</span>)
|
||||
|
||||
<span class="hljs-built_in">exports</span>.isFunction = <span class="hljs-function"><span class="hljs-params">(obj)</span> -></span> Object::toString.call(obj) <span class="hljs-keyword">is</span> <span class="hljs-string">'[object Function]'</span>
|
||||
<span class="hljs-built_in">exports</span>.isNumber = isNumber = <span class="hljs-function"><span class="hljs-params">(obj)</span> -></span> Object::toString.call(obj) <span class="hljs-keyword">is</span> <span class="hljs-string">'[object Number]'</span>
|
||||
<span class="hljs-built_in">exports</span>.isString = isString = <span class="hljs-function"><span class="hljs-params">(obj)</span> -></span> Object::toString.call(obj) <span class="hljs-keyword">is</span> <span class="hljs-string">'[object String]'</span>
|
||||
<span class="hljs-built_in">exports</span>.isBoolean = isBoolean = <span class="hljs-function"><span class="hljs-params">(obj)</span> -></span> obj <span class="hljs-keyword">is</span> <span class="hljs-literal">yes</span> <span class="hljs-keyword">or</span> obj <span class="hljs-keyword">is</span> <span class="hljs-literal">no</span> <span class="hljs-keyword">or</span> Object::toString.call(obj) <span class="hljs-keyword">is</span> <span class="hljs-string">'[object Boolean]'</span>
|
||||
<span class="hljs-built_in">exports</span>.isPlainObject = <span class="hljs-function"><span class="hljs-params">(obj)</span> -></span> <span class="hljs-keyword">typeof</span> obj <span class="hljs-keyword">is</span> <span class="hljs-string">'object'</span> <span class="hljs-keyword">and</span> !!obj <span class="hljs-keyword">and</span> <span class="hljs-keyword">not</span> <span class="hljs-built_in">Array</span>.isArray(obj) <span class="hljs-keyword">and</span> <span class="hljs-keyword">not</span> isNumber(obj) <span class="hljs-keyword">and</span> <span class="hljs-keyword">not</span> isString(obj) <span class="hljs-keyword">and</span> <span class="hljs-keyword">not</span> isBoolean(obj)
|
||||
<span class="hljs-function">
|
||||
<span class="hljs-title">unicodeCodePointToUnicodeEscapes</span> = <span class="hljs-params">(codePoint)</span> -></span>
|
||||
<span class="hljs-function"> <span class="hljs-title">toUnicodeEscape</span> = <span class="hljs-params">(val)</span> -></span>
|
||||
str = val.toString <span class="hljs-number">16</span>
|
||||
<span class="hljs-string">"\\u<span class="hljs-subst">#{repeat <span class="hljs-string">'0'</span>, <span class="hljs-number">4</span> - str.length}</span><span class="hljs-subst">#{str}</span>"</span>
|
||||
<span class="hljs-keyword">return</span> toUnicodeEscape(codePoint) <span class="hljs-keyword">if</span> codePoint < <span class="hljs-number">0x10000</span></pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-33">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-33">§</a>
|
||||
</div>
|
||||
<p>surrogate pair</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre> high = <span class="hljs-built_in">Math</span>.floor((codePoint - <span class="hljs-number">0x10000</span>) / <span class="hljs-number">0x400</span>) + <span class="hljs-number">0xD800</span>
|
||||
low = (codePoint - <span class="hljs-number">0x10000</span>) % <span class="hljs-number">0x400</span> + <span class="hljs-number">0xDC00</span>
|
||||
<span class="hljs-string">"<span class="hljs-subst">#{toUnicodeEscape(high)}</span><span class="hljs-subst">#{toUnicodeEscape(low)}</span>"</span></pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-34">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-34">§</a>
|
||||
</div>
|
||||
<p>Replace <code>\u{...}</code> with <code>\uxxxx[\uxxxx]</code> in regexes without <code>u</code> flag</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre><span class="hljs-built_in">exports</span>.replaceUnicodeCodePointEscapes = <span class="hljs-function"><span class="hljs-params">(str, {flags, error, delimiter = <span class="hljs-string">''</span>} = {})</span> -></span>
|
||||
shouldReplace = flags? <span class="hljs-keyword">and</span> <span class="hljs-string">'u'</span> <span class="hljs-keyword">not</span> <span class="hljs-keyword">in</span> flags
|
||||
str.replace UNICODE_CODE_POINT_ESCAPE, <span class="hljs-function"><span class="hljs-params">(match, escapedBackslash, codePointHex, offset)</span> -></span>
|
||||
<span class="hljs-keyword">return</span> escapedBackslash <span class="hljs-keyword">if</span> escapedBackslash
|
||||
|
||||
codePointDecimal = <span class="hljs-built_in">parseInt</span> codePointHex, <span class="hljs-number">16</span>
|
||||
<span class="hljs-keyword">if</span> codePointDecimal > <span class="hljs-number">0x10ffff</span>
|
||||
error <span class="hljs-string">"unicode code point escapes greater than \\u{10ffff} are not allowed"</span>,
|
||||
offset: offset + delimiter.length
|
||||
length: codePointHex.length + <span class="hljs-number">4</span>
|
||||
<span class="hljs-keyword">return</span> match <span class="hljs-keyword">unless</span> shouldReplace
|
||||
|
||||
unicodeCodePointToUnicodeEscapes codePointDecimal
|
||||
|
||||
UNICODE_CODE_POINT_ESCAPE = <span class="hljs-regexp">///
|
||||
( \\\\ ) <span class="hljs-comment"># Make sure the escape isn’t escaped.</span>
|
||||
|
|
||||
\\u\{ ( [\da-fA-F]+ ) \}
|
||||
///</span>g</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
@@ -112,20 +112,27 @@
|
||||
<li id="section-1">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-1">¶</a>
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-1">§</a>
|
||||
</div>
|
||||
<p>Node.js Implementation</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>CoffeeScript = <span class="hljs-built_in">require</span> <span class="hljs-string">'./coffeescript'</span>
|
||||
fs = <span class="hljs-built_in">require</span> <span class="hljs-string">'fs'</span>
|
||||
vm = <span class="hljs-built_in">require</span> <span class="hljs-string">'vm'</span>
|
||||
path = <span class="hljs-built_in">require</span> <span class="hljs-string">'path'</span>
|
||||
<div class="content"><div class='highlight'><pre>CoffeeScript = <span class="hljs-built_in">require</span> <span class="hljs-string">'./coffeescript'</span>
|
||||
fs = <span class="hljs-built_in">require</span> <span class="hljs-string">'fs'</span>
|
||||
vm = <span class="hljs-built_in">require</span> <span class="hljs-string">'vm'</span>
|
||||
path = <span class="hljs-built_in">require</span> <span class="hljs-string">'path'</span>
|
||||
|
||||
helpers = CoffeeScript.helpers
|
||||
compile = CoffeeScript.compile</pre></div></div>
|
||||
|
||||
CoffeeScript.transpile = <span class="hljs-function"><span class="hljs-params">(js, options)</span> -></span>
|
||||
<span class="hljs-keyword">try</span>
|
||||
babel = <span class="hljs-built_in">require</span> <span class="hljs-string">'@babel/core'</span>
|
||||
<span class="hljs-keyword">catch</span>
|
||||
<span class="hljs-keyword">try</span>
|
||||
babel = <span class="hljs-built_in">require</span> <span class="hljs-string">'babel-core'</span>
|
||||
<span class="hljs-keyword">catch</span></pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
@@ -133,8 +140,75 @@ compile = CoffeeScript.compile</pre></div></div>
|
||||
<li id="section-2">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-2">¶</a>
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-2">§</a>
|
||||
</div>
|
||||
<p>This error is only for Node, as CLI users will see a different error
|
||||
earlier if they don’t have Babel installed.</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre> <span class="hljs-keyword">throw</span> <span class="hljs-keyword">new</span> <span class="hljs-built_in">Error</span> <span class="hljs-string">'To use the transpile option, you must have the \'@babel/core\' module installed'</span>
|
||||
babel.transform js, options</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-3">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-3">§</a>
|
||||
</div>
|
||||
<p>The <code>compile</code> method shared by the CLI, Node and browser APIs.</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>universalCompile = CoffeeScript.compile</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-4">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-4">§</a>
|
||||
</div>
|
||||
<p>The <code>compile</code> method particular to the Node API.</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>CoffeeScript.compile = <span class="hljs-function"><span class="hljs-params">(code, options)</span> -></span></pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-5">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-5">§</a>
|
||||
</div>
|
||||
<p>Pass a reference to Babel into the compiler, so that the transpile option
|
||||
is available in the Node API. 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-keyword">if</span> options?.transpile
|
||||
options.transpile.transpile = CoffeeScript.transpile
|
||||
universalCompile.call CoffeeScript, code, options</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-6">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-6">§</a>
|
||||
</div>
|
||||
<p>Compile and execute a string of CoffeeScript (on the server), correctly
|
||||
setting <code>__filename</code>, <code>__dirname</code>, and relative <code>require()</code>.</p>
|
||||
@@ -147,27 +221,27 @@ setting <code>__filename</code>, <code>__dirname</code>, and relative <code>requ
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-3">
|
||||
<li id="section-7">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-3">¶</a>
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-7">§</a>
|
||||
</div>
|
||||
<p>Set the filename.</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre> mainModule.filename = process.argv[<span class="hljs-number">1</span>] =
|
||||
<span class="hljs-keyword">if</span> options.filename <span class="hljs-keyword">then</span> fs.realpathSync(options.filename) <span class="hljs-keyword">else</span> <span class="hljs-string">'<anonymous>'</span></pre></div></div>
|
||||
<span class="hljs-keyword">if</span> options.filename <span class="hljs-keyword">then</span> fs.realpathSync(options.filename) <span class="hljs-keyword">else</span> <span class="hljs-string">'<anonymous>'</span></pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-4">
|
||||
<li id="section-8">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-4">¶</a>
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-8">§</a>
|
||||
</div>
|
||||
<p>Clear the module cache.</p>
|
||||
|
||||
@@ -178,11 +252,11 @@ setting <code>__filename</code>, <code>__dirname</code>, and relative <code>requ
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-5">
|
||||
<li id="section-9">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-5">¶</a>
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-9">§</a>
|
||||
</div>
|
||||
<p>Assign paths for node_modules loading</p>
|
||||
|
||||
@@ -191,24 +265,39 @@ setting <code>__filename</code>, <code>__dirname</code>, and relative <code>requ
|
||||
<div class="content"><div class='highlight'><pre> dir = <span class="hljs-keyword">if</span> options.filename?
|
||||
path.dirname fs.realpathSync options.filename
|
||||
<span class="hljs-keyword">else</span>
|
||||
fs.realpathSync <span class="hljs-string">'.'</span>
|
||||
mainModule.paths = <span class="hljs-built_in">require</span>(<span class="hljs-string">'module'</span>)._nodeModulePaths dir</pre></div></div>
|
||||
fs.realpathSync <span class="hljs-string">'.'</span>
|
||||
mainModule.paths = <span class="hljs-built_in">require</span>(<span class="hljs-string">'module'</span>)._nodeModulePaths dir</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-6">
|
||||
<li id="section-10">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-6">¶</a>
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-10">§</a>
|
||||
</div>
|
||||
<p>Save the options for compiling child imports.</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre> mainModule.options = options</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-11">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-11">§</a>
|
||||
</div>
|
||||
<p>Compile.</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre> <span class="hljs-keyword">if</span> <span class="hljs-keyword">not</span> helpers.isCoffee(mainModule.filename) <span class="hljs-keyword">or</span> <span class="hljs-built_in">require</span>.extensions
|
||||
answer = compile code, options
|
||||
answer = CoffeeScript.compile code, options
|
||||
code = answer.js ? answer
|
||||
|
||||
mainModule._compile code, mainModule.filename</pre></div></div>
|
||||
@@ -216,18 +305,18 @@ setting <code>__filename</code>, <code>__dirname</code>, and relative <code>requ
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-7">
|
||||
<li id="section-12">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-7">¶</a>
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-12">§</a>
|
||||
</div>
|
||||
<p>Compile and evaluate a string of CoffeeScript (in a Node.js-like environment).
|
||||
The CoffeeScript REPL uses this to run the input.</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>CoffeeScript.eval = <span class="hljs-function"><span class="hljs-params">(code, options = {})</span> -></span>
|
||||
<div class="content"><div class='highlight'><pre>CoffeeScript.<span class="hljs-built_in">eval</span> = <span class="hljs-function"><span class="hljs-params">(code, options = {})</span> -></span>
|
||||
<span class="hljs-keyword">return</span> <span class="hljs-keyword">unless</span> code = code.trim()
|
||||
createContext = vm.Script.createContext ? vm.createContext
|
||||
|
||||
@@ -241,41 +330,41 @@ The CoffeeScript REPL uses this to run the input.</p>
|
||||
<span class="hljs-keyword">else</span>
|
||||
sandbox = createContext()
|
||||
sandbox[k] = v <span class="hljs-keyword">for</span> own k, v <span class="hljs-keyword">of</span> options.sandbox
|
||||
sandbox.<span class="hljs-built_in">global</span> = sandbox.root = sandbox.GLOBAL = sandbox
|
||||
sandbox.global = sandbox.root = sandbox.GLOBAL = sandbox
|
||||
<span class="hljs-keyword">else</span>
|
||||
sandbox = <span class="hljs-built_in">global</span>
|
||||
sandbox.__filename = options.filename || <span class="hljs-string">'eval'</span>
|
||||
sandbox = global
|
||||
sandbox.__filename = options.filename || <span class="hljs-string">'eval'</span>
|
||||
sandbox.__dirname = path.dirname sandbox.__filename</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-8">
|
||||
<li id="section-13">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-8">¶</a>
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-13">§</a>
|
||||
</div>
|
||||
<p>define module/require only if they chose not to specify their own</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre> <span class="hljs-keyword">unless</span> sandbox <span class="hljs-keyword">isnt</span> <span class="hljs-built_in">global</span> <span class="hljs-keyword">or</span> sandbox.<span class="hljs-built_in">module</span> <span class="hljs-keyword">or</span> sandbox.<span class="hljs-built_in">require</span>
|
||||
Module = <span class="hljs-built_in">require</span> <span class="hljs-string">'module'</span>
|
||||
sandbox.<span class="hljs-built_in">module</span> = _module = <span class="hljs-keyword">new</span> Module(options.modulename || <span class="hljs-string">'eval'</span>)
|
||||
<div class="content"><div class='highlight'><pre> <span class="hljs-keyword">unless</span> sandbox <span class="hljs-keyword">isnt</span> global <span class="hljs-keyword">or</span> sandbox.module <span class="hljs-keyword">or</span> sandbox.<span class="hljs-built_in">require</span>
|
||||
Module = <span class="hljs-built_in">require</span> <span class="hljs-string">'module'</span>
|
||||
sandbox.module = _module = <span class="hljs-keyword">new</span> Module(options.modulename || <span class="hljs-string">'eval'</span>)
|
||||
sandbox.<span class="hljs-built_in">require</span> = _require = <span class="hljs-function"><span class="hljs-params">(path)</span> -></span> Module._load path, _module, <span class="hljs-literal">true</span>
|
||||
_module.filename = sandbox.__filename
|
||||
<span class="hljs-keyword">for</span> r <span class="hljs-keyword">in</span> Object.getOwnPropertyNames <span class="hljs-built_in">require</span> <span class="hljs-keyword">when</span> r <span class="hljs-keyword">not</span> <span class="hljs-keyword">in</span> [<span class="hljs-string">'paths'</span>, <span class="hljs-string">'arguments'</span>, <span class="hljs-string">'caller'</span>]
|
||||
<span class="hljs-keyword">for</span> r <span class="hljs-keyword">in</span> <span class="hljs-built_in">Object</span>.getOwnPropertyNames <span class="hljs-built_in">require</span> <span class="hljs-keyword">when</span> r <span class="hljs-keyword">not</span> <span class="hljs-keyword">in</span> [<span class="hljs-string">'paths'</span>, <span class="hljs-string">'arguments'</span>, <span class="hljs-string">'caller'</span>]
|
||||
_require[r] = <span class="hljs-built_in">require</span>[r]</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-9">
|
||||
<li id="section-14">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-9">¶</a>
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-14">§</a>
|
||||
</div>
|
||||
<p>use the same hack node currently uses for their own REPL</p>
|
||||
|
||||
@@ -286,22 +375,22 @@ The CoffeeScript REPL uses this to run the input.</p>
|
||||
o = {}
|
||||
o[k] = v <span class="hljs-keyword">for</span> own k, v <span class="hljs-keyword">of</span> options
|
||||
o.bare = <span class="hljs-literal">on</span> <span class="hljs-comment"># ensure return value</span>
|
||||
js = compile code, o
|
||||
<span class="hljs-keyword">if</span> sandbox <span class="hljs-keyword">is</span> <span class="hljs-built_in">global</span>
|
||||
js = CoffeeScript.compile code, o
|
||||
<span class="hljs-keyword">if</span> sandbox <span class="hljs-keyword">is</span> global
|
||||
vm.runInThisContext js
|
||||
<span class="hljs-keyword">else</span>
|
||||
vm.runInContext js, sandbox
|
||||
|
||||
CoffeeScript.register = <span class="hljs-function">-></span> <span class="hljs-built_in">require</span> <span class="hljs-string">'./register'</span></pre></div></div>
|
||||
CoffeeScript.register = <span class="hljs-function">-></span> <span class="hljs-built_in">require</span> <span class="hljs-string">'./register'</span></pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-10">
|
||||
<li id="section-15">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-10">¶</a>
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-15">§</a>
|
||||
</div>
|
||||
<p>Throw error with deprecation warning when depending upon implicit <code>require.extensions</code> registration</p>
|
||||
|
||||
@@ -310,21 +399,20 @@ CoffeeScript.register = <span class="hljs-function">-></span> <span class="hl
|
||||
<div class="content"><div class='highlight'><pre><span class="hljs-keyword">if</span> <span class="hljs-built_in">require</span>.extensions
|
||||
<span class="hljs-keyword">for</span> ext <span class="hljs-keyword">in</span> CoffeeScript.FILE_EXTENSIONS <span class="hljs-keyword">then</span> <span class="hljs-keyword">do</span> (ext) ->
|
||||
<span class="hljs-built_in">require</span>.extensions[ext] ?= <span class="hljs-function">-></span>
|
||||
<span class="hljs-keyword">throw</span> <span class="hljs-keyword">new</span> Error <span class="hljs-string">"""
|
||||
<span class="hljs-keyword">throw</span> <span class="hljs-keyword">new</span> <span class="hljs-built_in">Error</span> <span class="hljs-string">"""
|
||||
Use CoffeeScript.register() or require the coffeescript/register module to require <span class="hljs-subst">#{ext}</span> files.
|
||||
"""</span>
|
||||
"""</span>
|
||||
|
||||
CoffeeScript._compileFile = <span class="hljs-function"><span class="hljs-params">(filename, sourceMap = <span class="hljs-literal">no</span>, inlineMap = <span class="hljs-literal">no</span>)</span> -></span>
|
||||
raw = fs.readFileSync filename, <span class="hljs-string">'utf8'</span></pre></div></div>
|
||||
CoffeeScript._compileRawFileContent = <span class="hljs-function"><span class="hljs-params">(raw, filename, options = {})</span> -></span></pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-11">
|
||||
<li id="section-16">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-11">¶</a>
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-16">§</a>
|
||||
</div>
|
||||
<p>Strip the Unicode byte order mark, if this file begins with one.</p>
|
||||
|
||||
@@ -332,22 +420,24 @@ CoffeeScript._compileFile = <span class="hljs-function"><span class="hljs-params
|
||||
|
||||
<div class="content"><div class='highlight'><pre> stripped = <span class="hljs-keyword">if</span> raw.charCodeAt(<span class="hljs-number">0</span>) <span class="hljs-keyword">is</span> <span class="hljs-number">0xFEFF</span> <span class="hljs-keyword">then</span> raw.substring <span class="hljs-number">1</span> <span class="hljs-keyword">else</span> raw
|
||||
|
||||
options = <span class="hljs-built_in">Object</span>.assign {}, options,
|
||||
filename: filename
|
||||
literate: helpers.isLiterate filename
|
||||
sourceFiles: [filename]
|
||||
inlineMap: <span class="hljs-literal">yes</span> <span class="hljs-comment"># Always generate a source map, so that stack traces line up.</span>
|
||||
|
||||
<span class="hljs-keyword">try</span>
|
||||
answer = compile stripped, {
|
||||
filename, sourceMap, inlineMap
|
||||
sourceFiles: [filename]
|
||||
literate: helpers.isLiterate filename
|
||||
}
|
||||
answer = CoffeeScript.compile stripped, options
|
||||
<span class="hljs-keyword">catch</span> err</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-12">
|
||||
<li id="section-17">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-12">¶</a>
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-17">§</a>
|
||||
</div>
|
||||
<p>As the filename and code of a dynamically loaded file will be different
|
||||
from the original file compiled with CoffeeScript.run, add that
|
||||
@@ -359,7 +449,43 @@ information to error so it can be pretty-printed later.</p>
|
||||
|
||||
answer
|
||||
|
||||
<span class="hljs-built_in">module</span>.exports = CoffeeScript</pre></div></div>
|
||||
CoffeeScript._compileFile = <span class="hljs-function"><span class="hljs-params">(filename, options = {})</span> -></span>
|
||||
raw = fs.readFileSync filename, <span class="hljs-string">'utf8'</span>
|
||||
|
||||
CoffeeScript._compileRawFileContent raw, filename, options
|
||||
|
||||
module.<span class="hljs-built_in">exports</span> = CoffeeScript</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-18">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-18">§</a>
|
||||
</div>
|
||||
<p>Explicitly define all named exports so that Node’s automatic detection of
|
||||
named exports from CommonJS packages finds all of them. This enables consuming
|
||||
packages to write code like <code>import { compile } from 'coffeescript'</code>.
|
||||
Don’t simplify this into a loop or similar; the <code>module.exports.name</code> part is
|
||||
essential for Node’s algorithm to successfully detect the name.</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>module.<span class="hljs-built_in">exports</span>.VERSION = CoffeeScript.VERSION
|
||||
module.<span class="hljs-built_in">exports</span>.FILE_EXTENSIONS = CoffeeScript.FILE_EXTENSIONS
|
||||
module.<span class="hljs-built_in">exports</span>.helpers = CoffeeScript.helpers
|
||||
module.<span class="hljs-built_in">exports</span>.registerCompiled = CoffeeScript.registerCompiled
|
||||
module.<span class="hljs-built_in">exports</span>.compile = CoffeeScript.compile
|
||||
module.<span class="hljs-built_in">exports</span>.tokens = CoffeeScript.tokens
|
||||
module.<span class="hljs-built_in">exports</span>.nodes = CoffeeScript.nodes
|
||||
module.<span class="hljs-built_in">exports</span>.register = CoffeeScript.register
|
||||
module.<span class="hljs-built_in">exports</span>.<span class="hljs-built_in">eval</span> = CoffeeScript.<span class="hljs-built_in">eval</span>
|
||||
module.<span class="hljs-built_in">exports</span>.run = CoffeeScript.run
|
||||
module.<span class="hljs-built_in">exports</span>.transpile = CoffeeScript.transpile
|
||||
module.<span class="hljs-built_in">exports</span>._compileRawFileContent = CoffeeScript._compileRawFileContent
|
||||
module.<span class="hljs-built_in">exports</span>._compileFile = CoffeeScript._compileFile</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -112,13 +112,13 @@
|
||||
<li id="section-1">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-1">¶</a>
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-1">§</a>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>{repeat} = <span class="hljs-built_in">require</span> <span class="hljs-string">'./helpers'</span></pre></div></div>
|
||||
<div class="content"><div class='highlight'><pre>{repeat} = <span class="hljs-built_in">require</span> <span class="hljs-string">'./helpers'</span></pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
@@ -126,8 +126,8 @@
|
||||
<li id="section-2">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-2">¶</a>
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-2">§</a>
|
||||
</div>
|
||||
<p>A simple <strong>OptionParser</strong> class to parse option flags from the command-line.
|
||||
Use it like so:</p>
|
||||
@@ -140,7 +140,7 @@ command-line arguments in <code>src/command.coffee</code>.</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>exports.OptionParser = <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">OptionParser</span></span></pre></div></div>
|
||||
<div class="content"><div class='highlight'><pre><span class="hljs-built_in">exports</span>.OptionParser = <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">OptionParser</span></span></pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
@@ -148,8 +148,8 @@ command-line arguments in <code>src/command.coffee</code>.</p>
|
||||
<li id="section-3">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-3">¶</a>
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-3">§</a>
|
||||
</div>
|
||||
<p>Initialize with a list of valid options, in the form:</p>
|
||||
<pre><code>[short-flag, long-flag, description]
|
||||
@@ -166,8 +166,8 @@ command-line arguments in <code>src/command.coffee</code>.</p>
|
||||
<li id="section-4">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-4">¶</a>
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-4">§</a>
|
||||
</div>
|
||||
<p>Parse the list of arguments, populating an <code>options</code> object with all of the
|
||||
specified options, and return it. Options after the first non-option
|
||||
@@ -186,8 +186,8 @@ you’re responsible for interpreting the options object.</p>
|
||||
<li id="section-5">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-5">¶</a>
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-5">§</a>
|
||||
</div>
|
||||
<p>The CoffeeScript option parser is a little odd; options after the first
|
||||
non-option argument are treated as non-option arguments themselves.
|
||||
@@ -208,8 +208,8 @@ line <code>#!/usr/bin/env coffee</code>, or <code>#!/absolute/path/to/coffee</co
|
||||
<li id="section-6">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-6">¶</a>
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-6">§</a>
|
||||
</div>
|
||||
<p>The <code>argument</code> field is added to the rule instance non-destructively by
|
||||
<code>normalizeArguments</code>.</p>
|
||||
@@ -226,7 +226,7 @@ line <code>#!/usr/bin/env coffee</code>, or <code>#!/absolute/path/to/coffee</co
|
||||
<span class="hljs-keyword">else</span>
|
||||
options[name] = <span class="hljs-literal">true</span>
|
||||
|
||||
<span class="hljs-keyword">if</span> positional[<span class="hljs-number">0</span>] <span class="hljs-keyword">is</span> <span class="hljs-string">'--'</span>
|
||||
<span class="hljs-keyword">if</span> positional[<span class="hljs-number">0</span>] <span class="hljs-keyword">is</span> <span class="hljs-string">'--'</span>
|
||||
options.doubleDashed = <span class="hljs-literal">yes</span>
|
||||
positional = positional[<span class="hljs-number">1.</span>.]
|
||||
|
||||
@@ -239,8 +239,8 @@ line <code>#!/usr/bin/env coffee</code>, or <code>#!/absolute/path/to/coffee</co
|
||||
<li id="section-7">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-7">¶</a>
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-7">§</a>
|
||||
</div>
|
||||
<p>Return the help text for this <strong>OptionParser</strong>, listing and describing all
|
||||
of the valid options, for <code>--help</code> and such.</p>
|
||||
@@ -249,13 +249,13 @@ of the valid options, for <code>--help</code> and such.</p>
|
||||
|
||||
<div class="content"><div class='highlight'><pre> help: <span class="hljs-function">-></span>
|
||||
lines = []
|
||||
lines.unshift <span class="hljs-string">"<span class="hljs-subst">#{@banner}</span>\n"</span> <span class="hljs-keyword">if</span> @banner
|
||||
lines.unshift <span class="hljs-string">"<span class="hljs-subst">#{@banner}</span>\n"</span> <span class="hljs-keyword">if</span> @banner
|
||||
<span class="hljs-keyword">for</span> rule <span class="hljs-keyword">in</span> @rules.ruleList
|
||||
spaces = <span class="hljs-number">15</span> - rule.longFlag.length
|
||||
spaces = <span class="hljs-keyword">if</span> spaces > <span class="hljs-number">0</span> <span class="hljs-keyword">then</span> repeat <span class="hljs-string">' '</span>, spaces <span class="hljs-keyword">else</span> <span class="hljs-string">''</span>
|
||||
letPart = <span class="hljs-keyword">if</span> rule.shortFlag <span class="hljs-keyword">then</span> rule.shortFlag + <span class="hljs-string">', '</span> <span class="hljs-keyword">else</span> <span class="hljs-string">' '</span>
|
||||
lines.push <span class="hljs-string">' '</span> + letPart + rule.longFlag + spaces + rule.description
|
||||
<span class="hljs-string">"\n<span class="hljs-subst">#{ lines.join(<span class="hljs-string">'\n'</span>) }</span>\n"</span></pre></div></div>
|
||||
spaces = <span class="hljs-keyword">if</span> spaces > <span class="hljs-number">0</span> <span class="hljs-keyword">then</span> repeat <span class="hljs-string">' '</span>, spaces <span class="hljs-keyword">else</span> <span class="hljs-string">''</span>
|
||||
letPart = <span class="hljs-keyword">if</span> rule.shortFlag <span class="hljs-keyword">then</span> rule.shortFlag + <span class="hljs-string">', '</span> <span class="hljs-keyword">else</span> <span class="hljs-string">' '</span>
|
||||
lines.push <span class="hljs-string">' '</span> + letPart + rule.longFlag + spaces + rule.description
|
||||
<span class="hljs-string">"\n<span class="hljs-subst">#{ lines.join(<span class="hljs-string">'\n'</span>) }</span>\n"</span></pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
@@ -263,8 +263,8 @@ of the valid options, for <code>--help</code> and such.</p>
|
||||
<li id="section-8">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-8">¶</a>
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-8">§</a>
|
||||
</div>
|
||||
<h2 id="helpers">Helpers</h2>
|
||||
|
||||
@@ -276,8 +276,8 @@ of the valid options, for <code>--help</code> and such.</p>
|
||||
<li id="section-9">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-9">¶</a>
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-9">§</a>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
@@ -288,8 +288,8 @@ of the valid options, for <code>--help</code> and such.</p>
|
||||
<li id="section-10">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-10">¶</a>
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-10">§</a>
|
||||
</div>
|
||||
<p>Regex matchers for option flags on the command line and their rules.</p>
|
||||
|
||||
@@ -305,8 +305,8 @@ MULTI_FLAG = <span class="hljs-regexp">/^-(\w{2,})/</span></pre></div></div>
|
||||
<li id="section-11">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-11">¶</a>
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-11">§</a>
|
||||
</div>
|
||||
<p>Matches the long flag part of a rule for an option with an argument. Not
|
||||
applied to anything in process.argv.</p>
|
||||
@@ -321,8 +321,8 @@ applied to anything in process.argv.</p>
|
||||
<li id="section-12">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-12">¶</a>
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-12">§</a>
|
||||
</div>
|
||||
<p>Build and return the list of option rules. If the optional <em>short-flag</em> is
|
||||
unspecified, leave it out by padding with <code>null</code>.</p>
|
||||
@@ -342,8 +342,8 @@ unspecified, leave it out by padding with <code>null</code>.</p>
|
||||
<li id="section-13">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-13">¶</a>
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-13">§</a>
|
||||
</div>
|
||||
<p><code>shortFlag</code> is null if not provided in the rule.</p>
|
||||
|
||||
@@ -351,8 +351,8 @@ unspecified, leave it out by padding with <code>null</code>.</p>
|
||||
|
||||
<div class="content"><div class='highlight'><pre> <span class="hljs-keyword">for</span> flag <span class="hljs-keyword">in</span> [rule.shortFlag, rule.longFlag] <span class="hljs-keyword">when</span> flag?
|
||||
<span class="hljs-keyword">if</span> flagDict[flag]?
|
||||
<span class="hljs-keyword">throw</span> <span class="hljs-keyword">new</span> Error <span class="hljs-string">"flag <span class="hljs-subst">#{flag}</span> for switch <span class="hljs-subst">#{rule.name}</span>
|
||||
was already declared for switch <span class="hljs-subst">#{flagDict[flag].name}</span>"</span>
|
||||
<span class="hljs-keyword">throw</span> <span class="hljs-keyword">new</span> <span class="hljs-built_in">Error</span> <span class="hljs-string">"flag <span class="hljs-subst">#{flag}</span> for switch <span class="hljs-subst">#{rule.name}</span>
|
||||
was already declared for switch <span class="hljs-subst">#{flagDict[flag].name}</span>"</span>
|
||||
flagDict[flag] = rule
|
||||
|
||||
{ruleList, flagDict}</pre></div></div>
|
||||
@@ -363,8 +363,8 @@ unspecified, leave it out by padding with <code>null</code>.</p>
|
||||
<li id="section-14">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-14">¶</a>
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-14">§</a>
|
||||
</div>
|
||||
<p>Build a rule from a <code>-o</code> short flag, a <code>--output [DIR]</code> long flag, and the
|
||||
description of what the option does.</p>
|
||||
@@ -376,7 +376,7 @@ description of what the option does.</p>
|
||||
shortFlag = shortFlag?.match(SHORT_FLAG)[<span class="hljs-number">1</span>]
|
||||
longFlag = longFlag.match(LONG_FLAG)[<span class="hljs-number">1</span>]
|
||||
{
|
||||
name: longFlag.replace <span class="hljs-regexp">/^--/</span>, <span class="hljs-string">''</span>
|
||||
name: longFlag.replace <span class="hljs-regexp">/^--/</span>, <span class="hljs-string">''</span>
|
||||
shortFlag: shortFlag
|
||||
longFlag: longFlag
|
||||
description: description
|
||||
@@ -396,8 +396,8 @@ description of what the option does.</p>
|
||||
<li id="section-15">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-15">¶</a>
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-15">§</a>
|
||||
</div>
|
||||
<p>If the previous argument given to the script was an option that uses the
|
||||
next command-line argument as its argument, create copy of the option’s
|
||||
@@ -406,19 +406,19 @@ rule with an <code>argument</code> field.</p>
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre> <span class="hljs-keyword">if</span> needsArgOpt?
|
||||
withArg = Object.assign {}, needsArgOpt.rule, {argument: arg}
|
||||
withArg = <span class="hljs-built_in">Object</span>.assign {}, needsArgOpt.rule, {argument: arg}
|
||||
rules.push withArg
|
||||
needsArgOpt = <span class="hljs-literal">null</span>
|
||||
<span class="hljs-keyword">continue</span>
|
||||
|
||||
multiFlags = arg.match(MULTI_FLAG)?[<span class="hljs-number">1</span>]
|
||||
.split(<span class="hljs-string">''</span>)
|
||||
.map (flagName) -> <span class="hljs-string">"-<span class="hljs-subst">#{flagName}</span>"</span>
|
||||
.split(<span class="hljs-string">''</span>)
|
||||
.map (flagName) -> <span class="hljs-string">"-<span class="hljs-subst">#{flagName}</span>"</span>
|
||||
<span class="hljs-keyword">if</span> multiFlags?
|
||||
multiOpts = multiFlags.map (flag) ->
|
||||
rule = flagDict[flag]
|
||||
<span class="hljs-keyword">unless</span> rule?
|
||||
<span class="hljs-keyword">throw</span> <span class="hljs-keyword">new</span> Error <span class="hljs-string">"unrecognized option <span class="hljs-subst">#{flag}</span> in multi-flag <span class="hljs-subst">#{arg}</span>"</span>
|
||||
<span class="hljs-keyword">throw</span> <span class="hljs-keyword">new</span> <span class="hljs-built_in">Error</span> <span class="hljs-string">"unrecognized option <span class="hljs-subst">#{flag}</span> in multi-flag <span class="hljs-subst">#{arg}</span>"</span>
|
||||
{rule, flag}</pre></div></div>
|
||||
|
||||
</li>
|
||||
@@ -427,8 +427,8 @@ rule with an <code>argument</code> field.</p>
|
||||
<li id="section-16">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-16">¶</a>
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-16">§</a>
|
||||
</div>
|
||||
<p>Only the last flag in a multi-flag may have an argument.</p>
|
||||
|
||||
@@ -437,8 +437,8 @@ rule with an <code>argument</code> field.</p>
|
||||
<div class="content"><div class='highlight'><pre> [innerOpts..., lastOpt] = multiOpts
|
||||
<span class="hljs-keyword">for</span> {rule, flag} <span class="hljs-keyword">in</span> innerOpts
|
||||
<span class="hljs-keyword">if</span> rule.hasArgument
|
||||
<span class="hljs-keyword">throw</span> <span class="hljs-keyword">new</span> Error <span class="hljs-string">"cannot use option <span class="hljs-subst">#{flag}</span> in multi-flag <span class="hljs-subst">#{arg}</span> except
|
||||
as the last option, because it needs an argument"</span>
|
||||
<span class="hljs-keyword">throw</span> <span class="hljs-keyword">new</span> <span class="hljs-built_in">Error</span> <span class="hljs-string">"cannot use option <span class="hljs-subst">#{flag}</span> in multi-flag <span class="hljs-subst">#{arg}</span> except
|
||||
as the last option, because it needs an argument"</span>
|
||||
rules.push rule
|
||||
<span class="hljs-keyword">if</span> lastOpt.rule.hasArgument
|
||||
needsArgOpt = lastOpt
|
||||
@@ -447,7 +447,7 @@ rule with an <code>argument</code> field.</p>
|
||||
<span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> ([LONG_FLAG, SHORT_FLAG].some (pat) -> arg.match(pat)?)
|
||||
singleRule = flagDict[arg]
|
||||
<span class="hljs-keyword">unless</span> singleRule?
|
||||
<span class="hljs-keyword">throw</span> <span class="hljs-keyword">new</span> Error <span class="hljs-string">"unrecognized option <span class="hljs-subst">#{arg}</span>"</span>
|
||||
<span class="hljs-keyword">throw</span> <span class="hljs-keyword">new</span> <span class="hljs-built_in">Error</span> <span class="hljs-string">"unrecognized option <span class="hljs-subst">#{arg}</span>"</span>
|
||||
<span class="hljs-keyword">if</span> singleRule.hasArgument
|
||||
needsArgOpt = {rule: singleRule, flag: arg}
|
||||
<span class="hljs-keyword">else</span>
|
||||
@@ -460,8 +460,8 @@ rule with an <code>argument</code> field.</p>
|
||||
<li id="section-17">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-17">¶</a>
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-17">§</a>
|
||||
</div>
|
||||
<p>This is a positional argument.</p>
|
||||
|
||||
@@ -471,8 +471,8 @@ rule with an <code>argument</code> field.</p>
|
||||
<span class="hljs-keyword">break</span>
|
||||
|
||||
<span class="hljs-keyword">if</span> needsArgOpt?
|
||||
<span class="hljs-keyword">throw</span> <span class="hljs-keyword">new</span> Error <span class="hljs-string">"value required for <span class="hljs-subst">#{needsArgOpt.flag}</span>, but it was the last
|
||||
argument provided"</span>
|
||||
<span class="hljs-keyword">throw</span> <span class="hljs-keyword">new</span> <span class="hljs-built_in">Error</span> <span class="hljs-string">"value required for <span class="hljs-subst">#{needsArgOpt.flag}</span>, but it was the last
|
||||
argument provided"</span>
|
||||
{rules, positional}</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
@@ -112,16 +112,16 @@
|
||||
<li id="section-1">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-1">¶</a>
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-1">§</a>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>CoffeeScript = <span class="hljs-built_in">require</span> <span class="hljs-string">'./'</span>
|
||||
child_process = <span class="hljs-built_in">require</span> <span class="hljs-string">'child_process'</span>
|
||||
helpers = <span class="hljs-built_in">require</span> <span class="hljs-string">'./helpers'</span>
|
||||
path = <span class="hljs-built_in">require</span> <span class="hljs-string">'path'</span></pre></div></div>
|
||||
<div class="content"><div class='highlight'><pre>CoffeeScript = <span class="hljs-built_in">require</span> <span class="hljs-string">'./'</span>
|
||||
child_process = <span class="hljs-built_in">require</span> <span class="hljs-string">'child_process'</span>
|
||||
helpers = <span class="hljs-built_in">require</span> <span class="hljs-string">'./helpers'</span>
|
||||
path = <span class="hljs-built_in">require</span> <span class="hljs-string">'path'</span></pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
@@ -129,16 +129,17 @@ path = <span class="hljs-built_in">require</span> <span class="hljs-str
|
||||
<li id="section-2">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-2">¶</a>
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-2">§</a>
|
||||
</div>
|
||||
<p>Load and run a CoffeeScript file for Node, stripping any <code>BOM</code>s.</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre><span class="hljs-function"><span class="hljs-title">loadFile</span> = <span class="hljs-params">(<span class="hljs-built_in">module</span>, filename)</span> -></span>
|
||||
answer = CoffeeScript._compileFile filename, <span class="hljs-literal">no</span>, <span class="hljs-literal">yes</span>
|
||||
<span class="hljs-built_in">module</span>._compile answer, filename</pre></div></div>
|
||||
<div class="content"><div class='highlight'><pre><span class="hljs-function"><span class="hljs-title">loadFile</span> = <span class="hljs-params">(module, filename)</span> -></span>
|
||||
options = module.options <span class="hljs-keyword">or</span> getRootModule(module).options
|
||||
answer = CoffeeScript._compileFile filename, options
|
||||
module._compile answer, filename</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
@@ -146,8 +147,8 @@ path = <span class="hljs-built_in">require</span> <span class="hljs-str
|
||||
<li id="section-3">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-3">¶</a>
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-3">§</a>
|
||||
</div>
|
||||
<p>If the installed version of Node supports <code>require.extensions</code>, register
|
||||
CoffeeScript as an extension.</p>
|
||||
@@ -164,18 +165,18 @@ CoffeeScript as an extension.</p>
|
||||
<li id="section-4">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-4">¶</a>
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-4">§</a>
|
||||
</div>
|
||||
<p>Patch Node’s module loader to be able to handle multi-dot extensions.
|
||||
This is a horrible thing that should not be required.</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre> Module = <span class="hljs-built_in">require</span> <span class="hljs-string">'module'</span>
|
||||
<div class="content"><div class='highlight'><pre> Module = <span class="hljs-built_in">require</span> <span class="hljs-string">'module'</span>
|
||||
<span class="hljs-function">
|
||||
<span class="hljs-title">findExtension</span> = <span class="hljs-params">(filename)</span> -></span>
|
||||
extensions = path.basename(filename).split <span class="hljs-string">'.'</span></pre></div></div>
|
||||
extensions = path.basename(filename).split <span class="hljs-string">'.'</span></pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
@@ -183,14 +184,14 @@ This is a horrible thing that should not be required.</p>
|
||||
<li id="section-5">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-5">¶</a>
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-5">§</a>
|
||||
</div>
|
||||
<p>Remove the initial dot from dotfiles.</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre> extensions.shift() <span class="hljs-keyword">if</span> extensions[<span class="hljs-number">0</span>] <span class="hljs-keyword">is</span> <span class="hljs-string">''</span></pre></div></div>
|
||||
<div class="content"><div class='highlight'><pre> extensions.shift() <span class="hljs-keyword">if</span> extensions[<span class="hljs-number">0</span>] <span class="hljs-keyword">is</span> <span class="hljs-string">''</span></pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
@@ -198,23 +199,23 @@ This is a horrible thing that should not be required.</p>
|
||||
<li id="section-6">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-6">¶</a>
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-6">§</a>
|
||||
</div>
|
||||
<p>Start with the longest possible extension and work our way shortwards.</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre> <span class="hljs-keyword">while</span> extensions.shift()
|
||||
curExtension = <span class="hljs-string">'.'</span> + extensions.join <span class="hljs-string">'.'</span>
|
||||
curExtension = <span class="hljs-string">'.'</span> + extensions.join <span class="hljs-string">'.'</span>
|
||||
<span class="hljs-keyword">return</span> curExtension <span class="hljs-keyword">if</span> Module._extensions[curExtension]
|
||||
<span class="hljs-string">'.js'</span>
|
||||
<span class="hljs-string">'.js'</span>
|
||||
|
||||
Module::load = <span class="hljs-function"><span class="hljs-params">(filename)</span> -></span>
|
||||
@filename = filename
|
||||
@paths = Module._nodeModulePaths path.dirname filename
|
||||
extension = findExtension filename
|
||||
Module._extensions[extension](<span class="hljs-keyword">this</span>, filename)
|
||||
Module._extensions[extension](this, filename)
|
||||
@loaded = <span class="hljs-literal">true</span></pre></div></div>
|
||||
|
||||
</li>
|
||||
@@ -223,8 +224,8 @@ This is a horrible thing that should not be required.</p>
|
||||
<li id="section-7">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-7">¶</a>
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-7">§</a>
|
||||
</div>
|
||||
<p>If we’re on Node, patch <code>child_process.fork</code> so that Coffee scripts are able
|
||||
to fork both CoffeeScript files, and JavaScript files, directly.</p>
|
||||
@@ -233,10 +234,10 @@ to fork both CoffeeScript files, and JavaScript files, directly.</p>
|
||||
|
||||
<div class="content"><div class='highlight'><pre><span class="hljs-keyword">if</span> child_process
|
||||
{fork} = child_process
|
||||
binary = <span class="hljs-built_in">require</span>.resolve <span class="hljs-string">'../../bin/coffee'</span>
|
||||
binary = <span class="hljs-built_in">require</span>.resolve <span class="hljs-string">'../../bin/coffee'</span>
|
||||
child_process.fork = <span class="hljs-function"><span class="hljs-params">(path, args, options)</span> -></span>
|
||||
<span class="hljs-keyword">if</span> helpers.isCoffee path
|
||||
<span class="hljs-keyword">unless</span> Array.isArray args
|
||||
<span class="hljs-keyword">unless</span> <span class="hljs-built_in">Array</span>.isArray args
|
||||
options = args <span class="hljs-keyword">or</span> {}
|
||||
args = []
|
||||
args = [path].concat args
|
||||
@@ -245,6 +246,22 @@ to fork both CoffeeScript files, and JavaScript files, directly.</p>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-8">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-8">§</a>
|
||||
</div>
|
||||
<p>Utility function to find the <code>options</code> object attached to the topmost module.</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre><span class="hljs-function"><span class="hljs-title">getRootModule</span> = <span class="hljs-params">(module)</span> -></span>
|
||||
<span class="hljs-keyword">if</span> module.parent <span class="hljs-keyword">then</span> getRootModule module.parent <span class="hljs-keyword">else</span> module</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
</div>
|
||||
</body>
|
||||
|
||||
@@ -112,26 +112,27 @@
|
||||
<li id="section-1">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-1">¶</a>
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-1">§</a>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>fs = <span class="hljs-built_in">require</span> <span class="hljs-string">'fs'</span>
|
||||
path = <span class="hljs-built_in">require</span> <span class="hljs-string">'path'</span>
|
||||
vm = <span class="hljs-built_in">require</span> <span class="hljs-string">'vm'</span>
|
||||
nodeREPL = <span class="hljs-built_in">require</span> <span class="hljs-string">'repl'</span>
|
||||
CoffeeScript = <span class="hljs-built_in">require</span> <span class="hljs-string">'./'</span>
|
||||
{merge, updateSyntaxError} = <span class="hljs-built_in">require</span> <span class="hljs-string">'./helpers'</span>
|
||||
<div class="content"><div class='highlight'><pre>fs = <span class="hljs-built_in">require</span> <span class="hljs-string">'fs'</span>
|
||||
path = <span class="hljs-built_in">require</span> <span class="hljs-string">'path'</span>
|
||||
vm = <span class="hljs-built_in">require</span> <span class="hljs-string">'vm'</span>
|
||||
nodeREPL = <span class="hljs-built_in">require</span> <span class="hljs-string">'repl'</span>
|
||||
CoffeeScript = <span class="hljs-built_in">require</span> <span class="hljs-string">'./'</span>
|
||||
{merge, updateSyntaxError} = <span class="hljs-built_in">require</span> <span class="hljs-string">'./helpers'</span>
|
||||
|
||||
sawSIGINT = <span class="hljs-literal">no</span>
|
||||
transpile = <span class="hljs-literal">no</span>
|
||||
|
||||
replDefaults =
|
||||
prompt: <span class="hljs-string">'coffee> '</span>,
|
||||
prompt: <span class="hljs-string">'coffee> '</span>,
|
||||
historyFile: <span class="hljs-keyword">do</span> ->
|
||||
historyPath = process.env.XDG_CACHE_HOME <span class="hljs-keyword">or</span> process.env.HOME
|
||||
path.join historyPath, <span class="hljs-string">'.coffee_history'</span> <span class="hljs-keyword">if</span> historyPath
|
||||
path.join historyPath, <span class="hljs-string">'.coffee_history'</span> <span class="hljs-keyword">if</span> historyPath
|
||||
historyMaxInputSize: <span class="hljs-number">10240</span>
|
||||
eval: <span class="hljs-function"><span class="hljs-params">(input, context, filename, cb)</span> -></span></pre></div></div>
|
||||
|
||||
@@ -141,14 +142,14 @@ replDefaults =
|
||||
<li id="section-2">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-2">¶</a>
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-2">§</a>
|
||||
</div>
|
||||
<p>XXX: multiline hack.</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre> input = input.replace <span class="hljs-regexp">/\uFF00/g</span>, <span class="hljs-string">'\n'</span></pre></div></div>
|
||||
<div class="content"><div class='highlight'><pre> input = input.replace <span class="hljs-regexp">/\uFF00/g</span>, <span class="hljs-string">'\n'</span></pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
@@ -156,15 +157,15 @@ replDefaults =
|
||||
<li id="section-3">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-3">¶</a>
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-3">§</a>
|
||||
</div>
|
||||
<p>Node’s REPL sends the input ending with a newline and then wrapped in
|
||||
parens. Unwrap all that.</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre> input = input.replace <span class="hljs-regexp">/^\(([\s\S]*)\n\)$/m</span>, <span class="hljs-string">'$1'</span></pre></div></div>
|
||||
<div class="content"><div class='highlight'><pre> input = input.replace <span class="hljs-regexp">/^\(([\s\S]*)\n\)$/m</span>, <span class="hljs-string">'$1'</span></pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
@@ -172,15 +173,15 @@ parens. Unwrap all that.</p>
|
||||
<li id="section-4">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-4">¶</a>
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-4">§</a>
|
||||
</div>
|
||||
<p>Node’s REPL v6.9.1+ sends the input wrapped in a try/catch statement.
|
||||
Unwrap that too.</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre> input = input.replace <span class="hljs-regexp">/^\s*try\s*{([\s\S]*)}\s*catch.*$/m</span>, <span class="hljs-string">'$1'</span></pre></div></div>
|
||||
<div class="content"><div class='highlight'><pre> input = input.replace <span class="hljs-regexp">/^\s*try\s*{([\s\S]*)}\s*catch.*$/m</span>, <span class="hljs-string">'$1'</span></pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
@@ -188,14 +189,14 @@ Unwrap that too.</p>
|
||||
<li id="section-5">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-5">¶</a>
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-5">§</a>
|
||||
</div>
|
||||
<p>Require AST nodes to do some AST manipulation.</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre> {Block, Assign, Value, Literal, Call, Code} = <span class="hljs-built_in">require</span> <span class="hljs-string">'./nodes'</span>
|
||||
<div class="content"><div class='highlight'><pre> {Block, Assign, Value, Literal, Call, Code, Root} = <span class="hljs-built_in">require</span> <span class="hljs-string">'./nodes'</span>
|
||||
|
||||
<span class="hljs-keyword">try</span></pre></div></div>
|
||||
|
||||
@@ -205,8 +206,8 @@ Unwrap that too.</p>
|
||||
<li id="section-6">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-6">¶</a>
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-6">§</a>
|
||||
</div>
|
||||
<p>Tokenize the clean input.</p>
|
||||
|
||||
@@ -220,14 +221,20 @@ Unwrap that too.</p>
|
||||
<li id="section-7">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-7">¶</a>
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-7">§</a>
|
||||
</div>
|
||||
<p>Collect referenced variable names just like in <code>CoffeeScript.compile</code>.</p>
|
||||
<p>Filter out tokens generated just to hold comments.</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre> referencedVars = (token[<span class="hljs-number">1</span>] <span class="hljs-keyword">for</span> token <span class="hljs-keyword">in</span> tokens <span class="hljs-keyword">when</span> token[<span class="hljs-number">0</span>] <span class="hljs-keyword">is</span> <span class="hljs-string">'IDENTIFIER'</span>)</pre></div></div>
|
||||
<div class="content"><div class='highlight'><pre> <span class="hljs-keyword">if</span> tokens.length >= <span class="hljs-number">2</span> <span class="hljs-keyword">and</span> tokens[<span class="hljs-number">0</span>].generated <span class="hljs-keyword">and</span>
|
||||
tokens[<span class="hljs-number">0</span>].comments?.length <span class="hljs-keyword">isnt</span> <span class="hljs-number">0</span> <span class="hljs-keyword">and</span> <span class="hljs-string">"<span class="hljs-subst">#{tokens[<span class="hljs-number">0</span>][<span class="hljs-number">1</span>]}</span>"</span> <span class="hljs-keyword">is</span> <span class="hljs-string">''</span> <span class="hljs-keyword">and</span>
|
||||
tokens[<span class="hljs-number">1</span>][<span class="hljs-number">0</span>] <span class="hljs-keyword">is</span> <span class="hljs-string">'TERMINATOR'</span>
|
||||
tokens = tokens[<span class="hljs-number">2.</span>..]
|
||||
<span class="hljs-keyword">if</span> tokens.length >= <span class="hljs-number">1</span> <span class="hljs-keyword">and</span> tokens[tokens.length - <span class="hljs-number">1</span>].generated <span class="hljs-keyword">and</span>
|
||||
tokens[tokens.length - <span class="hljs-number">1</span>].comments?.length <span class="hljs-keyword">isnt</span> <span class="hljs-number">0</span> <span class="hljs-keyword">and</span> <span class="hljs-string">"<span class="hljs-subst">#{tokens[tokens.length - <span class="hljs-number">1</span>][<span class="hljs-number">1</span>]}</span>"</span> <span class="hljs-keyword">is</span> <span class="hljs-string">''</span>
|
||||
tokens.pop()</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
@@ -235,14 +242,14 @@ Unwrap that too.</p>
|
||||
<li id="section-8">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-8">¶</a>
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-8">§</a>
|
||||
</div>
|
||||
<p>Generate the AST of the tokens.</p>
|
||||
<p>Collect referenced variable names just like in <code>CoffeeScript.compile</code>.</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre> ast = CoffeeScript.nodes tokens</pre></div></div>
|
||||
<div class="content"><div class='highlight'><pre> referencedVars = (token[<span class="hljs-number">1</span>] <span class="hljs-keyword">for</span> token <span class="hljs-keyword">in</span> tokens <span class="hljs-keyword">when</span> token[<span class="hljs-number">0</span>] <span class="hljs-keyword">is</span> <span class="hljs-string">'IDENTIFIER'</span>)</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
@@ -250,14 +257,14 @@ Unwrap that too.</p>
|
||||
<li id="section-9">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-9">¶</a>
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-9">§</a>
|
||||
</div>
|
||||
<p>Add assignment to <code>__</code> variable to force the input to be an expression.</p>
|
||||
<p>Generate the AST of the tokens.</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre> ast = <span class="hljs-keyword">new</span> Block [<span class="hljs-keyword">new</span> Assign (<span class="hljs-keyword">new</span> Value <span class="hljs-keyword">new</span> Literal <span class="hljs-string">'__'</span>), ast, <span class="hljs-string">'='</span>]</pre></div></div>
|
||||
<div class="content"><div class='highlight'><pre> ast = CoffeeScript.nodes(tokens).body</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
@@ -265,10 +272,25 @@ Unwrap that too.</p>
|
||||
<li id="section-10">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-10">¶</a>
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-10">§</a>
|
||||
</div>
|
||||
<p>Wrap the expression in a closure to support top-level <code>await</code></p>
|
||||
<p>Add assignment to <code>__</code> variable to force the input to be an expression.</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre> ast = <span class="hljs-keyword">new</span> Block [<span class="hljs-keyword">new</span> Assign (<span class="hljs-keyword">new</span> Value <span class="hljs-keyword">new</span> Literal <span class="hljs-string">'__'</span>), ast, <span class="hljs-string">'='</span>]</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-11">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-11">§</a>
|
||||
</div>
|
||||
<p>Wrap the expression in a closure to support top-level <code>await</code>.</p>
|
||||
|
||||
</div>
|
||||
|
||||
@@ -278,30 +300,48 @@ Unwrap that too.</p>
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-11">
|
||||
<li id="section-12">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-11">¶</a>
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-12">§</a>
|
||||
</div>
|
||||
<p>Invoke the wrapping closure</p>
|
||||
<p>Invoke the wrapping closure.</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre> ast = <span class="hljs-keyword">new</span> Block [<span class="hljs-keyword">new</span> Call ast]
|
||||
js = ast.compile {bare: <span class="hljs-literal">yes</span>, locals: Object.keys(context), referencedVars, sharedScope: <span class="hljs-literal">yes</span>}
|
||||
<div class="content"><div class='highlight'><pre> ast = <span class="hljs-keyword">new</span> Root <span class="hljs-keyword">new</span> Block [<span class="hljs-keyword">new</span> Call ast]
|
||||
js = ast.compile {bare: <span class="hljs-literal">yes</span>, locals: <span class="hljs-built_in">Object</span>.keys(context), referencedVars, sharedScope: <span class="hljs-literal">yes</span>}
|
||||
<span class="hljs-keyword">if</span> transpile
|
||||
js = transpile.transpile(js, transpile.options).code</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-13">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-13">§</a>
|
||||
</div>
|
||||
<p>Strip <code>"use strict"</code>, to avoid an exception on assigning to
|
||||
undeclared variable <code>__</code>.</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre> js = js.replace <span class="hljs-regexp">/^"use strict"|^'use strict'/</span>, <span class="hljs-string">''</span>
|
||||
result = runInContext js, context, filename</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-12">
|
||||
<li id="section-14">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-12">¶</a>
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-14">§</a>
|
||||
</div>
|
||||
<p>Await an async result, if necessary</p>
|
||||
<p>Await an async result, if necessary.</p>
|
||||
|
||||
</div>
|
||||
|
||||
@@ -316,11 +356,11 @@ Unwrap that too.</p>
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-13">
|
||||
<li id="section-15">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-13">¶</a>
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-15">§</a>
|
||||
</div>
|
||||
<p>AST’s <code>compile</code> does not add source code information to syntax errors.</p>
|
||||
|
||||
@@ -330,22 +370,22 @@ Unwrap that too.</p>
|
||||
cb err
|
||||
<span class="hljs-function">
|
||||
<span class="hljs-title">runInContext</span> = <span class="hljs-params">(js, context, filename)</span> -></span>
|
||||
<span class="hljs-keyword">if</span> context <span class="hljs-keyword">is</span> <span class="hljs-built_in">global</span>
|
||||
<span class="hljs-keyword">if</span> context <span class="hljs-keyword">is</span> global
|
||||
vm.runInThisContext js, filename
|
||||
<span class="hljs-keyword">else</span>
|
||||
vm.runInContext js, context, filename
|
||||
<span class="hljs-function">
|
||||
<span class="hljs-title">addMultilineHandler</span> = <span class="hljs-params">(repl)</span> -></span>
|
||||
{rli, inputStream, outputStream} = repl</pre></div></div>
|
||||
{inputStream, outputStream} = repl</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-14">
|
||||
<li id="section-16">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-14">¶</a>
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-16">§</a>
|
||||
</div>
|
||||
<p>Node 0.11.12 changed API, prompt is now _prompt.</p>
|
||||
|
||||
@@ -355,51 +395,9 @@ Unwrap that too.</p>
|
||||
|
||||
multiline =
|
||||
enabled: <span class="hljs-literal">off</span>
|
||||
initialPrompt: origPrompt.replace <span class="hljs-regexp">/^[^> ]*/</span>, <span class="hljs-function"><span class="hljs-params">(x)</span> -></span> x.replace <span class="hljs-regexp">/./g</span>, <span class="hljs-string">'-'</span>
|
||||
prompt: origPrompt.replace <span class="hljs-regexp">/^[^> ]*>?/</span>, <span class="hljs-function"><span class="hljs-params">(x)</span> -></span> x.replace <span class="hljs-regexp">/./g</span>, <span class="hljs-string">'.'</span>
|
||||
buffer: <span class="hljs-string">''</span></pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-15">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-15">¶</a>
|
||||
</div>
|
||||
<p>Proxy node’s line listener</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre> nodeLineListener = rli.listeners(<span class="hljs-string">'line'</span>)[<span class="hljs-number">0</span>]
|
||||
rli.removeListener <span class="hljs-string">'line'</span>, nodeLineListener
|
||||
rli.<span class="hljs-literal">on</span> <span class="hljs-string">'line'</span>, <span class="hljs-function"><span class="hljs-params">(cmd)</span> -></span>
|
||||
<span class="hljs-keyword">if</span> multiline.enabled
|
||||
multiline.buffer += <span class="hljs-string">"<span class="hljs-subst">#{cmd}</span>\n"</span>
|
||||
rli.setPrompt multiline.prompt
|
||||
rli.prompt <span class="hljs-literal">true</span>
|
||||
<span class="hljs-keyword">else</span>
|
||||
rli.setPrompt origPrompt
|
||||
nodeLineListener cmd
|
||||
<span class="hljs-keyword">return</span></pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-16">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-16">¶</a>
|
||||
</div>
|
||||
<p>Handle Ctrl-v</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre> inputStream.<span class="hljs-literal">on</span> <span class="hljs-string">'keypress'</span>, <span class="hljs-function"><span class="hljs-params">(char, key)</span> -></span>
|
||||
<span class="hljs-keyword">return</span> <span class="hljs-keyword">unless</span> key <span class="hljs-keyword">and</span> key.ctrl <span class="hljs-keyword">and</span> <span class="hljs-keyword">not</span> key.meta <span class="hljs-keyword">and</span> <span class="hljs-keyword">not</span> key.shift <span class="hljs-keyword">and</span> key.name <span class="hljs-keyword">is</span> <span class="hljs-string">'v'</span>
|
||||
<span class="hljs-keyword">if</span> multiline.enabled</pre></div></div>
|
||||
initialPrompt: origPrompt.replace <span class="hljs-regexp">/^[^> ]*/</span>, <span class="hljs-function"><span class="hljs-params">(x)</span> -></span> x.replace <span class="hljs-regexp">/./g</span>, <span class="hljs-string">'-'</span>
|
||||
prompt: origPrompt.replace <span class="hljs-regexp">/^[^> ]*>?/</span>, <span class="hljs-function"><span class="hljs-params">(x)</span> -></span> x.replace <span class="hljs-regexp">/./g</span>, <span class="hljs-string">'.'</span>
|
||||
buffer: <span class="hljs-string">''</span></pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
@@ -407,18 +405,24 @@ Unwrap that too.</p>
|
||||
<li id="section-17">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-17">¶</a>
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-17">§</a>
|
||||
</div>
|
||||
<p>allow arbitrarily switching between modes any time before multiple lines are entered</p>
|
||||
<p>Proxy node’s line listener</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre> <span class="hljs-keyword">unless</span> multiline.buffer.match <span class="hljs-regexp">/\n/</span>
|
||||
multiline.enabled = <span class="hljs-keyword">not</span> multiline.enabled
|
||||
rli.setPrompt origPrompt
|
||||
rli.prompt <span class="hljs-literal">true</span>
|
||||
<span class="hljs-keyword">return</span></pre></div></div>
|
||||
<div class="content"><div class='highlight'><pre> nodeLineListener = repl.listeners(<span class="hljs-string">'line'</span>)[<span class="hljs-number">0</span>]
|
||||
repl.removeListener <span class="hljs-string">'line'</span>, nodeLineListener
|
||||
repl.<span class="hljs-literal">on</span> <span class="hljs-string">'line'</span>, <span class="hljs-function"><span class="hljs-params">(cmd)</span> -></span>
|
||||
<span class="hljs-keyword">if</span> multiline.enabled
|
||||
multiline.buffer += <span class="hljs-string">"<span class="hljs-subst">#{cmd}</span>\n"</span>
|
||||
repl.setPrompt multiline.prompt
|
||||
repl.prompt <span class="hljs-literal">true</span>
|
||||
<span class="hljs-keyword">else</span>
|
||||
repl.setPrompt origPrompt
|
||||
nodeLineListener cmd
|
||||
<span class="hljs-keyword">return</span></pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
@@ -426,14 +430,16 @@ Unwrap that too.</p>
|
||||
<li id="section-18">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-18">¶</a>
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-18">§</a>
|
||||
</div>
|
||||
<p>no-op unless the current line is empty</p>
|
||||
<p>Handle Ctrl-v</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre> <span class="hljs-keyword">return</span> <span class="hljs-keyword">if</span> rli.line? <span class="hljs-keyword">and</span> <span class="hljs-keyword">not</span> rli.line.match <span class="hljs-regexp">/^\s*$/</span></pre></div></div>
|
||||
<div class="content"><div class='highlight'><pre> inputStream.<span class="hljs-literal">on</span> <span class="hljs-string">'keypress'</span>, <span class="hljs-function"><span class="hljs-params">(char, key)</span> -></span>
|
||||
<span class="hljs-keyword">return</span> <span class="hljs-keyword">unless</span> key <span class="hljs-keyword">and</span> key.ctrl <span class="hljs-keyword">and</span> <span class="hljs-keyword">not</span> key.meta <span class="hljs-keyword">and</span> <span class="hljs-keyword">not</span> key.shift <span class="hljs-keyword">and</span> key.name <span class="hljs-keyword">is</span> <span class="hljs-string">'v'</span>
|
||||
<span class="hljs-keyword">if</span> multiline.enabled</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
@@ -441,18 +447,18 @@ Unwrap that too.</p>
|
||||
<li id="section-19">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-19">¶</a>
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-19">§</a>
|
||||
</div>
|
||||
<p>eval, print, loop</p>
|
||||
<p>allow arbitrarily switching between modes any time before multiple lines are entered</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre> multiline.enabled = <span class="hljs-keyword">not</span> multiline.enabled
|
||||
rli.line = <span class="hljs-string">''</span>
|
||||
rli.cursor = <span class="hljs-number">0</span>
|
||||
rli.output.cursorTo <span class="hljs-number">0</span>
|
||||
rli.output.clearLine <span class="hljs-number">1</span></pre></div></div>
|
||||
<div class="content"><div class='highlight'><pre> <span class="hljs-keyword">unless</span> multiline.buffer.match <span class="hljs-regexp">/\n/</span>
|
||||
multiline.enabled = <span class="hljs-keyword">not</span> multiline.enabled
|
||||
repl.setPrompt origPrompt
|
||||
repl.prompt <span class="hljs-literal">true</span>
|
||||
<span class="hljs-keyword">return</span></pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
@@ -460,21 +466,14 @@ Unwrap that too.</p>
|
||||
<li id="section-20">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-20">¶</a>
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-20">§</a>
|
||||
</div>
|
||||
<p>XXX: multiline hack</p>
|
||||
<p>no-op unless the current line is empty</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre> multiline.buffer = multiline.buffer.replace <span class="hljs-regexp">/\n/g</span>, <span class="hljs-string">'\uFF00'</span>
|
||||
rli.emit <span class="hljs-string">'line'</span>, multiline.buffer
|
||||
multiline.buffer = <span class="hljs-string">''</span>
|
||||
<span class="hljs-keyword">else</span>
|
||||
multiline.enabled = <span class="hljs-keyword">not</span> multiline.enabled
|
||||
rli.setPrompt multiline.initialPrompt
|
||||
rli.prompt <span class="hljs-literal">true</span>
|
||||
<span class="hljs-keyword">return</span></pre></div></div>
|
||||
<div class="content"><div class='highlight'><pre> <span class="hljs-keyword">return</span> <span class="hljs-keyword">if</span> repl.line? <span class="hljs-keyword">and</span> <span class="hljs-keyword">not</span> repl.line.match <span class="hljs-regexp">/^\s*$/</span></pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
@@ -482,8 +481,49 @@ Unwrap that too.</p>
|
||||
<li id="section-21">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-21">¶</a>
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-21">§</a>
|
||||
</div>
|
||||
<p>eval, print, loop</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre> multiline.enabled = <span class="hljs-keyword">not</span> multiline.enabled
|
||||
repl.line = <span class="hljs-string">''</span>
|
||||
repl.cursor = <span class="hljs-number">0</span>
|
||||
repl.output.cursorTo <span class="hljs-number">0</span>
|
||||
repl.output.clearLine <span class="hljs-number">1</span></pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-22">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-22">§</a>
|
||||
</div>
|
||||
<p>XXX: multiline hack</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre> multiline.buffer = multiline.buffer.replace <span class="hljs-regexp">/\n/g</span>, <span class="hljs-string">'\uFF00'</span>
|
||||
repl.emit <span class="hljs-string">'line'</span>, multiline.buffer
|
||||
multiline.buffer = <span class="hljs-string">''</span>
|
||||
<span class="hljs-keyword">else</span>
|
||||
multiline.enabled = <span class="hljs-keyword">not</span> multiline.enabled
|
||||
repl.setPrompt multiline.initialPrompt
|
||||
repl.prompt <span class="hljs-literal">true</span>
|
||||
<span class="hljs-keyword">return</span></pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-23">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-23">§</a>
|
||||
</div>
|
||||
<p>Store and load command history from a file</p>
|
||||
|
||||
@@ -496,51 +536,18 @@ Unwrap that too.</p>
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-22">
|
||||
<li id="section-24">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-22">¶</a>
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-24">§</a>
|
||||
</div>
|
||||
<p>Get file info and at most maxSize of command history</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre> stat = fs.statSync filename
|
||||
size = Math.min maxSize, stat.size</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-23">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-23">¶</a>
|
||||
</div>
|
||||
<p>Read last <code>size</code> bytes from the file</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre> readFd = fs.openSync filename, <span class="hljs-string">'r'</span>
|
||||
buffer = Buffer.alloc size
|
||||
fs.readSync readFd, buffer, <span class="hljs-number">0</span>, size, stat.size - size
|
||||
fs.closeSync readFd</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-24">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-24">¶</a>
|
||||
</div>
|
||||
<p>Set the history on the interpreter</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre> repl.rli.history = buffer.toString().split(<span class="hljs-string">'\n'</span>).reverse()</pre></div></div>
|
||||
size = <span class="hljs-built_in">Math</span>.min maxSize, stat.size</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
@@ -548,14 +555,17 @@ Unwrap that too.</p>
|
||||
<li id="section-25">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-25">¶</a>
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-25">§</a>
|
||||
</div>
|
||||
<p>If the history file was truncated we should pop off a potential partial line</p>
|
||||
<p>Read last <code>size</code> bytes from the file</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre> repl.rli.history.pop() <span class="hljs-keyword">if</span> stat.size > maxSize</pre></div></div>
|
||||
<div class="content"><div class='highlight'><pre> readFd = fs.openSync filename, <span class="hljs-string">'r'</span>
|
||||
buffer = Buffer.alloc size
|
||||
fs.readSync readFd, buffer, <span class="hljs-number">0</span>, size, stat.size - size
|
||||
fs.closeSync readFd</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
@@ -563,21 +573,14 @@ Unwrap that too.</p>
|
||||
<li id="section-26">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-26">¶</a>
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-26">§</a>
|
||||
</div>
|
||||
<p>Shift off the final blank newline</p>
|
||||
<p>Set the history on the interpreter</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre> repl.rli.history.shift() <span class="hljs-keyword">if</span> repl.rli.history[<span class="hljs-number">0</span>] <span class="hljs-keyword">is</span> <span class="hljs-string">''</span>
|
||||
repl.rli.historyIndex = <span class="hljs-number">-1</span>
|
||||
lastLine = repl.rli.history[<span class="hljs-number">0</span>]
|
||||
|
||||
fd = fs.openSync filename, <span class="hljs-string">'a'</span>
|
||||
|
||||
repl.rli.addListener <span class="hljs-string">'line'</span>, <span class="hljs-function"><span class="hljs-params">(code)</span> -></span>
|
||||
<span class="hljs-keyword">if</span> code <span class="hljs-keyword">and</span> code.length <span class="hljs-keyword">and</span> code <span class="hljs-keyword">isnt</span> <span class="hljs-string">'.history'</span> <span class="hljs-keyword">and</span> code <span class="hljs-keyword">isnt</span> <span class="hljs-string">'.exit'</span> <span class="hljs-keyword">and</span> lastLine <span class="hljs-keyword">isnt</span> code</pre></div></div>
|
||||
<div class="content"><div class='highlight'><pre> repl.history = buffer.toString().split(<span class="hljs-string">'\n'</span>).reverse()</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
@@ -585,15 +588,14 @@ Unwrap that too.</p>
|
||||
<li id="section-27">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-27">¶</a>
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-27">§</a>
|
||||
</div>
|
||||
<p>Save the latest command in the file</p>
|
||||
<p>If the history file was truncated we should pop off a potential partial line</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre> fs.writeSync fd, <span class="hljs-string">"<span class="hljs-subst">#{code}</span>\n"</span>
|
||||
lastLine = code</pre></div></div>
|
||||
<div class="content"><div class='highlight'><pre> repl.history.pop() <span class="hljs-keyword">if</span> stat.size > maxSize</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
@@ -601,15 +603,21 @@ Unwrap that too.</p>
|
||||
<li id="section-28">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-28">¶</a>
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-28">§</a>
|
||||
</div>
|
||||
<p>XXX: The SIGINT event from REPLServer is undocumented, so this is a bit fragile</p>
|
||||
<p>Shift off the final blank newline</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre> repl.<span class="hljs-literal">on</span> <span class="hljs-string">'SIGINT'</span>, <span class="hljs-function">-></span> sawSIGINT = <span class="hljs-literal">yes</span>
|
||||
repl.<span class="hljs-literal">on</span> <span class="hljs-string">'exit'</span>, <span class="hljs-function">-></span> fs.closeSync fd</pre></div></div>
|
||||
<div class="content"><div class='highlight'><pre> repl.history.shift() <span class="hljs-keyword">if</span> repl.history[<span class="hljs-number">0</span>] <span class="hljs-keyword">is</span> <span class="hljs-string">''</span>
|
||||
repl.historyIndex = <span class="hljs-number">-1</span>
|
||||
lastLine = repl.history[<span class="hljs-number">0</span>]
|
||||
|
||||
fd = fs.openSync filename, <span class="hljs-string">'a'</span>
|
||||
|
||||
repl.addListener <span class="hljs-string">'line'</span>, <span class="hljs-function"><span class="hljs-params">(code)</span> -></span>
|
||||
<span class="hljs-keyword">if</span> code <span class="hljs-keyword">and</span> code.length <span class="hljs-keyword">and</span> code <span class="hljs-keyword">isnt</span> <span class="hljs-string">'.history'</span> <span class="hljs-keyword">and</span> code <span class="hljs-keyword">isnt</span> <span class="hljs-string">'.exit'</span> <span class="hljs-keyword">and</span> lastLine <span class="hljs-keyword">isnt</span> code</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
@@ -617,20 +625,15 @@ Unwrap that too.</p>
|
||||
<li id="section-29">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-29">¶</a>
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-29">§</a>
|
||||
</div>
|
||||
<p>Add a command to show the history stack</p>
|
||||
<p>Save the latest command in the file</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre> repl.commands[getCommandId(repl, <span class="hljs-string">'history'</span>)] =
|
||||
help: <span class="hljs-string">'Show command history'</span>
|
||||
action: <span class="hljs-function">-></span>
|
||||
repl.outputStream.write <span class="hljs-string">"<span class="hljs-subst">#{repl.rli.history[..].reverse().join <span class="hljs-string">'\n'</span>}</span>\n"</span>
|
||||
repl.displayPrompt()
|
||||
<span class="hljs-function">
|
||||
<span class="hljs-title">getCommandId</span> = <span class="hljs-params">(repl, commandName)</span> -></span></pre></div></div>
|
||||
<div class="content"><div class='highlight'><pre> fs.writeSync fd, <span class="hljs-string">"<span class="hljs-subst">#{code}</span>\n"</span>
|
||||
lastLine = code</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
@@ -638,32 +641,15 @@ Unwrap that too.</p>
|
||||
<li id="section-30">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-30">¶</a>
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-30">§</a>
|
||||
</div>
|
||||
<p>Node 0.11 changed API, a command such as ‘.help’ is now stored as ‘help’</p>
|
||||
<p>XXX: The SIGINT event from REPLServer is undocumented, so this is a bit fragile</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre> commandsHaveLeadingDot = repl.commands[<span class="hljs-string">'.help'</span>]?
|
||||
<span class="hljs-keyword">if</span> commandsHaveLeadingDot <span class="hljs-keyword">then</span> <span class="hljs-string">".<span class="hljs-subst">#{commandName}</span>"</span> <span class="hljs-keyword">else</span> commandName
|
||||
|
||||
<span class="hljs-built_in">module</span>.exports =
|
||||
start: <span class="hljs-function"><span class="hljs-params">(opts = {})</span> -></span>
|
||||
[major, minor, build] = process.versions.node.split(<span class="hljs-string">'.'</span>).map (n) -> parseInt(n, <span class="hljs-number">10</span>)
|
||||
|
||||
<span class="hljs-keyword">if</span> major < <span class="hljs-number">6</span>
|
||||
<span class="hljs-built_in">console</span>.warn <span class="hljs-string">"Node 6+ required for CoffeeScript REPL"</span>
|
||||
process.exit <span class="hljs-number">1</span>
|
||||
|
||||
CoffeeScript.register()
|
||||
process.argv = [<span class="hljs-string">'coffee'</span>].concat process.argv[<span class="hljs-number">2.</span>.]
|
||||
opts = merge replDefaults, opts
|
||||
repl = nodeREPL.start opts
|
||||
runInContext opts.prelude, repl.context, <span class="hljs-string">'prelude'</span> <span class="hljs-keyword">if</span> opts.prelude
|
||||
repl.<span class="hljs-literal">on</span> <span class="hljs-string">'exit'</span>, <span class="hljs-function">-></span> repl.outputStream.write <span class="hljs-string">'\n'</span> <span class="hljs-keyword">if</span> <span class="hljs-keyword">not</span> repl.rli.closed
|
||||
addMultilineHandler repl
|
||||
addHistory repl, opts.historyFile, opts.historyMaxInputSize <span class="hljs-keyword">if</span> opts.historyFile</pre></div></div>
|
||||
<div class="content"><div class='highlight'><pre> repl.<span class="hljs-literal">on</span> <span class="hljs-string">'SIGINT'</span>, <span class="hljs-function">-></span> sawSIGINT = <span class="hljs-literal">yes</span>
|
||||
repl.<span class="hljs-literal">on</span> <span class="hljs-string">'exit'</span>, <span class="hljs-function">-></span> fs.closeSync fd</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
@@ -671,14 +657,109 @@ Unwrap that too.</p>
|
||||
<li id="section-31">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-31">¶</a>
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-31">§</a>
|
||||
</div>
|
||||
<p>Add a command to show the history stack</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre> repl.commands[getCommandId(repl, <span class="hljs-string">'history'</span>)] =
|
||||
help: <span class="hljs-string">'Show command history'</span>
|
||||
action: <span class="hljs-function">-></span>
|
||||
repl.outputStream.write <span class="hljs-string">"<span class="hljs-subst">#{repl.history[..].reverse().join <span class="hljs-string">'\n'</span>}</span>\n"</span>
|
||||
repl.displayPrompt()
|
||||
<span class="hljs-function">
|
||||
<span class="hljs-title">getCommandId</span> = <span class="hljs-params">(repl, commandName)</span> -></span></pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-32">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-32">§</a>
|
||||
</div>
|
||||
<p>Node 0.11 changed API, a command such as ‘.help’ is now stored as ‘help’</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre> commandsHaveLeadingDot = repl.commands[<span class="hljs-string">'.help'</span>]?
|
||||
<span class="hljs-keyword">if</span> commandsHaveLeadingDot <span class="hljs-keyword">then</span> <span class="hljs-string">".<span class="hljs-subst">#{commandName}</span>"</span> <span class="hljs-keyword">else</span> commandName
|
||||
|
||||
module.<span class="hljs-built_in">exports</span> =
|
||||
start: <span class="hljs-function"><span class="hljs-params">(opts = {})</span> -></span>
|
||||
[major, minor, build] = process.versions.node.split(<span class="hljs-string">'.'</span>).map (n) -> <span class="hljs-built_in">parseInt</span>(n, <span class="hljs-number">10</span>)
|
||||
|
||||
<span class="hljs-keyword">if</span> major < <span class="hljs-number">6</span>
|
||||
console.warn <span class="hljs-string">"Node 6+ required for CoffeeScript REPL"</span>
|
||||
process.exit <span class="hljs-number">1</span>
|
||||
|
||||
CoffeeScript.register()
|
||||
process.argv = [<span class="hljs-string">'coffee'</span>].concat process.argv[<span class="hljs-number">2.</span>.]
|
||||
<span class="hljs-keyword">if</span> opts.transpile
|
||||
transpile = {}
|
||||
<span class="hljs-keyword">try</span>
|
||||
transpile.transpile = <span class="hljs-built_in">require</span>(<span class="hljs-string">'@babel/core'</span>).transform
|
||||
<span class="hljs-keyword">catch</span>
|
||||
<span class="hljs-keyword">try</span>
|
||||
transpile.transpile = <span class="hljs-built_in">require</span>(<span class="hljs-string">'babel-core'</span>).transform
|
||||
<span class="hljs-keyword">catch</span>
|
||||
console.error <span class="hljs-string">'''
|
||||
To use --transpile with an interactive REPL, @babel/core must be installed either in the current folder or globally:
|
||||
npm install --save-dev @babel/core
|
||||
or
|
||||
npm install --global @babel/core
|
||||
And you must save options to configure Babel in one of the places it looks to find its options.
|
||||
See https://coffeescript.org/#transpilation
|
||||
'''</span>
|
||||
process.exit <span class="hljs-number">1</span>
|
||||
transpile.options =
|
||||
filename: path.resolve process.cwd(), <span class="hljs-string">'<repl>'</span></pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-33">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-33">§</a>
|
||||
</div>
|
||||
<p>Since the REPL compilation path is unique (in <code>eval</code> above), we need
|
||||
another way to get the <code>options</code> object attached to a module so that
|
||||
it knows later on whether it needs to be transpiled. In the case of
|
||||
the REPL, the only applicable option is <code>transpile</code>.</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre> Module = <span class="hljs-built_in">require</span> <span class="hljs-string">'module'</span>
|
||||
originalModuleLoad = Module::load
|
||||
Module::load = <span class="hljs-function"><span class="hljs-params">(filename)</span> -></span>
|
||||
@options = transpile: transpile.options
|
||||
originalModuleLoad.call @, filename
|
||||
opts = merge replDefaults, opts
|
||||
repl = nodeREPL.start opts
|
||||
runInContext opts.prelude, repl.context, <span class="hljs-string">'prelude'</span> <span class="hljs-keyword">if</span> opts.prelude
|
||||
repl.<span class="hljs-literal">on</span> <span class="hljs-string">'exit'</span>, <span class="hljs-function">-></span> repl.outputStream.write <span class="hljs-string">'\n'</span> <span class="hljs-keyword">if</span> <span class="hljs-keyword">not</span> repl.closed
|
||||
addMultilineHandler repl
|
||||
addHistory repl, opts.historyFile, opts.historyMaxInputSize <span class="hljs-keyword">if</span> opts.historyFile</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-34">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-34">§</a>
|
||||
</div>
|
||||
<p>Adapt help inherited from the node REPL</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre> repl.commands[getCommandId(repl, <span class="hljs-string">'load'</span>)].help = <span class="hljs-string">'Load code from a file into this REPL session'</span>
|
||||
<div class="content"><div class='highlight'><pre> repl.commands[getCommandId(repl, <span class="hljs-string">'load'</span>)].help = <span class="hljs-string">'Load code from a file into this REPL session'</span>
|
||||
repl</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -112,8 +112,8 @@
|
||||
<li id="section-1">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-1">¶</a>
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-1">§</a>
|
||||
</div>
|
||||
<p>The <strong>Scope</strong> class regulates lexical scoping within CoffeeScript. As you
|
||||
generate code, you create a tree of scopes in the same shape as the nested
|
||||
@@ -124,7 +124,7 @@ with external scopes.</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre>exports.Scope = <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Scope</span></span></pre></div></div>
|
||||
<div class="content"><div class='highlight'><pre><span class="hljs-built_in">exports</span>.Scope = <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Scope</span></span></pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
@@ -132,19 +132,21 @@ with external scopes.</p>
|
||||
<li id="section-2">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-2">¶</a>
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-2">§</a>
|
||||
</div>
|
||||
<p>Initialize a scope with its parent, for lookups up the chain,
|
||||
as well as a reference to the <strong>Block</strong> node it belongs to, which is
|
||||
where it should declare its variables, a reference to the function that
|
||||
it belongs to, and a list of variables referenced in the source code
|
||||
and therefore should be avoided when generating variables.</p>
|
||||
and therefore should be avoided when generating variables. Also track comments
|
||||
that should be output as part of variable declarations.</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre> constructor: <span class="hljs-function"><span class="hljs-params">(@parent, @expressions, @method, @referencedVars)</span> -></span>
|
||||
@variables = [{name: <span class="hljs-string">'arguments'</span>, type: <span class="hljs-string">'arguments'</span>}]
|
||||
@variables = [{name: <span class="hljs-string">'arguments'</span>, type: <span class="hljs-string">'arguments'</span>}]
|
||||
@comments = {}
|
||||
@positions = {}
|
||||
@utilities = {} <span class="hljs-keyword">unless</span> @parent</pre></div></div>
|
||||
|
||||
@@ -154,14 +156,14 @@ and therefore should be avoided when generating variables.</p>
|
||||
<li id="section-3">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-3">¶</a>
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-3">§</a>
|
||||
</div>
|
||||
<p>The <code>@root</code> is the top-level <strong>Scope</strong> object for a given file.</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre> @root = @parent?.root ? <span class="hljs-keyword">this</span></pre></div></div>
|
||||
<div class="content"><div class='highlight'><pre> @root = @parent?.root ? this</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
@@ -169,8 +171,8 @@ and therefore should be avoided when generating variables.</p>
|
||||
<li id="section-4">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-4">¶</a>
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-4">§</a>
|
||||
</div>
|
||||
<p>Adds a new variable or overrides an existing one.</p>
|
||||
|
||||
@@ -189,8 +191,8 @@ and therefore should be avoided when generating variables.</p>
|
||||
<li id="section-5">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-5">¶</a>
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-5">§</a>
|
||||
</div>
|
||||
<p>When <code>super</code> is called, we need to find the name of the current method we’re
|
||||
in, so that we know how to invoke the same method of the parent class. This
|
||||
@@ -210,15 +212,15 @@ function object that has a name filled in, or bottoms out.</p>
|
||||
<li id="section-6">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-6">¶</a>
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-6">§</a>
|
||||
</div>
|
||||
<p>Look up a variable name in lexical scope, and declare it if it does not
|
||||
already exist.</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre> find: <span class="hljs-function"><span class="hljs-params">(name, type = <span class="hljs-string">'var'</span>)</span> -></span>
|
||||
<div class="content"><div class='highlight'><pre> find: <span class="hljs-function"><span class="hljs-params">(name, type = <span class="hljs-string">'var'</span>)</span> -></span>
|
||||
<span class="hljs-keyword">return</span> <span class="hljs-literal">yes</span> <span class="hljs-keyword">if</span> @check name
|
||||
@add name, type
|
||||
<span class="hljs-literal">no</span></pre></div></div>
|
||||
@@ -229,8 +231,8 @@ already exist.</p>
|
||||
<li id="section-7">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-7">¶</a>
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-7">§</a>
|
||||
</div>
|
||||
<p>Reserve a variable name as originating from a function parameter for this
|
||||
scope. No <code>var</code> required for internal references.</p>
|
||||
@@ -239,7 +241,7 @@ scope. No <code>var</code> required for internal references.</p>
|
||||
|
||||
<div class="content"><div class='highlight'><pre> parameter: <span class="hljs-function"><span class="hljs-params">(name)</span> -></span>
|
||||
<span class="hljs-keyword">return</span> <span class="hljs-keyword">if</span> @shared <span class="hljs-keyword">and</span> @parent.check name, <span class="hljs-literal">yes</span>
|
||||
@add name, <span class="hljs-string">'param'</span></pre></div></div>
|
||||
@add name, <span class="hljs-string">'param'</span></pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
@@ -247,8 +249,8 @@ scope. No <code>var</code> required for internal references.</p>
|
||||
<li id="section-8">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-8">¶</a>
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-8">§</a>
|
||||
</div>
|
||||
<p>Just check to see if a variable has already been declared, without reserving,
|
||||
walks up to the root scope.</p>
|
||||
@@ -264,8 +266,8 @@ walks up to the root scope.</p>
|
||||
<li id="section-9">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-9">¶</a>
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-9">§</a>
|
||||
</div>
|
||||
<p>Generate a temporary variable name at the given index.</p>
|
||||
|
||||
@@ -274,14 +276,14 @@ walks up to the root scope.</p>
|
||||
<div class="content"><div class='highlight'><pre> temporary: <span class="hljs-function"><span class="hljs-params">(name, index, single=<span class="hljs-literal">false</span>)</span> -></span>
|
||||
<span class="hljs-keyword">if</span> single
|
||||
startCode = name.charCodeAt(<span class="hljs-number">0</span>)
|
||||
endCode = <span class="hljs-string">'z'</span>.charCodeAt(<span class="hljs-number">0</span>)
|
||||
endCode = <span class="hljs-string">'z'</span>.charCodeAt(<span class="hljs-number">0</span>)
|
||||
diff = endCode - startCode
|
||||
newCode = startCode + index % (diff + <span class="hljs-number">1</span>)
|
||||
letter = String.fromCharCode(newCode)
|
||||
letter = <span class="hljs-built_in">String</span>.fromCharCode(newCode)
|
||||
num = index <span class="hljs-regexp">//</span> (diff + <span class="hljs-number">1</span>)
|
||||
<span class="hljs-string">"<span class="hljs-subst">#{letter}</span><span class="hljs-subst">#{num <span class="hljs-keyword">or</span> <span class="hljs-string">''</span>}</span>"</span>
|
||||
<span class="hljs-string">"<span class="hljs-subst">#{letter}</span><span class="hljs-subst">#{num <span class="hljs-keyword">or</span> <span class="hljs-string">''</span>}</span>"</span>
|
||||
<span class="hljs-keyword">else</span>
|
||||
<span class="hljs-string">"<span class="hljs-subst">#{name}</span><span class="hljs-subst">#{index <span class="hljs-keyword">or</span> <span class="hljs-string">''</span>}</span>"</span></pre></div></div>
|
||||
<span class="hljs-string">"<span class="hljs-subst">#{name}</span><span class="hljs-subst">#{index <span class="hljs-keyword">or</span> <span class="hljs-string">''</span>}</span>"</span></pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
@@ -289,8 +291,8 @@ walks up to the root scope.</p>
|
||||
<li id="section-10">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-10">¶</a>
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-10">§</a>
|
||||
</div>
|
||||
<p>Gets the type of a variable.</p>
|
||||
|
||||
@@ -306,8 +308,8 @@ walks up to the root scope.</p>
|
||||
<li id="section-11">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-11">¶</a>
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-11">§</a>
|
||||
</div>
|
||||
<p>If we need to store an intermediate result, find an available name for a
|
||||
compiler-generated variable. <code>_var</code>, <code>_var2</code>, and so on…</p>
|
||||
@@ -320,7 +322,7 @@ compiler-generated variable. <code>_var</code>, <code>_var2</code>, and so on…
|
||||
temp = @temporary name, index, options.single
|
||||
<span class="hljs-keyword">break</span> <span class="hljs-keyword">unless</span> @check(temp) <span class="hljs-keyword">or</span> temp <span class="hljs-keyword">in</span> @root.referencedVars
|
||||
index++
|
||||
@add temp, <span class="hljs-string">'var'</span>, <span class="hljs-literal">yes</span> <span class="hljs-keyword">if</span> options.reserve ? <span class="hljs-literal">true</span>
|
||||
@add temp, <span class="hljs-string">'var'</span>, <span class="hljs-literal">yes</span> <span class="hljs-keyword">if</span> options.reserve ? <span class="hljs-literal">true</span>
|
||||
temp</pre></div></div>
|
||||
|
||||
</li>
|
||||
@@ -329,8 +331,8 @@ compiler-generated variable. <code>_var</code>, <code>_var2</code>, and so on…
|
||||
<li id="section-12">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-12">¶</a>
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-12">§</a>
|
||||
</div>
|
||||
<p>Ensure that an assignment is made at the top of this scope
|
||||
(or at the top-level scope, if requested).</p>
|
||||
@@ -347,8 +349,8 @@ compiler-generated variable. <code>_var</code>, <code>_var2</code>, and so on…
|
||||
<li id="section-13">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-13">¶</a>
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-13">§</a>
|
||||
</div>
|
||||
<p>Does this scope have any declared variables?</p>
|
||||
|
||||
@@ -363,15 +365,15 @@ compiler-generated variable. <code>_var</code>, <code>_var2</code>, and so on…
|
||||
<li id="section-14">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-14">¶</a>
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-14">§</a>
|
||||
</div>
|
||||
<p>Return the list of variables first declared in this scope.</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre> declaredVariables: <span class="hljs-function">-></span>
|
||||
(v.name <span class="hljs-keyword">for</span> v <span class="hljs-keyword">in</span> @variables <span class="hljs-keyword">when</span> v.type <span class="hljs-keyword">is</span> <span class="hljs-string">'var'</span>).sort()</pre></div></div>
|
||||
(v.name <span class="hljs-keyword">for</span> v <span class="hljs-keyword">in</span> @variables <span class="hljs-keyword">when</span> v.type <span class="hljs-keyword">is</span> <span class="hljs-string">'var'</span>).sort()</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
@@ -379,8 +381,8 @@ compiler-generated variable. <code>_var</code>, <code>_var2</code>, and so on…
|
||||
<li id="section-15">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-15">¶</a>
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-15">§</a>
|
||||
</div>
|
||||
<p>Return the list of assignments that are supposed to be made at the top
|
||||
of this scope.</p>
|
||||
@@ -388,7 +390,7 @@ of this scope.</p>
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre> assignedVariables: <span class="hljs-function">-></span>
|
||||
<span class="hljs-string">"<span class="hljs-subst">#{v.name}</span> = <span class="hljs-subst">#{v.type.value}</span>"</span> <span class="hljs-keyword">for</span> v <span class="hljs-keyword">in</span> @variables <span class="hljs-keyword">when</span> v.type.assigned</pre></div></div>
|
||||
<span class="hljs-string">"<span class="hljs-subst">#{v.name}</span> = <span class="hljs-subst">#{v.type.value}</span>"</span> <span class="hljs-keyword">for</span> v <span class="hljs-keyword">in</span> @variables <span class="hljs-keyword">when</span> v.type.assigned</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
@@ -112,8 +112,8 @@
|
||||
<li id="section-1">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-1">¶</a>
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-1">§</a>
|
||||
</div>
|
||||
<p>Source maps allow JavaScript runtimes to match running JavaScript back to
|
||||
the original source code that corresponds to it. This can be minified
|
||||
@@ -134,8 +134,8 @@ of this information — to write out alongside the generated JavaScript.</p>
|
||||
<li id="section-2">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-2">¶</a>
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-2">§</a>
|
||||
</div>
|
||||
<p>A <strong>LineMap</strong> object keeps track of information about original line and column
|
||||
positions for a single line of output JavaScript code.
|
||||
@@ -161,8 +161,8 @@ positions for a single line of output JavaScript code.
|
||||
<li id="section-3">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-3">¶</a>
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-3">§</a>
|
||||
</div>
|
||||
<h2 id="sourcemap">SourceMap</h2>
|
||||
|
||||
@@ -174,8 +174,8 @@ positions for a single line of output JavaScript code.
|
||||
<li id="section-4">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-4">¶</a>
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-4">§</a>
|
||||
</div>
|
||||
<p>Maps locations in a single generated JavaScript file back to locations in
|
||||
the original CoffeeScript source file.</p>
|
||||
@@ -195,8 +195,8 @@ through the arrays of line and column buffer to produce it.</p>
|
||||
<li id="section-5">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-5">¶</a>
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-5">§</a>
|
||||
</div>
|
||||
<p>Adds a mapping to this SourceMap. <code>sourceLocation</code> and <code>generatedLocation</code>
|
||||
are both <code>[line, column]</code> arrays. If <code>options.noReplace</code> is true, then if there
|
||||
@@ -216,8 +216,8 @@ effect.</p>
|
||||
<li id="section-6">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-6">¶</a>
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-6">§</a>
|
||||
</div>
|
||||
<p>Look up the original position of a given <code>line</code> and <code>column</code> in the generated
|
||||
code.</p>
|
||||
@@ -234,8 +234,8 @@ code.</p>
|
||||
<li id="section-7">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-7">¶</a>
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-7">§</a>
|
||||
</div>
|
||||
<h2 id="v3-sourcemap-generation">V3 SourceMap Generation</h2>
|
||||
|
||||
@@ -247,8 +247,8 @@ code.</p>
|
||||
<li id="section-8">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-8">¶</a>
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-8">§</a>
|
||||
</div>
|
||||
<p>Builds up a V3 source map, returning the generated JSON as a string.
|
||||
<code>options.sourceRoot</code> may be used to specify the sourceRoot written to the source
|
||||
@@ -263,14 +263,14 @@ set “sources” and “file”, respectively.</p>
|
||||
lastSourceLine = <span class="hljs-number">0</span>
|
||||
lastSourceColumn = <span class="hljs-number">0</span>
|
||||
needComma = <span class="hljs-literal">no</span>
|
||||
buffer = <span class="hljs-string">""</span>
|
||||
buffer = <span class="hljs-string">""</span>
|
||||
|
||||
<span class="hljs-keyword">for</span> lineMap, lineNumber <span class="hljs-keyword">in</span> @lines <span class="hljs-keyword">when</span> lineMap
|
||||
<span class="hljs-keyword">for</span> mapping <span class="hljs-keyword">in</span> lineMap.columns <span class="hljs-keyword">when</span> mapping
|
||||
<span class="hljs-keyword">while</span> writingline < mapping.line
|
||||
lastColumn = <span class="hljs-number">0</span>
|
||||
needComma = <span class="hljs-literal">no</span>
|
||||
buffer += <span class="hljs-string">";"</span>
|
||||
buffer += <span class="hljs-string">";"</span>
|
||||
writingline++</pre></div></div>
|
||||
|
||||
</li>
|
||||
@@ -279,15 +279,15 @@ set “sources” and “file”, respectively.</p>
|
||||
<li id="section-9">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-9">¶</a>
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-9">§</a>
|
||||
</div>
|
||||
<p>Write a comma if we’ve already written a segment on this line.</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre> <span class="hljs-keyword">if</span> needComma
|
||||
buffer += <span class="hljs-string">","</span>
|
||||
buffer += <span class="hljs-string">","</span>
|
||||
needComma = <span class="hljs-literal">no</span></pre></div></div>
|
||||
|
||||
</li>
|
||||
@@ -296,8 +296,8 @@ set “sources” and “file”, respectively.</p>
|
||||
<li id="section-10">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-10">¶</a>
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-10">§</a>
|
||||
</div>
|
||||
<p>Write the next segment. Segments can be 1, 4, or 5 values. If just one, then it
|
||||
is a generated column which doesn’t match anything in the source code.</p>
|
||||
@@ -315,8 +315,8 @@ column for the current line:</p>
|
||||
<li id="section-11">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-11">¶</a>
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-11">§</a>
|
||||
</div>
|
||||
<p>The index into the list of sources:</p>
|
||||
|
||||
@@ -330,8 +330,8 @@ column for the current line:</p>
|
||||
<li id="section-12">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-12">¶</a>
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-12">§</a>
|
||||
</div>
|
||||
<p>The starting line in the original source, relative to the previous source line.</p>
|
||||
|
||||
@@ -346,8 +346,8 @@ column for the current line:</p>
|
||||
<li id="section-13">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-13">¶</a>
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-13">§</a>
|
||||
</div>
|
||||
<p>The starting column in the original source, relative to the previous column.</p>
|
||||
|
||||
@@ -363,8 +363,8 @@ column for the current line:</p>
|
||||
<li id="section-14">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-14">¶</a>
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-14">§</a>
|
||||
</div>
|
||||
<p>Produce the canonical JSON object format for a “v3” source map.</p>
|
||||
|
||||
@@ -375,17 +375,17 @@ column for the current line:</p>
|
||||
<span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> options.filename
|
||||
[options.filename]
|
||||
<span class="hljs-keyword">else</span>
|
||||
[<span class="hljs-string">'<anonymous>'</span>]
|
||||
[<span class="hljs-string">'<anonymous>'</span>]
|
||||
|
||||
v3 =
|
||||
version: <span class="hljs-number">3</span>
|
||||
file: options.generatedFile <span class="hljs-keyword">or</span> <span class="hljs-string">''</span>
|
||||
sourceRoot: options.sourceRoot <span class="hljs-keyword">or</span> <span class="hljs-string">''</span>
|
||||
file: options.generatedFile <span class="hljs-keyword">or</span> <span class="hljs-string">''</span>
|
||||
sourceRoot: options.sourceRoot <span class="hljs-keyword">or</span> <span class="hljs-string">''</span>
|
||||
sources: sources
|
||||
names: []
|
||||
mappings: buffer
|
||||
|
||||
v3.sourcesContent = [code] <span class="hljs-keyword">if</span> options.inlineMap
|
||||
v3.sourcesContent = [code] <span class="hljs-keyword">if</span> options.sourceMap <span class="hljs-keyword">or</span> options.inlineMap
|
||||
|
||||
v3</pre></div></div>
|
||||
|
||||
@@ -395,8 +395,8 @@ column for the current line:</p>
|
||||
<li id="section-15">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-15">¶</a>
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-15">§</a>
|
||||
</div>
|
||||
<h2 id="base64-vlq-encoding">Base64 VLQ Encoding</h2>
|
||||
|
||||
@@ -408,8 +408,8 @@ column for the current line:</p>
|
||||
<li id="section-16">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-16">¶</a>
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-16">§</a>
|
||||
</div>
|
||||
<p>Note that SourceMap VLQ encoding is “backwards”. MIDI-style VLQ encoding puts
|
||||
the most-significant-bit (MSB) from the original value into the MSB of the VLQ
|
||||
@@ -424,7 +424,7 @@ bits of the original value encoded into the first byte of the VLQ encoded value.
|
||||
VLQ_VALUE_MASK = VLQ_CONTINUATION_BIT - <span class="hljs-number">1</span> <span class="hljs-comment"># 0001 1111</span>
|
||||
|
||||
encodeVlq: <span class="hljs-function"><span class="hljs-params">(value)</span> -></span>
|
||||
answer = <span class="hljs-string">''</span></pre></div></div>
|
||||
answer = <span class="hljs-string">''</span></pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
@@ -432,8 +432,8 @@ bits of the original value encoded into the first byte of the VLQ encoded value.
|
||||
<li id="section-17">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-17">¶</a>
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-17">§</a>
|
||||
</div>
|
||||
<p>Least significant bit represents the sign.</p>
|
||||
|
||||
@@ -447,14 +447,14 @@ bits of the original value encoded into the first byte of the VLQ encoded value.
|
||||
<li id="section-18">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-18">¶</a>
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-18">§</a>
|
||||
</div>
|
||||
<p>The next bits are the actual value.</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre> valueToEncode = (Math.abs(value) << <span class="hljs-number">1</span>) + signBit</pre></div></div>
|
||||
<div class="content"><div class='highlight'><pre> valueToEncode = (<span class="hljs-built_in">Math</span>.abs(value) << <span class="hljs-number">1</span>) + signBit</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
@@ -462,8 +462,8 @@ bits of the original value encoded into the first byte of the VLQ encoded value.
|
||||
<li id="section-19">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-19">¶</a>
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-19">§</a>
|
||||
</div>
|
||||
<p>Make sure we encode at least one character, even if valueToEncode is 0.</p>
|
||||
|
||||
@@ -483,8 +483,8 @@ bits of the original value encoded into the first byte of the VLQ encoded value.
|
||||
<li id="section-20">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-20">¶</a>
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-20">§</a>
|
||||
</div>
|
||||
<h2 id="regular-base64-encoding">Regular Base64 Encoding</h2>
|
||||
|
||||
@@ -496,16 +496,16 @@ bits of the original value encoded into the first byte of the VLQ encoded value.
|
||||
<li id="section-21">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-21">¶</a>
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-21">§</a>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre> BASE64_CHARS = <span class="hljs-string">'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'</span>
|
||||
<div class="content"><div class='highlight'><pre> BASE64_CHARS = <span class="hljs-string">'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'</span>
|
||||
|
||||
encodeBase64: <span class="hljs-function"><span class="hljs-params">(value)</span> -></span>
|
||||
BASE64_CHARS[value] <span class="hljs-keyword">or</span> <span class="hljs-keyword">throw</span> <span class="hljs-keyword">new</span> Error <span class="hljs-string">"Cannot Base64 encode value: <span class="hljs-subst">#{value}</span>"</span></pre></div></div>
|
||||
BASE64_CHARS[value] <span class="hljs-keyword">or</span> <span class="hljs-keyword">throw</span> <span class="hljs-keyword">new</span> <span class="hljs-built_in">Error</span> <span class="hljs-string">"Cannot Base64 encode value: <span class="hljs-subst">#{value}</span>"</span></pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
@@ -513,14 +513,14 @@ bits of the original value encoded into the first byte of the VLQ encoded value.
|
||||
<li id="section-22">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-22">¶</a>
|
||||
<div class="sswrap ">
|
||||
<a class="ss" href="#section-22">§</a>
|
||||
</div>
|
||||
<p>Our API for source maps is just the <code>SourceMap</code> class.</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre><span class="hljs-built_in">module</span>.exports = SourceMap</pre></div></div>
|
||||
<div class="content"><div class='highlight'><pre>module.<span class="hljs-built_in">exports</span> = SourceMap</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
351
docs/v2/announcing-coffeescript-2/index.html
Normal file
351
docs/v2/announcing-coffeescript-2/index.html
Normal file
@@ -0,0 +1,351 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="content-type" content="text/html;charset=UTF-8" />
|
||||
<title>Announcing CoffeeScript 2</title>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<link rel="canonical" href="http://coffeescript.org" />
|
||||
|
||||
<link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png">
|
||||
<link rel="icon" type="image/png" href="/favicon-32x32.png" sizes="32x32">
|
||||
<link rel="icon" type="image/png" href="/favicon-16x16.png" sizes="16x16">
|
||||
<link rel="manifest" href="/manifest.json">
|
||||
<link rel="mask-icon" href="/safari-pinned-tab.svg" color="#5bbad5">
|
||||
<meta name="theme-color" content="#ffffff">
|
||||
|
||||
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-/Y6pD6FV/Vv2HJnA6t+vslU6fwYXjCFtcEpHbNJ0lyAFsXTsjBbfaDjzALeQsN6M" crossorigin="anonymous">
|
||||
<link href="https://fonts.googleapis.com/css?family=Alegreya+Sans:400,800|Galada:400|Lato:300,300i,400,700|Roboto+Mono:400,400i" rel="stylesheet" crossorigin="anonymous">
|
||||
<style>
|
||||
body {
|
||||
/* Push below header bar */
|
||||
margin-top: 3.5rem;
|
||||
background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1 3"><path opacity=".02" fill="#000" d="M0 0h1v1H0z"/><path opacity=".005" fill="#000" d="M0 1h1v2H0z"/></svg>');
|
||||
background-size: 1px 3px;
|
||||
}
|
||||
|
||||
svg {
|
||||
width: auto;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
a {
|
||||
color: #1b5e20;
|
||||
transition: 0.1s ease-in-out;
|
||||
}
|
||||
a:focus, a:hover, a:active {
|
||||
color: #388e3c;
|
||||
cursor: pointer;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
button:focus, .navbar-dark .navbar-toggler:focus {
|
||||
outline: none;
|
||||
border: thin solid rgba(248, 243, 240, 0.3);
|
||||
}
|
||||
|
||||
.bg-dark {
|
||||
background-color: #3e2723 !important;
|
||||
}
|
||||
|
||||
.bg-ribbed-light {
|
||||
background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1 3"><path opacity=".03" fill="#000" d="M0 0h1v1H0z"/><path opacity=".005" fill="#000" d="M0 1h1v2H0z"/></svg>');
|
||||
background-size: 1px 3px;
|
||||
}
|
||||
.bg-ribbed-dark {
|
||||
background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1 3"><path opacity=".2" fill="#000" d="M0 0h1v1H0z"/><path opacity=".15" fill="#000" d="M0 1h1v2H0z"/></svg>');
|
||||
background-size: 1px 3px;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Header
|
||||
*/
|
||||
.site-navbar {
|
||||
height: 3.5rem;
|
||||
font-family: 'Lato';
|
||||
font-weight: 400;
|
||||
font-size: 1.1em;
|
||||
}
|
||||
|
||||
.navbar-brand {
|
||||
height: 2.2em;
|
||||
margin-right: 1em;
|
||||
}
|
||||
|
||||
.navbar-dark path {
|
||||
fill: #fff;
|
||||
}
|
||||
|
||||
.navbar-nav .nav-item {
|
||||
margin-left: 0.6em;
|
||||
margin-right: 0.6em;
|
||||
border-radius: 0.4em;
|
||||
}
|
||||
.navbar-nav .nav-item:hover,
|
||||
.navbar-nav .nav-item:active,
|
||||
.navbar-nav .nav-item.show {
|
||||
background-color: #4e342e;
|
||||
}
|
||||
|
||||
.navbar-toggler {
|
||||
transition: all 0.1s ease-in-out;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Main content
|
||||
*/
|
||||
|
||||
.main {
|
||||
padding: 1.3em;
|
||||
}
|
||||
@media (min-width: 992px) {
|
||||
.main {
|
||||
padding-right: 2em;
|
||||
padding-left: 2em;
|
||||
}
|
||||
}
|
||||
|
||||
h1 {
|
||||
font: 2.5em Galada;
|
||||
color: #2f2625;
|
||||
text-align: center;
|
||||
}
|
||||
@media (min-width: 768px) {
|
||||
h1 {
|
||||
font-size: 3em;
|
||||
}
|
||||
}
|
||||
@media (min-width: 992px) {
|
||||
h1 {
|
||||
font-size: 4em;
|
||||
}
|
||||
}
|
||||
|
||||
.title-logo {
|
||||
display: inline-block;
|
||||
height: 1em;
|
||||
transform: translateY(0.2em);
|
||||
margin-left: 0.3em;
|
||||
margin-right: 0.25em;
|
||||
fill: #2f2625;
|
||||
}
|
||||
|
||||
.main p, .main li {
|
||||
font-family: Lato;
|
||||
font-weight: 300;
|
||||
font-size: 1.1em;
|
||||
line-height: 1.6;
|
||||
}
|
||||
.main blockquote {
|
||||
font-size: 1.1em;
|
||||
}
|
||||
@media (min-width: 768px) {
|
||||
.main p, .main li {
|
||||
font-size: 1.3em;
|
||||
}
|
||||
.main blockquote {
|
||||
font-size: 1.3em;
|
||||
}
|
||||
}
|
||||
.main strong {
|
||||
font-weight: 700;
|
||||
}
|
||||
.main a {
|
||||
border-bottom: 2px solid transparent;
|
||||
font-weight: 400;
|
||||
}
|
||||
.main a:focus, .main a:hover, .main a:active {
|
||||
border-bottom: 2px solid rgba(56, 142, 60, 0.2);
|
||||
}
|
||||
.main blockquote pre {
|
||||
background-color: #f8f3f0;
|
||||
color: #2f2625;
|
||||
border-radius: .3em;
|
||||
padding: 0.4em 0.6em;
|
||||
}
|
||||
|
||||
p, blockquote, li {
|
||||
margin-bottom: 1.3rem;
|
||||
}
|
||||
.credits li {
|
||||
margin-bottom: 0.3em;
|
||||
}
|
||||
|
||||
h2, h3, h4 {
|
||||
margin-top: 1.3em;
|
||||
margin-bottom: 0.6em;
|
||||
font-family: 'Alegreya Sans';
|
||||
}
|
||||
h2 {
|
||||
font-weight: 800;
|
||||
}
|
||||
h3, h4, h2 time {
|
||||
font-weight: 400;
|
||||
}
|
||||
|
||||
.main h2 {
|
||||
padding-top: 4rem;
|
||||
margin-top: -4rem;
|
||||
}
|
||||
|
||||
code {
|
||||
font-family: 'Roboto Mono';
|
||||
font-weight: 400;
|
||||
}
|
||||
code, a > code {
|
||||
background-color: #f8f3f0;
|
||||
padding: 0.2rem 0.4rem;
|
||||
}
|
||||
code {
|
||||
color: #2f2625;
|
||||
}
|
||||
|
||||
|
||||
.uneditable-code-block .comment {
|
||||
font-style: italic;
|
||||
color: #837B85;
|
||||
}
|
||||
.uneditable-code-block .class,
|
||||
.uneditable-code-block .function,
|
||||
.uneditable-code-block .keyword,
|
||||
.uneditable-code-block .reserved,
|
||||
.uneditable-code-block .title {
|
||||
color: #534328;
|
||||
}
|
||||
.uneditable-code-block .string
|
||||
.uneditable-code-block .value
|
||||
.uneditable-code-block .inheritance
|
||||
.uneditable-code-block .header {
|
||||
color: #3A4029;
|
||||
}
|
||||
.uneditable-code-block .variable,
|
||||
.uneditable-code-block .literal,
|
||||
.uneditable-code-block .tag,
|
||||
.uneditable-code-block .regexp,
|
||||
.uneditable-code-block .subst,
|
||||
.uneditable-code-block .property {
|
||||
color: #474429;
|
||||
}
|
||||
.uneditable-code-block .number,
|
||||
.uneditable-code-block .preprocessor,
|
||||
.uneditable-code-block .built_in,
|
||||
.uneditable-code-block .params,
|
||||
.uneditable-code-block .constant {
|
||||
color: #474429;
|
||||
}
|
||||
</style>
|
||||
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<nav class="navbar navbar-expand-lg fixed-top navbar-dark bg-dark bg-ribbed-dark site-navbar">
|
||||
<a class="navbar-brand" href="/" data-close="try"><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>
|
||||
</a>
|
||||
<button class="navbar-toggler" type="button" data-toggle="offcanvas" data-close="try" aria-label="Toggle sidebar">
|
||||
<span class="navbar-toggler-icon"></span>
|
||||
</button>
|
||||
|
||||
<nav class="collapse navbar-collapse">
|
||||
<div class="navbar-nav mr-auto d-none d-lg-flex">
|
||||
<a href="../#try" id="try-link" class="nav-item nav-link" data-toggle="try">Try CoffeeScript</a>
|
||||
<a href="../#language" class="nav-item nav-link" data-close="try">Language Reference</a>
|
||||
<a href="../#resources" class="nav-item nav-link" data-close="try">Resources</a>
|
||||
<a href="https://github.com/jashkenas/coffeescript" class="nav-item nav-link" data-close="try">GitHub
|
||||
</a>
|
||||
</div>
|
||||
</nav>
|
||||
</nav>
|
||||
|
||||
|
||||
<div class="container" id="top">
|
||||
<div class="row">
|
||||
<main class="main">
|
||||
<header>
|
||||
<h1>Announcing <span class="text-nowrap"><svg class="title-logo" xmlns="http://www.w3.org/2000/svg" viewBox="-76 212 458 369">
|
||||
<title>
|
||||
CoffeeScript Icon
|
||||
</title>
|
||||
<path d="M106 228.6c.5 2.3-.9 4.4-5 6.5-5.5-3.1-16.9-4.4-26.7-3.5-10.4.9-19.4 4.2-17.9 11.3 1.5 7.1 11.7 11 29.5 9.5 43.6-3.8 43.4-33.3 107.4-39 49.8-4.4 77.8 11 81.8 29.7 3.1 14.7-9.1 28.6-45.2 31.8-32 2.8-50.7-5.6-52.6-14.6-1-4.5 1.8-11.3 17.2-13.1 1.5 7 10.6 14.4 31.1 12.6 14.8-1.3 27.6-6.6 25.9-14.9-1.8-8.6-17.7-13.7-42.6-11.5-50.7 4.5-63.2 32.5-106.8 36.3-30.8 2.7-55.9-8.5-59.4-25.1-1.3-6.1-1.4-21 31.2-23.9 17.1-1.5 30.7 1.5 32.1 7.9zM-56.4 402.5c-14.3 18-20.4 38.8-19.2 59.2 1.2 20.4 11.4 37.1 26.9 50.2C-32 525-14 528.6 6.4 525c7.8-1.2 16.7-5.3 24.5-7.8-16.7 0-31-5.3-44.9-16.7-15.5-11.4-25.7-26.9-28.2-46.1-3.7-18 0-34.7 10.2-49 11.4-14.3 25.7-22 44.9-24.5 19.2-1.2 35.9 3.7 52.6 15.5-3.7-5.3-9-9-14.3-14.3-16.7-11.4-34.7-16.7-56.7-11.4-19.9 3.6-36.7 13.8-50.9 31.8zm223.6-96.3c-53.9 0-101.6-5.3-136.3-13.1-37.1-9-56.7-19.2-56.7-32.2 0-5.3 2.4-10.2 10.2-15.5-23.3 9-35.9 16.7-35.9 28.2 1.2 13.1 22 25.7 64.5 35.9 40 10.2 91.4 15.5 153 15.5 62.8 0 113-5.3 153-15.5 42.4-10.2 62.8-23.3 62.8-35.9 0-9-9-18-25.7-24.5 3.7 2.4 6.5 6.5 6.5 11.4 0 13.1-19.2 23.3-57.9 32.2-36 8.2-82.1 13.5-137.5 13.5zm153 35.9c-40 9-91.4 15.5-153 15.5-62.8 0-114.2-6.5-154.2-15.5-35.9-9-55.1-19.2-61.6-29.4 6.5 44.9 22 87.3 42.4 124.8 15.5 23.3 31 43.7 46.1 65.7 6.5 13.1 11.4 25.7 14.3 38.8 10.2 14.3 24.5 23.3 42.4 28.2 22 7.8 44.9 11.4 68.1 10.2h2.4c23.3 1.2 47.7-2.4 70.6-10.2 16.7-5.3 31-14.3 41.2-28.2h1.2c2.4-13.1 6.5-25.7 13.1-38.8 15.5-22 31-42.4 46.1-65.7 20.4-37.1 34.7-79.6 42.4-124.8-7.7 11.4-26.9 21.6-61.5 29.4z"/>
|
||||
</svg> CoffeeScript 2</span></h1>
|
||||
</header>
|
||||
<section>
|
||||
<p>We are pleased to announce CoffeeScript 2! This new release of the CoffeeScript language and compiler aims to bring CoffeeScript into the modern JavaScript era, closing gaps in compatibility with JavaScript while preserving the clean syntax that is CoffeeScript’s hallmark. In a nutshell:</p>
|
||||
<ul>
|
||||
<li>The CoffeeScript 2 compiler now translates CoffeeScript code into modern JavaScript syntax. So a CoffeeScript <code>=></code> is now output as <code>=></code>, a CoffeeScript <code>class</code> is now output using the <code>class</code> keyword, and so on. This means you may need to <a href="../#transpilation">transpile the CoffeeScript compiler’s output</a>.</li>
|
||||
<li>CoffeeScript 2 adds support for <a href="../#async-functions">async functions</a> syntax, for the future <a href="../#destructuring">object destructuring</a> syntax, and for <a href="../#jsx">JSX</a>. Some features, such as <a href="../#modules">modules</a> (<code>import</code> and <code>export</code> statements), <a href="../#generator-iteration"><code>for…of</code></a>, and <a href="../#tagged-template-literals">tagged template literals</a> were backported into CoffeeScript versions 1.11 and 1.12.</li>
|
||||
<li>All of the above was achieved with very few <a href="../#breaking-changes">breaking changes from 1.x</a>. Most current CoffeeScript projects should be able to upgrade with little or no refactoring necessary.</li>
|
||||
</ul>
|
||||
<p>CoffeeScript 2 was developed with two primary goals: remove any incompatibilities with modern JavaScript that might prevent CoffeeScript from being used on a project; and preserve as much backward compatibility as possible. <a href="../#installation">Install now</a>: <code>npm install -g coffeescript@2</code></p>
|
||||
<h2 id="modern-javascript-output">Modern JavaScript Output</h2>
|
||||
<p>From the beginning, CoffeeScript has been described as being “just JavaScript.” And today, JavaScript is ES2015 (well, ES2017; also commonly known as ES6). CoffeeScript welcomes the changes in the JavaScript world and we’re happy to stop outputting circa-1999 syntax for modern features.</p>
|
||||
<p>Many new JavaScript features, such as <code>=></code>, were informed by CoffeeScript and are one-to-one compatible, or very nearly so. This has made outputting many of CoffeeScript’s innovations into new JS syntax straightforward: not only does <code>=></code> become <code>=></code>, but <code>{ a } = obj</code> becomes <code>{ a } = obj</code>, <code>"a#{b}c"</code> becomes <code>`a${b}c`</code> and so on.</p>
|
||||
<p>The following CoffeeScript features were updated in 2.0 to output using modern JavaScript syntax (or added in CoffeeScript 1.11 through 2.0, output using modern syntax):</p>
|
||||
<ul>
|
||||
<li>Modules: <code>import</code>/<code>export</code></li>
|
||||
<li>Classes: <code>class Animal</code></li>
|
||||
<li>Async functions: <code>await someFunction()</code></li>
|
||||
<li>Bound/arrow functions: <code>=></code></li>
|
||||
<li>Function default parameters: <code>(options = {}) -></code></li>
|
||||
<li>Function splat/rest parameters: <code>(items...) -></code></li>
|
||||
<li>Destructuring, for both arrays and objects: <code>[first, second] = items</code>, <code>{length} = items</code></li>
|
||||
<li>Object rest/spread properties: <code>{options..., force: yes}</code>, <code>{force, otherOptions...} = options</code></li>
|
||||
<li>Interpolated strings/template literals (JS backticked strings): <code>"Hello, #{user}!"</code></li>
|
||||
<li>Tagged template literals: <code>html"<strong>coffee</strong>"</code></li>
|
||||
<li>JavaScript’s <code>for…of</code> is now available as CoffeeScript’s <code>for…from</code> (we already had a <code>for…of</code>): <code>for n from generatorFunction()</code></li>
|
||||
</ul>
|
||||
<p>Not all CoffeeScript features were adopted into JavaScript in 100% the same way; most notably, <a href="../#breaking-changes-default-values">default values</a> in JavaScript (and also in CoffeeScript 2) are only applied when a variable is <code>undefined</code>, not <code>undefined</code> or <code>null</code> as in CoffeeScript 1; and <a href="../#breaking-changes-classes">classes</a> have their own differences. See the <a href="../#breaking-changes">breaking changes</a> for the fine details.</p>
|
||||
<p>In our experience, most breaking changes are edge cases that should affect very few people, like JavaScript’s <a href="../#breaking-change-fat-arrow">lack of an <code>arguments</code> object inside arrow functions</a>. There seem to be two breaking changes that affect a significant number of projects:</p>
|
||||
<ul>
|
||||
<li>In CoffeeScript 2, “bare” <code>super</code> (calling <code>super</code> without arguments) is now no longer allowed, and one must use <code>super()</code> or <code>super arguments...</code> instead.</li>
|
||||
<li>References to <code>this</code>/<code>@</code> cannot occur before a call to <code>super</code>, per the JS spec.</li>
|
||||
</ul>
|
||||
<p>See the <a href="../#breaking-changes-super-extends">full details</a>. Either the CoffeeScript compiler or your transpiler will throw errors for either of these cases, so updating your code is a matter of fixing each occurrence as the compiler errors on it, until your code compiles successfully.</p>
|
||||
<h2 id="other-features">Other Features</h2>
|
||||
<p>Besides supporting new JavaScript features and outputting older CoffeeScript features in modern JS syntax, CoffeeScript 2 has added support for the following:</p>
|
||||
<ul>
|
||||
<li><a href="../#jsx">JSX</a></li>
|
||||
<li><a href="../#comments">Line comments</a> are now output (in CoffeeScript 1 they were discarded)</li>
|
||||
<li>Block comments are now allowed anywhere, enabling <a href="../#type-annotations">static type annotations</a> using Flow’s comment-based syntax</li>
|
||||
</ul>
|
||||
<p>There are many smaller improvements as well, such as to the <code>coffee</code> command-line tool. You can read all the details in the <a href="../#changelog">changelog</a> for the 2.0.0 betas.</p>
|
||||
<h2 id="what-about-…">“What About …?”</h2>
|
||||
<p>A few JavaScript features have been intentionally omitted from CoffeeScript. These include <code>let</code> and <code>const</code> (and <code>var</code>), named functions and the <code>get</code> and <code>set</code> keywords. These get asked about so often that we added a section to the docs called <a href="../#unsupported">Unsupported ECMAScript Features</a>. CoffeeScript’s lack of equivalents for these features does not affect compatibility or interoperability with JavaScript modules or libraries.</p>
|
||||
<h2 id="future-compatibility">Future Compatibility</h2>
|
||||
<p>Back when CoffeeScript 1 was created, ES2015 JavaScript and 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> were several years away. The CoffeeScript compiler itself had to do what today’s transpilers do, converting modern features like destructuring and arrow functions into equivalent lowest-common-denominator JavaScript.</p>
|
||||
<p>But transpilers exist now, and they do their job well. With them around, there’s no need for the CoffeeScript compiler to duplicate this functionality. All the CoffeeScript compiler needs to worry about now is converting the CoffeeScript version of new syntax into the JS version of that syntax, e.g. <code>"Hello, #{name}!"</code> into <code>`Hello, ${name}!`</code>. This makes adding support for new JavaScript features much easier than before.</p>
|
||||
<p>Most features added by ECMA in recent years haven’t required any updates at all in CoffeeScript. New global objects, or new methods on global objects, don’t require any updates on CoffeeScript’s part to work. Some proposed future JS features <em>do</em> involve new syntax, like <a href="https://github.com/tc39/proposal-class-fields">class fields</a>. We have adopted a policy of supporting new syntax only when it reaches Stage 4 in ECMA’s process, which means that the syntax is final and will be in the next ES release. On occasion we might support a <em>feature</em> before it has reached Stage 4, but output it using equivalent non-experimental syntax instead of the newly-proposed syntax; that’s what’s happening in 2.0.0 for <a href="../#splats">object destructuring</a>, where our output uses the same polyfill that Babel uses. When the new syntax is finalized, we will update our output to use the final syntax.</p>
|
||||
<h2 id="credits">Credits</h2>
|
||||
<p>The major features of 2.0.0 would not have been possible without the following people:</p>
|
||||
<ul class="credits">
|
||||
<li><a href="https://github.com/GeoffreyBooth">@GeoffreyBooth</a>: Organizer of the CoffeeScript 2 effort, developer for modules; arrow functions, function default parameters and function rest parameters output using ES2015 syntax; line comments output and block comments output anywhere; block embedded JavaScript via triple backticks; improved parsing of Literate CoffeeScript; and the new docs website.</li>
|
||||
<li><a href="https://github.com/connec">@connec</a>: Classes; destructuring; splats/rest syntax in arrays and function calls; and computed properties all output using ES2015 syntax.</li>
|
||||
<li><a href="https://github.com/GabrielRatener">@GabrielRatener</a>: Async functions.</li>
|
||||
<li><a href="https://github.com/xixixao">@xixixao</a>: JSX.</li>
|
||||
<li><a href="https://github.com/zdenko">@zdenko</a>: Object rest/spread properties (object destructuring).</li>
|
||||
<li><a href="https://github.com/greghuc">@greghuc</a>: Tagged template literals, interpolated strings output in ES2015 syntax.</li>
|
||||
<li><a href="https://github.com/atg">@atg</a>: ES2015 <code>for…of</code>, supported as CoffeeScript’s <code>for…from</code>.</li>
|
||||
<li><a href="https://github.com/lydell">@lydell</a> and <a href="https://github.com/jashkenas">@jashkenas</a>: Guidance, code reviews and feedback.</li>
|
||||
</ul>
|
||||
<p>See the full <a href="https://github.com/jashkenas/coffeescript/wiki/CoffeeScript-2-Honor-Roll">honor roll</a>.</p>
|
||||
<p>Thanks and we hope you enjoy CoffeeScript 2!</p>
|
||||
|
||||
</section>
|
||||
</main>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-106156830-1"></script>
|
||||
<script>
|
||||
window.dataLayer = window.dataLayer || [];
|
||||
function gtag(){dataLayer.push(arguments)};
|
||||
gtag('js', new Date());
|
||||
gtag('config', 'UA-106156830-1');
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
8
docs/v2/browser-compiler-legacy/coffeescript.js
Normal file
8
docs/v2/browser-compiler-legacy/coffeescript.js
Normal file
File diff suppressed because one or more lines are too long
8
docs/v2/browser-compiler-modern/coffeescript.js
Normal file
8
docs/v2/browser-compiler-modern/coffeescript.js
Normal file
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
3917
docs/v2/index.html
3917
docs/v2/index.html
File diff suppressed because one or more lines are too long
20144
docs/v2/test.html
20144
docs/v2/test.html
File diff suppressed because it is too large
Load Diff
4
documentation/examples/breaking_change_super_this.coffee
Normal file
4
documentation/examples/breaking_change_super_this.coffee
Normal file
@@ -0,0 +1,4 @@
|
||||
class B extends A
|
||||
constructor: (arg) ->
|
||||
super arg
|
||||
@arg = arg
|
||||
@@ -4,4 +4,4 @@ Released under the MIT License
|
||||
###
|
||||
|
||||
sayFortune = (fortune) ->
|
||||
console.log fortune # in bed!
|
||||
console.log fortune # in bed!
|
||||
|
||||
10
documentation/examples/dynamic_import.coffee
Normal file
10
documentation/examples/dynamic_import.coffee
Normal file
@@ -0,0 +1,10 @@
|
||||
# Your browser must support dynamic import to run this example.
|
||||
|
||||
do ->
|
||||
{ run } = await import('./browser-compiler-modern/coffeescript.js')
|
||||
run '''
|
||||
if 5 < new Date().getHours() < 9
|
||||
alert 'Time to make the coffee!'
|
||||
else
|
||||
alert 'Time to get some work done.'
|
||||
'''
|
||||
@@ -6,4 +6,4 @@ Object.defineProperty screen, 'height',
|
||||
get: ->
|
||||
this.width / this.ratio
|
||||
set: (val) ->
|
||||
this.width = val / this.ratio
|
||||
this.width = val * this.ratio
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import 'local-file.coffee'
|
||||
import 'coffeescript'
|
||||
import './local-file.js' # Must be the filename of the generated file
|
||||
import 'package'
|
||||
|
||||
import _ from 'underscore'
|
||||
import * as underscore from 'underscore'
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
class Teenager
|
||||
@say: (speech) ->
|
||||
words = speech.split ' '
|
||||
fillers = ['uh', 'um', 'like', 'actually', 'so', 'maybe']
|
||||
output = []
|
||||
for word, index in words
|
||||
output.push word
|
||||
output.push fillers[Math.floor(Math.random() * fillers.length)] unless index is words.length - 1
|
||||
output.join ', '
|
||||
@say: (speech) ->
|
||||
words = speech.split ' '
|
||||
fillers = ['uh', 'um', 'like', 'actually', 'so', 'maybe']
|
||||
output = []
|
||||
for word, index in words
|
||||
output.push word
|
||||
output.push fillers[Math.floor(Math.random() * fillers.length)] unless index is words.length - 1
|
||||
output.join ', '
|
||||
|
||||
@@ -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,6 +0,0 @@
|
||||
<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>
|
||||
|
Before Width: | Height: | Size: 4.7 KiB |
@@ -1,16 +1,16 @@
|
||||
## Annotated Source
|
||||
|
||||
You can browse the CoffeeScript <%= fullVersion %> source in readable, annotated form [here](http://coffeescript.org/v<%= majorVersion %>/annotated-source/). You can also jump directly to a particular source file:
|
||||
You can browse the CoffeeScript <%= fullVersion %> source in readable, annotated form [here](annotated-source/). You can also jump directly to a particular source file:
|
||||
|
||||
- [Grammar Rules — src/grammar](http://coffeescript.org/v<%= majorVersion %>/annotated-source/grammar.html)
|
||||
- [Lexing Tokens — src/lexer](http://coffeescript.org/v<%= majorVersion %>/annotated-source/lexer.html)
|
||||
- [The Rewriter — src/rewriter](http://coffeescript.org/v<%= majorVersion %>/annotated-source/rewriter.html)
|
||||
- [The Syntax Tree — src/nodes](http://coffeescript.org/v<%= majorVersion %>/annotated-source/nodes.html)
|
||||
- [Lexical Scope — src/scope](http://coffeescript.org/v<%= majorVersion %>/annotated-source/scope.html)
|
||||
- [Helpers & Utility Functions — src/helpers](http://coffeescript.org/v<%= majorVersion %>/annotated-source/helpers.html)
|
||||
- [The CoffeeScript Module — src/coffeescript](http://coffeescript.org/v<%= majorVersion %>/annotated-source/coffeescript.html)
|
||||
- [Cake & Cakefiles — src/cake](http://coffeescript.org/v<%= majorVersion %>/annotated-source/cake.html)
|
||||
- [“coffee” Command-Line Utility — src/command](http://coffeescript.org/v<%= majorVersion %>/annotated-source/command.html)
|
||||
- [Option Parsing — src/optparse](http://coffeescript.org/v<%= majorVersion %>/annotated-source/optparse.html)
|
||||
- [Interactive REPL — src/repl](http://coffeescript.org/v<%= majorVersion %>/annotated-source/repl.html)
|
||||
- [Source Maps — src/sourcemap](http://coffeescript.org/v<%= majorVersion %>/annotated-source/sourcemap.html)
|
||||
- [Grammar Rules — src/grammar](annotated-source/grammar.html)
|
||||
- [Lexing Tokens — src/lexer](annotated-source/lexer.html)
|
||||
- [The Rewriter — src/rewriter](annotated-source/rewriter.html)
|
||||
- [The Syntax Tree — src/nodes](annotated-source/nodes.html)
|
||||
- [Lexical Scope — src/scope](annotated-source/scope.html)
|
||||
- [Helpers & Utility Functions — src/helpers](annotated-source/helpers.html)
|
||||
- [The CoffeeScript Module — src/coffeescript](annotated-source/coffeescript.html)
|
||||
- [Cake & Cakefiles — src/cake](annotated-source/cake.html)
|
||||
- [“coffee” Command-Line Utility — src/command](annotated-source/command.html)
|
||||
- [Option Parsing — src/optparse](annotated-source/optparse.html)
|
||||
- [Interactive REPL — src/repl](annotated-source/repl.html)
|
||||
- [Source Maps — src/sourcemap](annotated-source/sourcemap.html)
|
||||
|
||||
78
documentation/sections/announcing_coffeescript_2.md
Normal file
78
documentation/sections/announcing_coffeescript_2.md
Normal file
@@ -0,0 +1,78 @@
|
||||
# Announcing CoffeeScript 2
|
||||
|
||||
We are pleased to announce CoffeeScript 2! This new release of the CoffeeScript language and compiler aims to bring CoffeeScript into the modern JavaScript era, closing gaps in compatibility with JavaScript while preserving the clean syntax that is CoffeeScript’s hallmark. In a nutshell:
|
||||
|
||||
- The CoffeeScript 2 compiler now translates CoffeeScript code into modern JavaScript syntax. So a CoffeeScript `=>` is now output as `=>`, a CoffeeScript `class` is now output using the `class` keyword, and so on. This means you may need to [transpile the CoffeeScript compiler’s output](../#es2015plus-output).
|
||||
- CoffeeScript 2 adds support for [async functions](../#async-functions) syntax, for the future [object destructuring](../#destructuring) syntax, and for [JSX](../#jsx). Some features, such as [modules](../#modules) (`import` and `export` statements), [`for…of`](../#generator-iteration), and [tagged template literals](../#tagged-template-literals) were backported into CoffeeScript versions 1.11 and 1.12.
|
||||
- All of the above was achieved with very few [breaking changes from 1.x](../#breaking-changes). Most current CoffeeScript projects should be able to upgrade with little or no refactoring necessary.
|
||||
|
||||
CoffeeScript 2 was developed with two primary goals: remove any incompatibilities with modern JavaScript that might prevent CoffeeScript from being used on a project; and preserve as much backward compatibility as possible. [Install now](../#installation): `npm install -g coffeescript@2`
|
||||
|
||||
## Modern JavaScript Output
|
||||
|
||||
From the beginning, CoffeeScript has been described as being “just JavaScript.” And today, JavaScript is ES2015 (well, ES2017; also commonly known as ES6). CoffeeScript welcomes the changes in the JavaScript world and we’re happy to stop outputting circa-1999 syntax for modern features.
|
||||
|
||||
Many new JavaScript features, such as `=>`, were informed by CoffeeScript and are one-to-one compatible, or very nearly so. This has made outputting many of CoffeeScript’s innovations into new JS syntax straightforward: not only does `=>` become `=>`, but `{ a } = obj` becomes `{ a } = obj`, `"a#{b}c"` becomes `` `a${b}c` `` and so on.
|
||||
|
||||
The following CoffeeScript features were updated in 2.0 to output using modern JavaScript syntax (or added in CoffeeScript 1.11 through 2.0, output using modern syntax):
|
||||
|
||||
- Modules: `import`/`export`
|
||||
- Classes: `class Animal`
|
||||
- Async functions: `await someFunction()`
|
||||
- Bound/arrow functions: `=>`
|
||||
- Function default parameters: `(options = {}) ->`
|
||||
- Function splat/rest parameters: `(items...) ->`
|
||||
- Destructuring, for both arrays and objects: `[first, second] = items`, `{length} = items`
|
||||
- Object rest/spread properties: `{options..., force: yes}`, `{force, otherOptions...} = options`
|
||||
- Interpolated strings/template literals (JS backticked strings): `"Hello, #{user}!"`
|
||||
- Tagged template literals: `html"<strong>coffee</strong>"`
|
||||
- JavaScript’s `for…of` is now available as CoffeeScript’s `for…from` (we already had a `for…of`): `for n from generatorFunction()`
|
||||
|
||||
Not all CoffeeScript features were adopted into JavaScript in 100% the same way; most notably, [default values](../#breaking-changes-default-values) in JavaScript (and also in CoffeeScript 2) are only applied when a variable is `undefined`, not `undefined` or `null` as in CoffeeScript 1; and [classes](../#breaking-changes-classes) have their own differences. See the [breaking changes](../#breaking-changes) for the fine details.
|
||||
|
||||
In our experience, most breaking changes are edge cases that should affect very few people, like JavaScript’s [lack of an `arguments` object inside arrow functions](../#breaking-change-fat-arrow). There seem to be two breaking changes that affect a significant number of projects:
|
||||
|
||||
- In CoffeeScript 2, “bare” `super` (calling `super` without arguments) is now no longer allowed, and one must use `super()` or `super arguments...` instead.
|
||||
- References to `this`/`@` cannot occur before a call to `super`, per the JS spec.
|
||||
|
||||
See the [full details](../#breaking-changes-super-extends). Either the CoffeeScript compiler or your transpiler will throw errors for either of these cases, so updating your code is a matter of fixing each occurrence as the compiler errors on it, until your code compiles successfully.
|
||||
|
||||
## Other Features
|
||||
|
||||
Besides supporting new JavaScript features and outputting older CoffeeScript features in modern JS syntax, CoffeeScript 2 has added support for the following:
|
||||
|
||||
- [JSX](../#jsx)
|
||||
- [Line comments](../#comments) are now output (in CoffeeScript 1 they were discarded)
|
||||
- Block comments are now allowed anywhere, enabling [static type annotations](../#type-annotations) using Flow’s comment-based syntax
|
||||
|
||||
There are many smaller improvements as well, such as to the `coffee` command-line tool. You can read all the details in the [changelog](../#changelog) for the 2.0.0 betas.
|
||||
|
||||
## “What About …?”
|
||||
|
||||
A few JavaScript features have been intentionally omitted from CoffeeScript. These include `let` and `const` (and `var`), named functions and the `get` and `set` keywords. These get asked about so often that we added a section to the docs called [Unsupported ECMAScript Features](../#unsupported). CoffeeScript’s lack of equivalents for these features does not affect compatibility or interoperability with JavaScript modules or libraries.
|
||||
|
||||
## Future Compatibility
|
||||
|
||||
Back when CoffeeScript 1 was created, ES2015 JavaScript and transpilers like [Babel](http://babeljs.io/), [Bublé](https://buble.surge.sh/) or [Traceur Compiler](https://github.com/google/traceur-compiler) were several years away. The CoffeeScript compiler itself had to do what today’s transpilers do, converting modern features like destructuring and arrow functions into equivalent lowest-common-denominator JavaScript.
|
||||
|
||||
But transpilers exist now, and they do their job well. With them around, there’s no need for the CoffeeScript compiler to duplicate this functionality. All the CoffeeScript compiler needs to worry about now is converting the CoffeeScript version of new syntax into the JS version of that syntax, e.g. `"Hello, #{name}!"` into `` `Hello, ${name}!` ``. This makes adding support for new JavaScript features much easier than before.
|
||||
|
||||
Most features added by ECMA in recent years haven’t required any updates at all in CoffeeScript. New global objects, or new methods on global objects, don’t require any updates on CoffeeScript’s part to work. Some proposed future JS features _do_ involve new syntax, like [class fields](https://github.com/tc39/proposal-class-fields). We have adopted a policy of supporting new syntax only when it reaches Stage 4 in ECMA’s process, which means that the syntax is final and will be in the next ES release. On occasion we might support a _feature_ before it has reached Stage 4, but output it using equivalent non-experimental syntax instead of the newly-proposed syntax; that’s what’s happening in 2.0.0 for [object destructuring](../#splats), where our output uses the same polyfill that Babel uses. When the new syntax is finalized, we will update our output to use the final syntax.
|
||||
|
||||
## Credits
|
||||
|
||||
The major features of 2.0.0 would not have been possible without the following people:
|
||||
|
||||
- [@GeoffreyBooth](https://github.com/GeoffreyBooth): Organizer of the CoffeeScript 2 effort, developer for modules; arrow functions, function default parameters and function rest parameters output using ES2015 syntax; line comments output and block comments output anywhere; block embedded JavaScript via triple backticks; improved parsing of Literate CoffeeScript; and the new docs website.
|
||||
- [@connec](https://github.com/connec): Classes; destructuring; splats/rest syntax in arrays and function calls; and computed properties all output using ES2015 syntax.
|
||||
- [@GabrielRatener](https://github.com/GabrielRatener): Async functions.
|
||||
- [@xixixao](https://github.com/xixixao): JSX.
|
||||
- [@zdenko](https://github.com/zdenko): Object rest/spread properties (object destructuring).
|
||||
- [@greghuc](https://github.com/greghuc): Tagged template literals, interpolated strings output in ES2015 syntax.
|
||||
- [@atg](https://github.com/atg): ES2015 `for…of`, supported as CoffeeScript’s `for…from`.
|
||||
- [@lydell](https://github.com/lydell) and [@jashkenas](https://github.com/jashkenas): Guidance, code reviews and feedback.
|
||||
|
||||
|
||||
See the full [honor roll](https://github.com/jashkenas/coffeescript/wiki/CoffeeScript-2-Honor-Roll).
|
||||
|
||||
Thanks and we hope you enjoy CoffeeScript 2!
|
||||
@@ -9,13 +9,6 @@ Class constructors can’t be invoked without `new`:
|
||||
# Throws a TypeError at runtime
|
||||
```
|
||||
|
||||
Derived (extended) class `constructor`s cannot use `this` before calling `super`:
|
||||
|
||||
```coffee
|
||||
class B extends A
|
||||
constructor: -> this # Throws a compiler error
|
||||
```
|
||||
|
||||
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:
|
||||
|
||||
```coffee
|
||||
|
||||
20
documentation/sections/breaking_changes_super_this.md
Normal file
20
documentation/sections/breaking_changes_super_this.md
Normal file
@@ -0,0 +1,20 @@
|
||||
### `super` and `this`
|
||||
|
||||
In the constructor of a derived class (a class that `extends` another class), `this` cannot be used before calling `super`:
|
||||
|
||||
```coffee
|
||||
class B extends A
|
||||
constructor: -> this # Throws a compiler error
|
||||
```
|
||||
This also means you cannot pass a reference to `this` as an argument to `super` in the constructor of a derived class:
|
||||
|
||||
```coffee
|
||||
class B extends A
|
||||
constructor: (@arg) ->
|
||||
super @arg # Throws a compiler error
|
||||
```
|
||||
This is a limitation of ES2015 classes. As a workaround, assign to `this` after the `super` call:
|
||||
|
||||
```
|
||||
codeFor('breaking_change_super_this')
|
||||
```
|
||||
@@ -1,642 +1 @@
|
||||
## Changelog
|
||||
|
||||
```
|
||||
releaseHeader('2017-09-02', '2.0.0-beta5', '2.0.0-beta4')
|
||||
```
|
||||
|
||||
* Node 6 is now supported, and we will try to maintain that as the minimum required version for CoffeeScript 2 via the `coffee` command or Node API. Older versions of Node, or non-evergreen browsers, can compile via the [browser compiler](./browser-compiler/coffeescript.js).
|
||||
* The command line `--output` flag now allows you to specify an output filename, not just an output folder.
|
||||
* The command line `--require` flag now properly handles filenames or module names that are invalid identifiers (like an NPM module with a hyphen in the name).
|
||||
* `Object.assign`, output when object destructuring is used, is polyfilled using the same polyfill that Babel outputs. This means that polyfills shouldn’t be required unless support for Internet Explorer 8 or below is desired (or your own code uses a feature that requires a polyfill). See [ES2015+ Output](#es2015plus-output).
|
||||
* A string or JSX interpolation that contains only a comment (`"a#{### comment ###}b"` or `<div>{### comment ###}</div>`) is now output (`` `a${/* comment */}b` ``)
|
||||
* Interpolated strings (ES2015 template literals) that contain quotation marks no longer have the quotation marks escaped: `` `say "${message}"` ``
|
||||
* It is now possible to chain after a function literal (for example, to define a function and then call `.call` on it).
|
||||
* The results of the async tests are included in the output when you run `cake test`.
|
||||
* Bugfixes for object destructuring; expansions in function parameters; generated reference variables in function parameters; chained functions after `do`; splats after existential operator soaks in arrays (`[a?.b...]`); trailing `if` with splat in arrays or function parameters (`[a if b...]`); attempting to `throw` an `if`, `for`, `switch`, `while` or other invalid construct.
|
||||
* Bugfixes for syntactical edge cases: semicolons after `=` and other “mid-expression” tokens; spaces after `::`; and scripts that begin with `:` or `*`.
|
||||
* Bugfixes for source maps generated via the Node API; and stack trace line numbers when compiling CoffeeScript via the Node API from within a `.coffee` file.
|
||||
|
||||
```
|
||||
releaseHeader('2017-08-03', '2.0.0-beta4', '2.0.0-beta3')
|
||||
```
|
||||
|
||||
* This release includes [all the changes from 1.12.6 to 1.12.7](#1.12.7).
|
||||
* [Line comments](#comments) (starting with `#`) are now output in the generated JavaScript.
|
||||
* [Block comments](#comments) (delimited by `###`) are now allowed anywhere, including inline where they previously weren’t possible. This provides support for [static type annotations](#type-annotations) using Flow’s comments-based syntax.
|
||||
* Spread syntax (`...` for objects) is now supported in JSX tags: `<div {props...} />`.
|
||||
* Argument parsing for scripts run via `coffee` is improved. See [breaking changes](#breaking-changes-argument-parsing-and-shebang-lines).
|
||||
* CLI: Propagate `SIGINT` and `SIGTERM` signals when node is forked.
|
||||
* `await` in the REPL is now allowed without requiring a wrapper function.
|
||||
* `do super` is now allowed, and other accesses of `super` like `super.x.y` or `super['x'].y` now work.
|
||||
* Splat/spread syntax triple dots are now allowed on either the left or the right (so `props...` or `...props` are both valid).
|
||||
* Tagged template literals are recognized as callable functions.
|
||||
* Bugfixes for object spread syntax in nested properties.
|
||||
* Bugfixes for destructured function parameter default values.
|
||||
|
||||
```
|
||||
releaseHeader('2017-07-16', '1.12.7', '1.12.6')
|
||||
```
|
||||
|
||||
* Fix regressions in 1.12.6 related to chained function calls and indented `return` and `throw` arguments.
|
||||
* The REPL no longer warns about assigning to `_`.
|
||||
|
||||
```
|
||||
releaseHeader('2017-06-30', '2.0.0-beta3', '2.0.0-beta2')
|
||||
```
|
||||
|
||||
* [JSX](#jsx) is now supported.
|
||||
* [Object rest/spread properties](#object-spread) are now supported.
|
||||
* Bound (fat arrow) methods are once again supported in classes; though an error will be thrown if you attempt to call the method before it is bound. See [breaking changes for classes](#breaking-changes-classes).
|
||||
* The REPL no longer warns about assigning to `_`.
|
||||
* Bugfixes for destructured nested default values and issues related to chaining or continuing expressions across multiple lines.
|
||||
|
||||
|
||||
```
|
||||
releaseHeader('2017-05-16', '2.0.0-beta2', '2.0.0-beta1')
|
||||
```
|
||||
|
||||
* This release includes [all the changes from 1.12.5 to 1.12.6](#1.12.6).
|
||||
* Bound (fat arrow) methods in classes must be declared in the class constructor, after `super()` if the class is extending a parent class. See [breaking changes for classes](#breaking-changes-classes).
|
||||
* All unnecessary utility helper functions have been removed, including the polyfills for `indexOf` and `bind`.
|
||||
* The `extends` keyword now only works in the context of classes; it cannot be used to extend a function prototype. See [breaking changes for `extends`](#breaking-changes-super-extends).
|
||||
* Literate CoffeeScript is now parsed entirely based on indentation, similar to the 1.x implementation; there is no longer a dependency for parsing Markdown. See [breaking changes for Literate CoffeeScript parsing](#breaking-changes-literate-coffeescript).
|
||||
* JavaScript reserved words used as properties are no longer wrapped in quotes.
|
||||
* `require('coffeescript')` should now work in non-Node environments such as the builds created by Webpack or Browserify. This provides a more convenient way to include the browser compiler in builds intending to run in a browser environment.
|
||||
* Unreachable `break` statements are no longer added after `switch` cases that `throw` exceptions.
|
||||
* The browser compiler is now compiled using Babili and transpiled down to Babel’s `env` preset (should be safe for use in all browsers in current use, not just evergreen versions).
|
||||
* Calling functions `@get` or `@set` no longer throws an error about required parentheses. (Bare `get` or `set`, not attached to an object or `@`, [still intentionally throws a compiler error](#unsupported-get-set).)
|
||||
* If `$XDG_CACHE_HOME` is set, the REPL `.coffee_history` file is saved there.
|
||||
|
||||
```
|
||||
releaseHeader('2017-05-15', '1.12.6', '1.12.5')
|
||||
```
|
||||
|
||||
* The `return` and `export` keywords can now accept implicit objects (defined by indentation, without needing braces).
|
||||
* Support Unicode code point escapes (e.g. `\u{1F4A9}`).
|
||||
* The `coffee` command now first looks to see if CoffeeScript is installed under `node_modules` in the current folder, and executes the `coffee` binary there if so; or otherwise it runs the globally installed one. This allows you to have one version of CoffeeScript installed globally and a different one installed locally for a particular project. (Likewise for the `cake` command.)
|
||||
* Bugfixes for chained function calls not closing implicit objects or ternaries.
|
||||
* Bugfixes for incorrect code generated by the `?` operator within a termary `if` statement.
|
||||
* Fixed some tests, and failing tests now result in a nonzero exit code.
|
||||
|
||||
```
|
||||
releaseHeader('2017-04-14', '2.0.0-beta1', '2.0.0-alpha1')
|
||||
```
|
||||
|
||||
* Initial beta release of CoffeeScript 2. No further breaking changes are anticipated.
|
||||
* Destructured objects and arrays now output using ES2015+ syntax whenever possible.
|
||||
* Literate CoffeeScript now has much better support for parsing Markdown, thanks to using [Markdown-It](https://github.com/markdown-it/markdown-it) to detect Markdown sections rather than just looking at indentation.
|
||||
* Calling a function named `get` or `set` now requires parentheses, to disambiguate from the `get` or `set` keywords (which are [disallowed](#unsupported-get-set)).
|
||||
* The compiler now requires Node 7.6+, the first version of Node to support asynchronous functions without requiring a flag.
|
||||
|
||||
```
|
||||
releaseHeader('2017-04-10', '1.12.5', '1.12.4')
|
||||
```
|
||||
|
||||
* Better handling of `default`, `from`, `as` and `*` within `import` and `export` statements. You can now import or export a member named `default` and the compiler won’t interpret it as the `default` keyword.
|
||||
* Fixed a bug where invalid octal escape sequences weren’t throwing errors in the compiler.
|
||||
|
||||
|
||||
```
|
||||
releaseHeader('2017-02-21', '2.0.0-alpha1', '1.12.4')
|
||||
```
|
||||
|
||||
* Initial alpha release of CoffeeScript 2. The CoffeeScript compiler now outputs ES2015+ syntax whenever possible. See [breaking changes](#breaking-changes).
|
||||
* Classes are output using ES2015 `class` and `extends` keywords.
|
||||
* Added support for `async`/`await`.
|
||||
* Bound (arrow) functions now output as `=>` functions.
|
||||
* Function parameters with default values now use ES2015 default values syntax.
|
||||
* Splat function parameters now use ES2015 spread syntax.
|
||||
* Computed properties now use ES2015 syntax.
|
||||
* Interpolated strings (template literals) now use ES2015 backtick syntax.
|
||||
* Improved support for recognizing Markdown in Literate CoffeeScript files.
|
||||
* Mixing tabs and spaces in indentation is now disallowed.
|
||||
* Browser compiler is now minified using the Google Closure Compiler (JavaScript version).
|
||||
* Node 7+ required for CoffeeScript 2.
|
||||
|
||||
```
|
||||
releaseHeader('2017-02-18', '1.12.4', '1.12.3')
|
||||
```
|
||||
|
||||
* The `cake` commands have been updated, with new `watch` options for most tasks. Clone the [CoffeeScript repo](https://github.com/jashkenas/coffeescript) and run `cake` at the root of the repo to see the options.
|
||||
* Fixed a bug where `export`ing a referenced variable was preventing the variable from being declared.
|
||||
* Fixed a bug where the `coffee` command wasn’t working for a `.litcoffee` file.
|
||||
* Bugfixes related to tokens and location data, for better source maps and improved compatibility with downstream tools.
|
||||
|
||||
```
|
||||
releaseHeader('2017-01-24', '1.12.3', '1.12.2')
|
||||
```
|
||||
|
||||
* `@` values can now be used as indices in `for` expressions. This loosens the compilation of `for` expressions to allow the index variable to be an `@` value, e.g. `do @visit for @node, @index in nodes`. Within `@visit`, the index of the current node (`@node`) would be available as `@index`.
|
||||
* CoffeeScript’s patched `Error.prepareStackTrace` has been restored, with some revisions that should prevent the erroneous exceptions that were making life difficult for some downstream projects. This fixes the incorrect line numbers in stack traces since 1.12.2.
|
||||
* The `//=` operator’s output now wraps parentheses around the right operand, like the other assignment operators.
|
||||
|
||||
```
|
||||
releaseHeader('2016-12-16', '1.12.2', '1.12.1')
|
||||
```
|
||||
|
||||
* The browser compiler can once again be built unminified via `MINIFY=false cake build:browser`.
|
||||
* The error-prone patched version of `Error.prepareStackTrace` has been removed.
|
||||
* Command completion in the REPL (pressing tab to get suggestions) has been fixed for Node 6.9.1+.
|
||||
* The [browser-based tests](/v<%= majorVersion %>/test.html) now include all the tests as the Node-based version.
|
||||
|
||||
```
|
||||
releaseHeader('2016-12-07', '1.12.1', '1.12.0')
|
||||
```
|
||||
|
||||
* You can now import a module member named `default`, e.g. `import { default } from 'lib'`. Though like in ES2015, you cannot import an entire module and name it `default` (so `import default from 'lib'` is not allowed).
|
||||
* Fix regression where `from` as a variable name was breaking `for` loop declarations. For the record, `from` is not a reserved word in CoffeeScript; you may use it for variable names. `from` behaves like a keyword within the context of `import` and `export` statements, and in the declaration of a `for` loop; though you should also be able to use variables named `from` in those contexts, and the compiler should be able to tell the difference.
|
||||
|
||||
```
|
||||
releaseHeader('2016-12-04', '1.12.0', '1.11.1')
|
||||
```
|
||||
|
||||
* CoffeeScript now supports ES2015 [tagged template literals](#tagged-template-literals). Note that using tagged template literals in your code makes you responsible for ensuring that either your runtime supports tagged template literals or that you transpile the output JavaScript further to a version your target runtime(s) support.
|
||||
* CoffeeScript now provides a [`for…from`](#generator-iteration) syntax for outputting ES2015 [`for…of`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for...of). (Sorry they couldn’t match, but we came up with `for…of` first for something else.) This allows iterating over generators or any other iterable object. Note that using `for…from` in your code makes you responsible for ensuring that either your runtime supports `for…of` or that you transpile the output JavaScript further to a version your target runtime(s) support.
|
||||
* Triple backticks (`` `````) allow the creation of embedded JavaScript blocks where escaping single backticks is not required, which should improve interoperability with ES2015 template literals and with Markdown.
|
||||
* Within single-backtick embedded JavaScript, backticks can now be escaped via `` \```.
|
||||
* The browser tests now run in the browser again, and are accessible [here](/v<%= majorVersion %>/test.html) if you would like to test your browser.
|
||||
* CoffeeScript-only keywords in ES2015 `import`s and `export`s are now ignored.
|
||||
* The compiler now throws an error on trying to export an anonymous class.
|
||||
* Bugfixes related to tokens and location data, for better source maps and improved compatibility with downstream tools.
|
||||
|
||||
```
|
||||
releaseHeader('2016-10-02', '1.11.1', '1.11.0')
|
||||
```
|
||||
|
||||
* Bugfix for shorthand object syntax after interpolated keys.
|
||||
* Bugfix for indentation-stripping in `"""` strings.
|
||||
* Bugfix for not being able to use the name “arguments” for a prototype property of class.
|
||||
* Correctly compile large hexadecimal numbers literals to `2e308` (just like all other large number literals do).
|
||||
|
||||
```
|
||||
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:
|
||||
```
|
||||
doubles = ->
|
||||
yield for i in [1..3]
|
||||
i * 2
|
||||
six = ->
|
||||
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.
|
||||
* Just like `undefined` compiles to `void 0`, `NaN` now compiles into `0/0` and `Infinity` into `2e308`.
|
||||
* 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.
|
||||
* `coffee -e 'throw null'` no longer crashes.
|
||||
* The REPL no longer crashes when using `.exit` to exit it.
|
||||
* Invalid JavaScript is no longer output when lots of `for` loops are used in the same scope.
|
||||
* A unicode issue when using stdin with the CLI.
|
||||
|
||||
```
|
||||
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.
|
||||
* A variable name clash for the caught error in `catch` blocks.
|
||||
|
||||
```
|
||||
releaseHeader('2015-05-27', '1.9.3', '1.9.2')
|
||||
```
|
||||
|
||||
* Bugfix for interpolation in the first key of an object literal in an implicit call.
|
||||
* Fixed broken error messages in the REPL, as well as a few minor bugs with the REPL.
|
||||
* Fixed source mappings for tokens at the beginning of lines when compiling with the `--bare` option. This has the nice side effect of generating smaller source maps.
|
||||
* Slight formatting improvement of compiled block comments.
|
||||
* Better error messages for `on`, `off`, `yes` and `no`.
|
||||
|
||||
```
|
||||
releaseHeader('2015-04-15', '1.9.2', '1.9.1')
|
||||
```
|
||||
|
||||
* Fixed a **watch** mode error introduced in 1.9.1 when compiling multiple files with the same filename.
|
||||
* Bugfix for `yield` around expressions containing `this`.
|
||||
* Added a Ruby-style `-r` option to the REPL, which allows requiring a module before execution with `--eval` or `--interactive`.
|
||||
* In `<script type="text/coffeescript">` tags, to avoid possible duplicate browser requests for .coffee files, you can now use the `data-src` attribute instead of `src`.
|
||||
* Minor bug fixes for IE8, strict ES5 regular expressions and Browserify.
|
||||
|
||||
```
|
||||
releaseHeader('2015-02-18', '1.9.1', '1.9.0')
|
||||
```
|
||||
|
||||
* Interpolation now works in object literal keys (again). You can use this to dynamically name properties.
|
||||
* Internal compiler variable names no longer start with underscores. This makes the generated JavaScript a bit prettier, and also fixes an issue with the completely broken and ungodly way that AngularJS “parses” function arguments.
|
||||
* Fixed a few `yield`-related edge cases with `yield return` and `yield throw`.
|
||||
* Minor bug fixes and various improvements to compiler error messages.
|
||||
|
||||
```
|
||||
releaseHeader('2015-01-29', '1.9.0', '1.8.0')
|
||||
```
|
||||
|
||||
* CoffeeScript now supports ES2015 generators. A generator is simply a function that `yield`s.
|
||||
* More robust parsing and improved error messages for strings and regexes — especially with respect to interpolation.
|
||||
* Changed strategy for the generation of internal compiler variable names. Note that this means that `@example` function parameters are no longer available as naked `example` variables within the function body.
|
||||
* Fixed REPL compatibility with latest versions of Node and Io.js.
|
||||
* Various minor bug fixes.
|
||||
|
||||
```
|
||||
releaseHeader('2014-08-26', '1.8.0', '1.7.1')
|
||||
```
|
||||
|
||||
* The `--join` option of the CLI is now deprecated.
|
||||
* Source maps now use `.js.map` as file extension, instead of just `.map`.
|
||||
* The CLI now exits with the exit code 1 when it fails to write a file to disk.
|
||||
* The compiler no longer crashes on unterminated, single-quoted strings.
|
||||
* Fixed location data for string interpolations, which made source maps out of sync.
|
||||
* The error marker in error messages is now correctly positioned if the code is indented with tabs.
|
||||
* Fixed a slight formatting error in CoffeeScript’s source map-patched stack traces.
|
||||
* The `%%` operator now coerces its right operand only once.
|
||||
* It is now possible to require CoffeeScript files from Cakefiles without having to register the compiler first.
|
||||
* The CoffeeScript REPL is now exported and can be required using `require 'coffeescript/repl'`.
|
||||
* Fixes for the REPL in Node 0.11.
|
||||
|
||||
```
|
||||
releaseHeader('2014-01-29', '1.7.1', '1.7.0')
|
||||
```
|
||||
|
||||
* Fixed a typo that broke node module lookup when running a script directly with the `coffee` binary.
|
||||
|
||||
```
|
||||
releaseHeader('2014-01-28', '1.7.0', '1.6.3')
|
||||
```
|
||||
|
||||
* When requiring CoffeeScript files in Node you must now explicitly register the compiler. This can be done with `require 'coffeescript/register'` or `CoffeeScript.register()`. Also for configuration such as Mocha’s, use **coffeescript/register**.
|
||||
* Improved error messages, source maps and stack traces. Source maps now use the updated `//#` syntax.
|
||||
* Leading `.` now closes all open calls, allowing for simpler chaining syntax.
|
||||
* Added `**`, `//` and `%%` operators and `...` expansion in parameter lists and destructuring expressions.
|
||||
* Multiline strings are now joined by a single space and ignore all indentation. A backslash at the end of a line can denote the amount of whitespace between lines, in both strings and heredocs. Backslashes correctly escape whitespace in block regexes.
|
||||
* Closing brackets can now be indented and therefore no longer cause unexpected error.
|
||||
* Several breaking compilation fixes. Non-callable literals (strings, numbers etc.) don’t compile in a call now and multiple postfix conditionals compile properly. Postfix conditionals and loops always bind object literals. Conditional assignment compiles properly in subexpressions. `super` is disallowed outside of methods and works correctly inside `for` loops.
|
||||
* Formatting of compiled block comments has been improved.
|
||||
* No more `-p` folders on Windows.
|
||||
* The `options` object passed to CoffeeScript is no longer mutated.
|
||||
|
||||
```
|
||||
releaseHeader('2013-06-02', '1.6.3', '1.6.2')
|
||||
```
|
||||
|
||||
* The CoffeeScript REPL now remembers your history between sessions. Just like a proper REPL should.
|
||||
* You can now use `require` in Node to load `.coffee.md` Literate CoffeeScript files. In the browser, `text/literate-coffeescript` script tags.
|
||||
* The old `coffee --lint` command has been removed. It was useful while originally working on the compiler, but has been surpassed by JSHint. You may now use `-l` to pass literate files in over **stdio**.
|
||||
* Bugfixes for Windows path separators, `catch` without naming the error, and executable-class-bodies-with- prototypal-property-attachment.
|
||||
|
||||
```
|
||||
releaseHeader('2013-03-18', '1.6.2', '1.6.1')
|
||||
```
|
||||
|
||||
* Source maps have been used to provide automatic line-mapping when running CoffeeScript directly via the `coffee` command, and for automatic line-mapping when running CoffeeScript directly in the browser. Also, to provide better error messages for semantic errors thrown by the compiler — [with colors, even](http://cl.ly/NdOA).
|
||||
* Improved support for mixed literate/vanilla-style CoffeeScript projects, and generating source maps for both at the same time.
|
||||
* Fixes for **1.6.x** regressions with overriding inherited bound functions, and for Windows file path management.
|
||||
* The `coffee` command can now correctly `fork()` both `.coffee` and `.js` files. (Requires Node.js 0.9+)
|
||||
|
||||
```
|
||||
releaseHeader('2013-03-05', '1.6.1', '1.5.0')
|
||||
```
|
||||
|
||||
* First release of [source maps](#source-maps). Pass the `--map` flag to the compiler, and off you go. Direct all your thanks over to [Jason Walton](https://github.com/jwalton).
|
||||
* Fixed a 1.5.0 regression with multiple implicit calls against an indented implicit object. Combinations of implicit function calls and implicit objects should generally be parsed better now — but it still isn’t good _style_ to nest them too heavily.
|
||||
* `.coffee.md` is now also supported as a Literate CoffeeScript file extension, for existing tooling. `.litcoffee` remains the canonical one.
|
||||
* Several minor fixes surrounding member properties, bound methods and `super` in class declarations.
|
||||
|
||||
```
|
||||
releaseHeader('2013-02-25', '1.5.0', '1.4.0')
|
||||
```
|
||||
|
||||
* First release of [Literate CoffeeScript](#literate).
|
||||
* The CoffeeScript REPL is now based on the Node.js REPL, and should work better and more familiarly.
|
||||
* Returning explicit values from constructors is now forbidden. If you want to return an arbitrary value, use a function, not a constructor.
|
||||
* You can now loop over an array backwards, without having to manually deal with the indexes: `for item in list by -1`
|
||||
* Source locations are now preserved in the CoffeeScript AST, although source maps are not yet being emitted.
|
||||
|
||||
```
|
||||
releaseHeader('2012-10-23', '1.4.0', '1.3.3')
|
||||
```
|
||||
|
||||
* The CoffeeScript compiler now strips Microsoft’s UTF-8 BOM if it exists, allowing you to compile BOM-borked source files.
|
||||
* Fix Node/compiler deprecation warnings by removing `registerExtension`, and moving from `path.exists` to `fs.exists`.
|
||||
* Small tweaks to splat compilation, backticks, slicing, and the error for duplicate keys in object literals.
|
||||
|
||||
```
|
||||
releaseHeader('2012-05-15', '1.3.3', '1.3.1')
|
||||
```
|
||||
|
||||
* Due to the new semantics of JavaScript’s strict mode, CoffeeScript no longer guarantees that constructor functions have names in all runtimes. See [#2052](https://github.com/jashkenas/coffeescript/issues/2052) for discussion.
|
||||
* Inside of a nested function inside of an instance method, it’s now possible to call `super` more reliably (walks recursively up).
|
||||
* Named loop variables no longer have different scoping heuristics than other local variables. (Reverts #643)
|
||||
* Fix for splats nested within the LHS of destructuring assignment.
|
||||
* Corrections to our compile time strict mode forbidding of octal literals.
|
||||
|
||||
```
|
||||
releaseHeader('2012-04-10', '1.3.1', '1.2.0')
|
||||
```
|
||||
|
||||
* CoffeeScript now enforces all of JavaScript’s **Strict Mode** early syntax errors at compile time. This includes old-style octal literals, duplicate property names in object literals, duplicate parameters in a function definition, deleting naked variables, setting the value of `eval` or `arguments`, and more. See a full discussion at [#1547](https://github.com/jashkenas/coffeescript/issues/1547).
|
||||
* The REPL now has a handy new multi-line mode for entering large blocks of code. It’s useful when copy-and-pasting examples into the REPL. Enter multi-line mode with `Ctrl-V`. You may also now pipe input directly into the REPL.
|
||||
* CoffeeScript now prints a `Generated by CoffeeScript VERSION` header at the top of each compiled file.
|
||||
* Conditional assignment of previously undefined variables `a or= b` is now considered a syntax error.
|
||||
* A tweak to the semantics of `do`, which can now be used to more easily simulate a namespace: `do (x = 1, y = 2) -> …`
|
||||
* Loop indices are now mutable within a loop iteration, and immutable between them.
|
||||
* Both endpoints of a slice are now allowed to be omitted for consistency, effectively creating a shallow copy of the list.
|
||||
* Additional tweaks and improvements to `coffee --watch` under Node’s “new” file watching API. Watch will now beep by default if you introduce a syntax error into a watched script. We also now ignore hidden directories by default when watching recursively.
|
||||
|
||||
```
|
||||
releaseHeader('2011-12-18', '1.2.0', '1.1.3')
|
||||
```
|
||||
|
||||
* Multiple improvements to `coffee --watch` and `--join`. You may now use both together, as well as add and remove files and directories within a `--watch`’d folder.
|
||||
* The `throw` statement can now be used as part of an expression.
|
||||
* Block comments at the top of the file will now appear outside of the safety closure wrapper.
|
||||
* Fixed a number of minor 1.1.3 regressions having to do with trailing operators and unfinished lines, and a more major 1.1.3 regression that caused bound functions _within_ bound class functions to have the incorrect `this`.
|
||||
|
||||
```
|
||||
releaseHeader('2011-11-08', '1.1.3', '1.1.2')
|
||||
```
|
||||
|
||||
* Ahh, whitespace. CoffeeScript’s compiled JS now tries to space things out and keep it readable, as you can see in the examples on this page.
|
||||
* You can now call `super` in class level methods in class bodies, and bound class methods now preserve their correct context.
|
||||
* JavaScript has always supported octal numbers `010 is 8`, and hexadecimal numbers `0xf is 15`, but CoffeeScript now also supports binary numbers: `0b10 is 2`.
|
||||
* The CoffeeScript module has been nested under a subdirectory to make it easier to `require` individual components separately, without having to use **npm**. For example, after adding the CoffeeScript folder to your path: `require('coffeescript/lexer')`
|
||||
* There’s a new “link” feature in Try CoffeeScript on this webpage. Use it to get a shareable permalink for your example script.
|
||||
* The `coffee --watch` feature now only works on Node.js 0.6.0 and higher, but now also works properly on Windows.
|
||||
* Lots of small bug fixes from **[@michaelficarra](https://github.com/michaelficarra)**, **[@geraldalewis](https://github.com/geraldalewis)**, **[@satyr](https://github.com/satyr)**, and **[@trevorburnham](https://github.com/trevorburnham)**.
|
||||
|
||||
```
|
||||
releaseHeader('2011-08-04', '1.1.2', '1.1.1')
|
||||
```
|
||||
|
||||
Fixes for block comment formatting, `?=` compilation, implicit calls against control structures, implicit invocation of a try/catch block, variadic arguments leaking from local scope, line numbers in syntax errors following heregexes, property access on parenthesized number literals, bound class methods and super with reserved names, a REPL overhaul, consecutive compiled semicolons, block comments in implicitly called objects, and a Chrome bug.
|
||||
|
||||
```
|
||||
releaseHeader('2011-05-10', '1.1.1', '1.1.0')
|
||||
```
|
||||
|
||||
Bugfix release for classes with external constructor functions, see issue #1182.
|
||||
|
||||
```
|
||||
releaseHeader('2011-05-01', '1.1.0', '1.0.1')
|
||||
```
|
||||
|
||||
When running via the `coffee` executable, `process.argv` and friends now report `coffee` instead of `node`. Better compatibility with **Node.js 0.4.x** module lookup changes. The output in the REPL is now colorized, like Node’s is. Giving your concatenated CoffeeScripts a name when using `--join` is now mandatory. Fix for lexing compound division `/=` as a regex accidentally. All `text/coffeescript` tags should now execute in the order they’re included. Fixed an issue with extended subclasses using external constructor functions. Fixed an edge-case infinite loop in `addImplicitParentheses`. Fixed exponential slowdown with long chains of function calls. Globals no longer leak into the CoffeeScript REPL. Splatted parameters are declared local to the function.
|
||||
|
||||
```
|
||||
releaseHeader('2011-01-31', '1.0.1', '1.0.0')
|
||||
```
|
||||
|
||||
Fixed a lexer bug with Unicode identifiers. Updated REPL for compatibility with Node.js 0.3.7\. Fixed requiring relative paths in the REPL. Trailing `return` and `return undefined` are now optimized away. Stopped requiring the core Node.js `util` module for back-compatibility with Node.js 0.2.5\. Fixed a case where a conditional `return` would cause fallthrough in a `switch` statement. Optimized empty objects in destructuring assignment.
|
||||
|
||||
```
|
||||
releaseHeader('2010-12-24', '1.0.0', '0.9.6')
|
||||
```
|
||||
|
||||
CoffeeScript loops no longer try to preserve block scope when functions are being generated within the loop body. Instead, you can use the `do` keyword to create a convenient closure wrapper. Added a `--nodejs` flag for passing through options directly to the `node` executable. Better behavior around the use of pure statements within expressions. Fixed inclusive slicing through `-1`, for all browsers, and splicing with arbitrary expressions as endpoints.
|
||||
|
||||
```
|
||||
releaseHeader('2010-12-06', '0.9.6', '0.9.5')
|
||||
```
|
||||
|
||||
The REPL now properly formats stacktraces, and stays alive through asynchronous exceptions. Using `--watch` now prints timestamps as files are compiled. Fixed some accidentally-leaking variables within plucked closure-loops. Constructors now maintain their declaration location within a class body. Dynamic object keys were removed. Nested classes are now supported. Fixes execution context for naked splatted functions. Bugfix for inversion of chained comparisons. Chained class instantiation now works properly with splats.
|
||||
|
||||
```
|
||||
releaseHeader('2010-11-21', '0.9.5', '0.9.4')
|
||||
```
|
||||
|
||||
0.9.5 should be considered the first release candidate for CoffeeScript 1.0. There have been a large number of internal changes since the previous release, many contributed from **satyr**’s [Coco](https://github.com/satyr/coco) dialect of CoffeeScript. Heregexes (extended regexes) were added. Functions can now have default arguments. Class bodies are now executable code. Improved syntax errors for invalid CoffeeScript. `undefined` now works like `null`, and cannot be assigned a new value. There was a precedence change with respect to single-line comprehensions: `result = i for i in list`
|
||||
used to parse as `result = (i for i in list)` by default … it now parses as
|
||||
`(result = i) for i in list`.
|
||||
|
||||
```
|
||||
releaseHeader('2010-09-21', '0.9.4', '0.9.3')
|
||||
```
|
||||
|
||||
CoffeeScript now uses appropriately-named temporary variables, and recycles their references after use. Added `require.extensions` support for **Node.js 0.3**. Loading CoffeeScript in the browser now adds just a single `CoffeeScript` object to global scope. Fixes for implicit object and block comment edge cases.
|
||||
|
||||
```
|
||||
releaseHeader('2010-09-16', '0.9.3', '0.9.2')
|
||||
```
|
||||
|
||||
CoffeeScript `switch` statements now compile into JS `switch` statements — they previously compiled into `if/else` chains for JavaScript 1.3 compatibility. Soaking a function invocation is now supported. Users of the RubyMine editor should now be able to use `--watch` mode.
|
||||
|
||||
```
|
||||
releaseHeader('2010-08-23', '0.9.2', '0.9.1')
|
||||
```
|
||||
|
||||
Specifying the start and end of a range literal is now optional, eg. `array[3..]`. You can now say `a not instanceof b`. Fixed important bugs with nested significant and non-significant indentation (Issue #637). Added a `--require` flag that allows you to hook into the `coffee` command. Added a custom `jsl.conf` file for our preferred JavaScriptLint setup. Sped up Jison grammar compilation time by flattening rules for operations. Block comments can now be used with JavaScript-minifier-friendly syntax. Added JavaScript’s compound assignment bitwise operators. Bugfixes to implicit object literals with leading number and string keys, as the subject of implicit calls, and as part of compound assignment.
|
||||
|
||||
```
|
||||
releaseHeader('2010-08-11', '0.9.1', '0.9.0')
|
||||
```
|
||||
|
||||
Bugfix release for **0.9.1**. Greatly improves the handling of mixed implicit objects, implicit function calls, and implicit indentation. String and regex interpolation is now strictly `#{ … }` (Ruby style). The compiler now takes a `--require` flag, which specifies scripts to run before compilation.
|
||||
|
||||
```
|
||||
releaseHeader('2010-08-04', '0.9.0', '0.7.2')
|
||||
```
|
||||
|
||||
The CoffeeScript **0.9** series is considered to be a release candidate for **1.0**; let’s give her a shakedown cruise. **0.9.0** introduces a massive backwards-incompatible change: Assignment now uses `=`, and object literals use `:`, as in JavaScript. This allows us to have implicit object literals, and YAML-style object definitions. Half assignments are removed, in favor of `+=`, `or=`, and friends. Interpolation now uses a hash mark `#` instead of the dollar sign `$` — because dollar signs may be part of a valid JS identifier. Downwards range comprehensions are now safe again, and are optimized to straight for loops when created with integer endpoints. A fast, unguarded form of object comprehension was added: `for all key, value of object`. Mentioning the `super` keyword with no arguments now forwards all arguments passed to the function, as in Ruby. If you extend class `B` from parent class `A`, if `A` has an `extended` method defined, it will be called, passing in `B` — this enables static inheritance, among other things. Cleaner output for functions bound with the fat arrow. `@variables` can now be used in parameter lists, with the parameter being automatically set as a property on the object — useful in constructors and setter functions. Constructor functions can now take splats.
|
||||
|
||||
```
|
||||
releaseHeader('2010-07-12', '0.7.2', '0.7.1')
|
||||
```
|
||||
|
||||
Quick bugfix (right after 0.7.1) for a problem that prevented `coffee` command-line options from being parsed in some circumstances.
|
||||
|
||||
```
|
||||
releaseHeader('2010-07-11', '0.7.1', '0.7.0')
|
||||
```
|
||||
|
||||
Block-style comments are now passed through and printed as JavaScript block comments – making them useful for licenses and copyright headers. Better support for running coffee scripts standalone via hashbangs. Improved syntax errors for tokens that are not in the grammar.
|
||||
|
||||
```
|
||||
releaseHeader('2010-06-28', '0.7.0', '0.6.2')
|
||||
```
|
||||
|
||||
Official CoffeeScript variable style is now camelCase, as in JavaScript. Reserved words are now allowed as object keys, and will be quoted for you. Range comprehensions now generate cleaner code, but you have to specify `by -1` if you’d like to iterate downward. Reporting of syntax errors is greatly improved from the previous release. Running `coffee` with no arguments now launches the REPL, with Readline support. The `<-` bind operator has been removed from CoffeeScript. The `loop` keyword was added, which is equivalent to a `while true` loop. Comprehensions that contain closures will now close over their variables, like the semantics of a `forEach`. You can now use bound function in class definitions (bound to the instance). For consistency, `a in b` is now an array presence check, and `a of b` is an object-key check. Comments are no longer passed through to the generated JavaScript.
|
||||
|
||||
```
|
||||
releaseHeader('2010-05-15', '0.6.2', '0.6.1')
|
||||
```
|
||||
|
||||
The `coffee` command will now preserve directory structure when compiling a directory full of scripts. Fixed two omissions that were preventing the CoffeeScript compiler from running live within Internet Explorer. There’s now a syntax for block comments, similar in spirit to CoffeeScript’s heredocs. ECMA Harmony DRY-style pattern matching is now supported, where the name of the property is the same as the name of the value: `{name, length}: func`. Pattern matching is now allowed within comprehension variables. `unless` is now allowed in block form. `until` loops were added, as the inverse of `while` loops. `switch` statements are now allowed without switch object clauses. Compatible with Node.js **v0.1.95**.
|
||||
|
||||
```
|
||||
releaseHeader('2010-04-12', '0.6.1', '0.6.0')
|
||||
```
|
||||
|
||||
Upgraded CoffeeScript for compatibility with the new Node.js **v0.1.90** series.
|
||||
|
||||
```
|
||||
releaseHeader('2010-04-03', '0.6.0', '0.5.6')
|
||||
```
|
||||
|
||||
Trailing commas are now allowed, a-la Python. Static properties may be assigned directly within class definitions, using `@property` notation.
|
||||
|
||||
```
|
||||
releaseHeader('2010-03-23', '0.5.6', '0.5.5')
|
||||
```
|
||||
|
||||
Interpolation can now be used within regular expressions and heredocs, as well as strings. Added the `<-` bind operator. Allowing assignment to half-expressions instead of special `||=`-style operators. The arguments object is no longer automatically converted into an array. After requiring `coffeescript`, Node.js can now directly load `.coffee` files, thanks to **registerExtension**. Multiple splats can now be used in function calls, arrays, and pattern matching.
|
||||
|
||||
```
|
||||
releaseHeader('2010-03-08', '0.5.5', '0.5.4')
|
||||
```
|
||||
|
||||
String interpolation, contributed by [Stan Angeloff](https://github.com/StanAngeloff). Since `--run` has been the default since **0.5.3**, updating `--stdio` and `--eval` to run by default, pass `--compile` as well if you’d like to print the result.
|
||||
|
||||
```
|
||||
releaseHeader('2010-03-03', '0.5.4', '0.5.3')
|
||||
```
|
||||
|
||||
Bugfix that corrects the Node.js global constants `__filename` and `__dirname`. Tweaks for more flexible parsing of nested function literals and improperly-indented comments. Updates for the latest Node.js API.
|
||||
|
||||
```
|
||||
releaseHeader('2010-02-27', '0.5.3', '0.5.2')
|
||||
```
|
||||
|
||||
CoffeeScript now has a syntax for defining classes. Many of the core components (Nodes, Lexer, Rewriter, Scope, Optparse) are using them. Cakefiles can use `optparse.coffee` to define options for tasks. `--run` is now the default flag for the `coffee` command, use `--compile` to save JavaScripts. Bugfix for an ambiguity between RegExp literals and chained divisions.
|
||||
|
||||
```
|
||||
releaseHeader('2010-02-25', '0.5.2', '0.5.1')
|
||||
```
|
||||
|
||||
Added a compressed version of the compiler for inclusion in web pages as
|
||||
`/v<%= majorVersion %>/browser-compiler/coffeescript.js`. It’ll automatically run any script tags with type `text/coffeescript` for you. Added a `--stdio` option to the `coffee` command, for piped-in compiles.
|
||||
|
||||
```
|
||||
releaseHeader('2010-02-24', '0.5.1', '0.5.0')
|
||||
```
|
||||
|
||||
Improvements to null soaking with the existential operator, including soaks on indexed properties. Added conditions to `while` loops, so you can use them as filters with `when`, in the same manner as comprehensions.
|
||||
|
||||
```
|
||||
releaseHeader('2010-02-21', '0.5.0', '0.3.2')
|
||||
```
|
||||
|
||||
CoffeeScript 0.5.0 is a major release, While there are no language changes, the Ruby compiler has been removed in favor of a self-hosting compiler written in pure CoffeeScript.
|
||||
|
||||
```
|
||||
releaseHeader('2010-02-08', '0.3.2', '0.3.0')
|
||||
```
|
||||
|
||||
`@property` is now a shorthand for `this.property`.
|
||||
Switched the default JavaScript engine from Narwhal to Node.js. Pass the `--narwhal` flag if you’d like to continue using it.
|
||||
|
||||
```
|
||||
releaseHeader('2010-01-26', '0.3.0', '0.2.6')
|
||||
```
|
||||
|
||||
CoffeeScript 0.3 includes major syntax changes:
|
||||
The function symbol was changed to `->`, and the bound function symbol is now `=>`.
|
||||
Parameter lists in function definitions must now be wrapped in parentheses.
|
||||
Added property soaking, with the `?.` operator.
|
||||
Made parentheses optional, when invoking functions with arguments.
|
||||
Removed the obsolete block literal syntax.
|
||||
|
||||
```
|
||||
releaseHeader('2010-01-17', '0.2.6', '0.2.5')
|
||||
```
|
||||
|
||||
Added Python-style chained comparisons, the conditional existence operator `?=`, and some examples from _Beautiful Code_. Bugfixes relating to statement-to-expression conversion, arguments-to-array conversion, and the TextMate syntax highlighter.
|
||||
|
||||
```
|
||||
releaseHeader('2010-01-13', '0.2.5', '0.2.4')
|
||||
```
|
||||
|
||||
The conditions in switch statements can now take multiple values at once — If any of them are true, the case will run. Added the long arrow `==>`, which defines and immediately binds a function to `this`. While loops can now be used as expressions, in the same way that comprehensions can. Splats can be used within pattern matches to soak up the rest of an array.
|
||||
|
||||
```
|
||||
releaseHeader('2010-01-12', '0.2.4', '0.2.3')
|
||||
```
|
||||
|
||||
Added ECMAScript Harmony style destructuring assignment, for dealing with extracting values from nested arrays and objects. Added indentation-sensitive heredocs for nicely formatted strings or chunks of code.
|
||||
|
||||
```
|
||||
releaseHeader('2010-01-11', '0.2.3', '0.2.2')
|
||||
```
|
||||
|
||||
Axed the unsatisfactory `ino` keyword, replacing it with `of` for object comprehensions. They now look like: `for prop, value of object`.
|
||||
|
||||
```
|
||||
releaseHeader('2010-01-10', '0.2.2', '0.2.1')
|
||||
```
|
||||
|
||||
When performing a comprehension over an object, use `ino`, instead of `in`, which helps us generate smaller, more efficient code at compile time.
|
||||
Added `::` as a shorthand for saying `.prototype.`
|
||||
The “splat” symbol has been changed from a prefix asterisk `*`, to a postfix ellipsis `...`
|
||||
Added JavaScript’s `in` operator, empty `return` statements, and empty `while` loops.
|
||||
Constructor functions that start with capital letters now include a safety check to make sure that the new instance of the object is returned.
|
||||
The `extends` keyword now functions identically to `goog.inherits` in Google’s Closure Library.
|
||||
|
||||
```
|
||||
releaseHeader('2010-01-05', '0.2.1', '0.2.0')
|
||||
```
|
||||
|
||||
Arguments objects are now converted into real arrays when referenced.
|
||||
|
||||
```
|
||||
releaseHeader('2010-01-05', '0.2.0', '0.1.6')
|
||||
```
|
||||
|
||||
Major release. Significant whitespace. Better statement-to-expression conversion. Splats. Splice literals. Object comprehensions. Blocks. The existential operator. Many thanks to all the folks who posted issues, with special thanks to [Liam O’Connor-Davis](https://github.com/liamoc) for whitespace and expression help.
|
||||
|
||||
```
|
||||
releaseHeader('2009-12-27', '0.1.6', '0.1.5')
|
||||
```
|
||||
|
||||
Bugfix for running `coffee --interactive` and `--run` from outside of the CoffeeScript directory. Bugfix for nested function/if-statements.
|
||||
|
||||
```
|
||||
releaseHeader('2009-12-26', '0.1.5', '0.1.4')
|
||||
```
|
||||
|
||||
Array slice literals and array comprehensions can now both take Ruby-style ranges to specify the start and end. JavaScript variable declaration is now pushed up to the top of the scope, making all assignment statements into expressions. You can use `\` to escape newlines. The `coffeescript` command is now called `coffee`.
|
||||
|
||||
```
|
||||
releaseHeader('2009-12-25', '0.1.4', '0.1.3')
|
||||
```
|
||||
|
||||
The official CoffeeScript extension is now `.coffee` instead of `.cs`, which properly belongs to [C#](https://en.wikipedia.org/wiki/C_Sharp_(programming_language)). Due to popular demand, you can now also use `=` to assign. Unlike JavaScript, `=` can also be used within object literals, interchangeably with `:`. Made a grammatical fix for chained function calls like `func(1)(2)(3)(4)`. Inheritance and super no longer use `__proto__`, so they should be IE-compatible now.
|
||||
|
||||
```
|
||||
releaseHeader('2009-12-25', '0.1.3', '0.1.2')
|
||||
```
|
||||
|
||||
The `coffee` command now includes `--interactive`, which launches an interactive CoffeeScript session, and `--run`, which directly compiles and executes a script. Both options depend on a working installation of Narwhal. The `aint` keyword has been replaced by `isnt`, which goes together a little smoother with `is`. Quoted strings are now allowed as identifiers within object literals: eg. `{"5+5": 10}`. All assignment operators now use a colon: `+:`, `-:`, `*:`, etc.
|
||||
|
||||
```
|
||||
releaseHeader('2009-12-24', '0.1.2', '0.1.1')
|
||||
```
|
||||
|
||||
Fixed a bug with calling `super()` through more than one level of inheritance, with the re-addition of the `extends` keyword. Added experimental [Narwhal](http://narwhaljs.org/) support (as a Tusk package), contributed by [Tom Robinson](http://blog.tlrobinson.net/), including **bin/cs** as a CoffeeScript REPL and interpreter. New `--no-wrap` option to suppress the safety function wrapper.
|
||||
|
||||
```
|
||||
releaseHeader('2009-12-24', '0.1.1', '0.1.0')
|
||||
```
|
||||
|
||||
Added `instanceof` and `typeof` as operators.
|
||||
|
||||
```
|
||||
releaseHeader('2009-12-24', '0.1.0', '8e9d637985d2dc9b44922076ad54ffef7fa8e9c2')
|
||||
```
|
||||
|
||||
Initial CoffeeScript release.
|
||||
|
||||
5
documentation/sections/changelog/0.1.0.md
Normal file
5
documentation/sections/changelog/0.1.0.md
Normal file
@@ -0,0 +1,5 @@
|
||||
```
|
||||
releaseHeader('2009-12-24', '0.1.0', '8e9d637985d2dc9b44922076ad54ffef7fa8e9c2')
|
||||
```
|
||||
|
||||
Initial CoffeeScript release.
|
||||
5
documentation/sections/changelog/0.1.1.md
Normal file
5
documentation/sections/changelog/0.1.1.md
Normal file
@@ -0,0 +1,5 @@
|
||||
```
|
||||
releaseHeader('2009-12-24', '0.1.1', '0.1.0')
|
||||
```
|
||||
|
||||
Added `instanceof` and `typeof` as operators.
|
||||
5
documentation/sections/changelog/0.1.2.md
Normal file
5
documentation/sections/changelog/0.1.2.md
Normal file
@@ -0,0 +1,5 @@
|
||||
```
|
||||
releaseHeader('2009-12-24', '0.1.2', '0.1.1')
|
||||
```
|
||||
|
||||
Fixed a bug with calling `super()` through more than one level of inheritance, with the re-addition of the `extends` keyword. Added experimental [Narwhal](http://narwhaljs.org/) support (as a Tusk package), contributed by [Tom Robinson](http://blog.tlrobinson.net/), including **bin/cs** as a CoffeeScript REPL and interpreter. New `--no-wrap` option to suppress the safety function wrapper.
|
||||
5
documentation/sections/changelog/0.1.3.md
Normal file
5
documentation/sections/changelog/0.1.3.md
Normal file
@@ -0,0 +1,5 @@
|
||||
```
|
||||
releaseHeader('2009-12-25', '0.1.3', '0.1.2')
|
||||
```
|
||||
|
||||
The `coffee` command now includes `--interactive`, which launches an interactive CoffeeScript session, and `--run`, which directly compiles and executes a script. Both options depend on a working installation of Narwhal. The `aint` keyword has been replaced by `isnt`, which goes together a little smoother with `is`. Quoted strings are now allowed as identifiers within object literals: eg. `{"5+5": 10}`. All assignment operators now use a colon: `+:`, `-:`, `*:`, etc.
|
||||
5
documentation/sections/changelog/0.1.4.md
Normal file
5
documentation/sections/changelog/0.1.4.md
Normal file
@@ -0,0 +1,5 @@
|
||||
```
|
||||
releaseHeader('2009-12-25', '0.1.4', '0.1.3')
|
||||
```
|
||||
|
||||
The official CoffeeScript extension is now `.coffee` instead of `.cs`, which properly belongs to [C#](https://en.wikipedia.org/wiki/C_Sharp_(programming_language)). Due to popular demand, you can now also use `=` to assign. Unlike JavaScript, `=` can also be used within object literals, interchangeably with `:`. Made a grammatical fix for chained function calls like `func(1)(2)(3)(4)`. Inheritance and super no longer use `__proto__`, so they should be IE-compatible now.
|
||||
5
documentation/sections/changelog/0.1.5.md
Normal file
5
documentation/sections/changelog/0.1.5.md
Normal file
@@ -0,0 +1,5 @@
|
||||
```
|
||||
releaseHeader('2009-12-26', '0.1.5', '0.1.4')
|
||||
```
|
||||
|
||||
Array slice literals and array comprehensions can now both take Ruby-style ranges to specify the start and end. JavaScript variable declaration is now pushed up to the top of the scope, making all assignment statements into expressions. You can use `\` to escape newlines. The `coffeescript` command is now called `coffee`.
|
||||
5
documentation/sections/changelog/0.1.6.md
Normal file
5
documentation/sections/changelog/0.1.6.md
Normal file
@@ -0,0 +1,5 @@
|
||||
```
|
||||
releaseHeader('2009-12-27', '0.1.6', '0.1.5')
|
||||
```
|
||||
|
||||
Bugfix for running `coffee --interactive` and `--run` from outside of the CoffeeScript directory. Bugfix for nested function/if-statements.
|
||||
5
documentation/sections/changelog/0.2.0.md
Normal file
5
documentation/sections/changelog/0.2.0.md
Normal file
@@ -0,0 +1,5 @@
|
||||
```
|
||||
releaseHeader('2010-01-05', '0.2.0', '0.1.6')
|
||||
```
|
||||
|
||||
Major release. Significant whitespace. Better statement-to-expression conversion. Splats. Splice literals. Object comprehensions. Blocks. The existential operator. Many thanks to all the folks who posted issues, with special thanks to [Liam O’Connor-Davis](https://github.com/liamoc) for whitespace and expression help.
|
||||
5
documentation/sections/changelog/0.2.1.md
Normal file
5
documentation/sections/changelog/0.2.1.md
Normal file
@@ -0,0 +1,5 @@
|
||||
```
|
||||
releaseHeader('2010-01-05', '0.2.1', '0.2.0')
|
||||
```
|
||||
|
||||
Arguments objects are now converted into real arrays when referenced.
|
||||
10
documentation/sections/changelog/0.2.2.md
Normal file
10
documentation/sections/changelog/0.2.2.md
Normal file
@@ -0,0 +1,10 @@
|
||||
```
|
||||
releaseHeader('2010-01-10', '0.2.2', '0.2.1')
|
||||
```
|
||||
|
||||
When performing a comprehension over an object, use `ino`, instead of `in`, which helps us generate smaller, more efficient code at compile time.
|
||||
Added `::` as a shorthand for saying `.prototype.`
|
||||
The “splat” symbol has been changed from a prefix asterisk `*`, to a postfix ellipsis `...`
|
||||
Added JavaScript’s `in` operator, empty `return` statements, and empty `while` loops.
|
||||
Constructor functions that start with capital letters now include a safety check to make sure that the new instance of the object is returned.
|
||||
The `extends` keyword now functions identically to `goog.inherits` in Google’s Closure Library.
|
||||
5
documentation/sections/changelog/0.2.3.md
Normal file
5
documentation/sections/changelog/0.2.3.md
Normal file
@@ -0,0 +1,5 @@
|
||||
```
|
||||
releaseHeader('2010-01-11', '0.2.3', '0.2.2')
|
||||
```
|
||||
|
||||
Axed the unsatisfactory `ino` keyword, replacing it with `of` for object comprehensions. They now look like: `for prop, value of object`.
|
||||
5
documentation/sections/changelog/0.2.4.md
Normal file
5
documentation/sections/changelog/0.2.4.md
Normal file
@@ -0,0 +1,5 @@
|
||||
```
|
||||
releaseHeader('2010-01-12', '0.2.4', '0.2.3')
|
||||
```
|
||||
|
||||
Added ECMAScript Harmony style destructuring assignment, for dealing with extracting values from nested arrays and objects. Added indentation-sensitive heredocs for nicely formatted strings or chunks of code.
|
||||
5
documentation/sections/changelog/0.2.5.md
Normal file
5
documentation/sections/changelog/0.2.5.md
Normal file
@@ -0,0 +1,5 @@
|
||||
```
|
||||
releaseHeader('2010-01-13', '0.2.5', '0.2.4')
|
||||
```
|
||||
|
||||
The conditions in switch statements can now take multiple values at once — If any of them are true, the case will run. Added the long arrow `==>`, which defines and immediately binds a function to `this`. While loops can now be used as expressions, in the same way that comprehensions can. Splats can be used within pattern matches to soak up the rest of an array.
|
||||
5
documentation/sections/changelog/0.2.6.md
Normal file
5
documentation/sections/changelog/0.2.6.md
Normal file
@@ -0,0 +1,5 @@
|
||||
```
|
||||
releaseHeader('2010-01-17', '0.2.6', '0.2.5')
|
||||
```
|
||||
|
||||
Added Python-style chained comparisons, the conditional existence operator `?=`, and some examples from _Beautiful Code_. Bugfixes relating to statement-to-expression conversion, arguments-to-array conversion, and the TextMate syntax highlighter.
|
||||
10
documentation/sections/changelog/0.3.0.md
Normal file
10
documentation/sections/changelog/0.3.0.md
Normal file
@@ -0,0 +1,10 @@
|
||||
```
|
||||
releaseHeader('2010-01-26', '0.3.0', '0.2.6')
|
||||
```
|
||||
|
||||
CoffeeScript 0.3 includes major syntax changes:
|
||||
The function symbol was changed to `->`, and the bound function symbol is now `=>`.
|
||||
Parameter lists in function definitions must now be wrapped in parentheses.
|
||||
Added property soaking, with the `?.` operator.
|
||||
Made parentheses optional, when invoking functions with arguments.
|
||||
Removed the obsolete block literal syntax.
|
||||
6
documentation/sections/changelog/0.3.2.md
Normal file
6
documentation/sections/changelog/0.3.2.md
Normal file
@@ -0,0 +1,6 @@
|
||||
```
|
||||
releaseHeader('2010-02-08', '0.3.2', '0.3.0')
|
||||
```
|
||||
|
||||
`@property` is now a shorthand for `this.property`.
|
||||
Switched the default JavaScript engine from Narwhal to Node.js. Pass the `--narwhal` flag if you’d like to continue using it.
|
||||
5
documentation/sections/changelog/0.5.0.md
Normal file
5
documentation/sections/changelog/0.5.0.md
Normal file
@@ -0,0 +1,5 @@
|
||||
```
|
||||
releaseHeader('2010-02-21', '0.5.0', '0.3.2')
|
||||
```
|
||||
|
||||
CoffeeScript 0.5.0 is a major release, While there are no language changes, the Ruby compiler has been removed in favor of a self-hosting compiler written in pure CoffeeScript.
|
||||
5
documentation/sections/changelog/0.5.1.md
Normal file
5
documentation/sections/changelog/0.5.1.md
Normal file
@@ -0,0 +1,5 @@
|
||||
```
|
||||
releaseHeader('2010-02-24', '0.5.1', '0.5.0')
|
||||
```
|
||||
|
||||
Improvements to null soaking with the existential operator, including soaks on indexed properties. Added conditions to `while` loops, so you can use them as filters with `when`, in the same manner as comprehensions.
|
||||
6
documentation/sections/changelog/0.5.2.md
Normal file
6
documentation/sections/changelog/0.5.2.md
Normal file
@@ -0,0 +1,6 @@
|
||||
```
|
||||
releaseHeader('2010-02-25', '0.5.2', '0.5.1')
|
||||
```
|
||||
|
||||
Added a compressed version of the compiler for inclusion in web pages as
|
||||
`/v<%= majorVersion %>/browser-compiler-legacy/coffeescript.js`. It’ll automatically run any script tags with type `text/coffeescript` for you. Added a `--stdio` option to the `coffee` command, for piped-in compiles.
|
||||
5
documentation/sections/changelog/0.5.3.md
Normal file
5
documentation/sections/changelog/0.5.3.md
Normal file
@@ -0,0 +1,5 @@
|
||||
```
|
||||
releaseHeader('2010-02-27', '0.5.3', '0.5.2')
|
||||
```
|
||||
|
||||
CoffeeScript now has a syntax for defining classes. Many of the core components (Nodes, Lexer, Rewriter, Scope, Optparse) are using them. Cakefiles can use `optparse.coffee` to define options for tasks. `--run` is now the default flag for the `coffee` command, use `--compile` to save JavaScripts. Bugfix for an ambiguity between RegExp literals and chained divisions.
|
||||
5
documentation/sections/changelog/0.5.4.md
Normal file
5
documentation/sections/changelog/0.5.4.md
Normal file
@@ -0,0 +1,5 @@
|
||||
```
|
||||
releaseHeader('2010-03-03', '0.5.4', '0.5.3')
|
||||
```
|
||||
|
||||
Bugfix that corrects the Node.js global constants `__filename` and `__dirname`. Tweaks for more flexible parsing of nested function literals and improperly-indented comments. Updates for the latest Node.js API.
|
||||
5
documentation/sections/changelog/0.5.5.md
Normal file
5
documentation/sections/changelog/0.5.5.md
Normal file
@@ -0,0 +1,5 @@
|
||||
```
|
||||
releaseHeader('2010-03-08', '0.5.5', '0.5.4')
|
||||
```
|
||||
|
||||
String interpolation, contributed by [Stan Angeloff](https://github.com/StanAngeloff). Since `--run` has been the default since **0.5.3**, updating `--stdio` and `--eval` to run by default, pass `--compile` as well if you’d like to print the result.
|
||||
5
documentation/sections/changelog/0.5.6.md
Normal file
5
documentation/sections/changelog/0.5.6.md
Normal file
@@ -0,0 +1,5 @@
|
||||
```
|
||||
releaseHeader('2010-03-23', '0.5.6', '0.5.5')
|
||||
```
|
||||
|
||||
Interpolation can now be used within regular expressions and heredocs, as well as strings. Added the `<-` bind operator. Allowing assignment to half-expressions instead of special `||=`-style operators. The arguments object is no longer automatically converted into an array. After requiring `coffeescript`, Node.js can now directly load `.coffee` files, thanks to **registerExtension**. Multiple splats can now be used in function calls, arrays, and pattern matching.
|
||||
5
documentation/sections/changelog/0.6.0.md
Normal file
5
documentation/sections/changelog/0.6.0.md
Normal file
@@ -0,0 +1,5 @@
|
||||
```
|
||||
releaseHeader('2010-04-03', '0.6.0', '0.5.6')
|
||||
```
|
||||
|
||||
Trailing commas are now allowed, a-la Python. Static properties may be assigned directly within class definitions, using `@property` notation.
|
||||
5
documentation/sections/changelog/0.6.1.md
Normal file
5
documentation/sections/changelog/0.6.1.md
Normal file
@@ -0,0 +1,5 @@
|
||||
```
|
||||
releaseHeader('2010-04-12', '0.6.1', '0.6.0')
|
||||
```
|
||||
|
||||
Upgraded CoffeeScript for compatibility with the new Node.js **v0.1.90** series.
|
||||
5
documentation/sections/changelog/0.6.2.md
Normal file
5
documentation/sections/changelog/0.6.2.md
Normal file
@@ -0,0 +1,5 @@
|
||||
```
|
||||
releaseHeader('2010-05-15', '0.6.2', '0.6.1')
|
||||
```
|
||||
|
||||
The `coffee` command will now preserve directory structure when compiling a directory full of scripts. Fixed two omissions that were preventing the CoffeeScript compiler from running live within Internet Explorer. There’s now a syntax for block comments, similar in spirit to CoffeeScript’s heredocs. ECMA Harmony DRY-style pattern matching is now supported, where the name of the property is the same as the name of the value: `{name, length}: func`. Pattern matching is now allowed within comprehension variables. `unless` is now allowed in block form. `until` loops were added, as the inverse of `while` loops. `switch` statements are now allowed without switch object clauses. Compatible with Node.js **v0.1.95**.
|
||||
5
documentation/sections/changelog/0.7.0.md
Normal file
5
documentation/sections/changelog/0.7.0.md
Normal file
@@ -0,0 +1,5 @@
|
||||
```
|
||||
releaseHeader('2010-06-28', '0.7.0', '0.6.2')
|
||||
```
|
||||
|
||||
Official CoffeeScript variable style is now camelCase, as in JavaScript. Reserved words are now allowed as object keys, and will be quoted for you. Range comprehensions now generate cleaner code, but you have to specify `by -1` if you’d like to iterate downward. Reporting of syntax errors is greatly improved from the previous release. Running `coffee` with no arguments now launches the REPL, with Readline support. The `<-` bind operator has been removed from CoffeeScript. The `loop` keyword was added, which is equivalent to a `while true` loop. Comprehensions that contain closures will now close over their variables, like the semantics of a `forEach`. You can now use bound function in class definitions (bound to the instance). For consistency, `a in b` is now an array presence check, and `a of b` is an object-key check. Comments are no longer passed through to the generated JavaScript.
|
||||
5
documentation/sections/changelog/0.7.1.md
Normal file
5
documentation/sections/changelog/0.7.1.md
Normal file
@@ -0,0 +1,5 @@
|
||||
```
|
||||
releaseHeader('2010-07-11', '0.7.1', '0.7.0')
|
||||
```
|
||||
|
||||
Block-style comments are now passed through and printed as JavaScript block comments – making them useful for licenses and copyright headers. Better support for running coffee scripts standalone via hashbangs. Improved syntax errors for tokens that are not in the grammar.
|
||||
5
documentation/sections/changelog/0.7.2.md
Normal file
5
documentation/sections/changelog/0.7.2.md
Normal file
@@ -0,0 +1,5 @@
|
||||
```
|
||||
releaseHeader('2010-07-12', '0.7.2', '0.7.1')
|
||||
```
|
||||
|
||||
Quick bugfix (right after 0.7.1) for a problem that prevented `coffee` command-line options from being parsed in some circumstances.
|
||||
5
documentation/sections/changelog/0.9.0.md
Normal file
5
documentation/sections/changelog/0.9.0.md
Normal file
@@ -0,0 +1,5 @@
|
||||
```
|
||||
releaseHeader('2010-08-04', '0.9.0', '0.7.2')
|
||||
```
|
||||
|
||||
The CoffeeScript **0.9** series is considered to be a release candidate for **1.0**; let’s give her a shakedown cruise. **0.9.0** introduces a massive backwards-incompatible change: Assignment now uses `=`, and object literals use `:`, as in JavaScript. This allows us to have implicit object literals, and YAML-style object definitions. Half assignments are removed, in favor of `+=`, `or=`, and friends. Interpolation now uses a hash mark `#` instead of the dollar sign `$` — because dollar signs may be part of a valid JS identifier. Downwards range comprehensions are now safe again, and are optimized to straight for loops when created with integer endpoints. A fast, unguarded form of object comprehension was added: `for all key, value of object`. Mentioning the `super` keyword with no arguments now forwards all arguments passed to the function, as in Ruby. If you extend class `B` from parent class `A`, if `A` has an `extended` method defined, it will be called, passing in `B` — this enables static inheritance, among other things. Cleaner output for functions bound with the fat arrow. `@variables` can now be used in parameter lists, with the parameter being automatically set as a property on the object — useful in constructors and setter functions. Constructor functions can now take splats.
|
||||
5
documentation/sections/changelog/0.9.1.md
Normal file
5
documentation/sections/changelog/0.9.1.md
Normal file
@@ -0,0 +1,5 @@
|
||||
```
|
||||
releaseHeader('2010-08-11', '0.9.1', '0.9.0')
|
||||
```
|
||||
|
||||
Bugfix release for **0.9.1**. Greatly improves the handling of mixed implicit objects, implicit function calls, and implicit indentation. String and regex interpolation is now strictly `#{ … }` (Ruby style). The compiler now takes a `--require` flag, which specifies scripts to run before compilation.
|
||||
5
documentation/sections/changelog/0.9.2.md
Normal file
5
documentation/sections/changelog/0.9.2.md
Normal file
@@ -0,0 +1,5 @@
|
||||
```
|
||||
releaseHeader('2010-08-23', '0.9.2', '0.9.1')
|
||||
```
|
||||
|
||||
Specifying the start and end of a range literal is now optional, eg. `array[3..]`. You can now say `a not instanceof b`. Fixed important bugs with nested significant and non-significant indentation (Issue #637). Added a `--require` flag that allows you to hook into the `coffee` command. Added a custom `jsl.conf` file for our preferred JavaScriptLint setup. Sped up Jison grammar compilation time by flattening rules for operations. Block comments can now be used with JavaScript-minifier-friendly syntax. Added JavaScript’s compound assignment bitwise operators. Bugfixes to implicit object literals with leading number and string keys, as the subject of implicit calls, and as part of compound assignment.
|
||||
5
documentation/sections/changelog/0.9.3.md
Normal file
5
documentation/sections/changelog/0.9.3.md
Normal file
@@ -0,0 +1,5 @@
|
||||
```
|
||||
releaseHeader('2010-09-16', '0.9.3', '0.9.2')
|
||||
```
|
||||
|
||||
CoffeeScript `switch` statements now compile into JS `switch` statements — they previously compiled into `if/else` chains for JavaScript 1.3 compatibility. Soaking a function invocation is now supported. Users of the RubyMine editor should now be able to use `--watch` mode.
|
||||
5
documentation/sections/changelog/0.9.4.md
Normal file
5
documentation/sections/changelog/0.9.4.md
Normal file
@@ -0,0 +1,5 @@
|
||||
```
|
||||
releaseHeader('2010-09-21', '0.9.4', '0.9.3')
|
||||
```
|
||||
|
||||
CoffeeScript now uses appropriately-named temporary variables, and recycles their references after use. Added `require.extensions` support for **Node.js 0.3**. Loading CoffeeScript in the browser now adds just a single `CoffeeScript` object to global scope. Fixes for implicit object and block comment edge cases.
|
||||
7
documentation/sections/changelog/0.9.5.md
Normal file
7
documentation/sections/changelog/0.9.5.md
Normal file
@@ -0,0 +1,7 @@
|
||||
```
|
||||
releaseHeader('2010-11-21', '0.9.5', '0.9.4')
|
||||
```
|
||||
|
||||
0.9.5 should be considered the first release candidate for CoffeeScript 1.0. There have been a large number of internal changes since the previous release, many contributed from **satyr**’s [Coco](https://github.com/satyr/coco) dialect of CoffeeScript. Heregexes (extended regexes) were added. Functions can now have default arguments. Class bodies are now executable code. Improved syntax errors for invalid CoffeeScript. `undefined` now works like `null`, and cannot be assigned a new value. There was a precedence change with respect to single-line comprehensions: `result = i for i in list`
|
||||
used to parse as `result = (i for i in list)` by default … it now parses as
|
||||
`(result = i) for i in list`.
|
||||
5
documentation/sections/changelog/0.9.6.md
Normal file
5
documentation/sections/changelog/0.9.6.md
Normal file
@@ -0,0 +1,5 @@
|
||||
```
|
||||
releaseHeader('2010-12-06', '0.9.6', '0.9.5')
|
||||
```
|
||||
|
||||
The REPL now properly formats stacktraces, and stays alive through asynchronous exceptions. Using `--watch` now prints timestamps as files are compiled. Fixed some accidentally-leaking variables within plucked closure-loops. Constructors now maintain their declaration location within a class body. Dynamic object keys were removed. Nested classes are now supported. Fixes execution context for naked splatted functions. Bugfix for inversion of chained comparisons. Chained class instantiation now works properly with splats.
|
||||
5
documentation/sections/changelog/1.0.0.md
Normal file
5
documentation/sections/changelog/1.0.0.md
Normal file
@@ -0,0 +1,5 @@
|
||||
```
|
||||
releaseHeader('2010-12-24', '1.0.0', '0.9.6')
|
||||
```
|
||||
|
||||
CoffeeScript loops no longer try to preserve block scope when functions are being generated within the loop body. Instead, you can use the `do` keyword to create a convenient closure wrapper. Added a `--nodejs` flag for passing through options directly to the `node` executable. Better behavior around the use of pure statements within expressions. Fixed inclusive slicing through `-1`, for all browsers, and splicing with arbitrary expressions as endpoints.
|
||||
5
documentation/sections/changelog/1.0.1.md
Normal file
5
documentation/sections/changelog/1.0.1.md
Normal file
@@ -0,0 +1,5 @@
|
||||
```
|
||||
releaseHeader('2011-01-31', '1.0.1', '1.0.0')
|
||||
```
|
||||
|
||||
Fixed a lexer bug with Unicode identifiers. Updated REPL for compatibility with Node.js 0.3.7\. Fixed requiring relative paths in the REPL. Trailing `return` and `return undefined` are now optimized away. Stopped requiring the core Node.js `util` module for back-compatibility with Node.js 0.2.5\. Fixed a case where a conditional `return` would cause fallthrough in a `switch` statement. Optimized empty objects in destructuring assignment.
|
||||
5
documentation/sections/changelog/1.1.0.md
Normal file
5
documentation/sections/changelog/1.1.0.md
Normal file
@@ -0,0 +1,5 @@
|
||||
```
|
||||
releaseHeader('2011-05-01', '1.1.0', '1.0.1')
|
||||
```
|
||||
|
||||
When running via the `coffee` executable, `process.argv` and friends now report `coffee` instead of `node`. Better compatibility with **Node.js 0.4.x** module lookup changes. The output in the REPL is now colorized, like Node’s is. Giving your concatenated CoffeeScripts a name when using `--join` is now mandatory. Fix for lexing compound division `/=` as a regex accidentally. All `text/coffeescript` tags should now execute in the order they’re included. Fixed an issue with extended subclasses using external constructor functions. Fixed an edge-case infinite loop in `addImplicitParentheses`. Fixed exponential slowdown with long chains of function calls. Globals no longer leak into the CoffeeScript REPL. Splatted parameters are declared local to the function.
|
||||
5
documentation/sections/changelog/1.1.1.md
Normal file
5
documentation/sections/changelog/1.1.1.md
Normal file
@@ -0,0 +1,5 @@
|
||||
```
|
||||
releaseHeader('2011-05-10', '1.1.1', '1.1.0')
|
||||
```
|
||||
|
||||
Bugfix release for classes with external constructor functions, see issue #1182.
|
||||
5
documentation/sections/changelog/1.1.2.md
Normal file
5
documentation/sections/changelog/1.1.2.md
Normal file
@@ -0,0 +1,5 @@
|
||||
```
|
||||
releaseHeader('2011-08-04', '1.1.2', '1.1.1')
|
||||
```
|
||||
|
||||
Fixes for block comment formatting, `?=` compilation, implicit calls against control structures, implicit invocation of a try/catch block, variadic arguments leaking from local scope, line numbers in syntax errors following heregexes, property access on parenthesized number literals, bound class methods and super with reserved names, a REPL overhaul, consecutive compiled semicolons, block comments in implicitly called objects, and a Chrome bug.
|
||||
11
documentation/sections/changelog/1.1.3.md
Normal file
11
documentation/sections/changelog/1.1.3.md
Normal file
@@ -0,0 +1,11 @@
|
||||
```
|
||||
releaseHeader('2011-11-08', '1.1.3', '1.1.2')
|
||||
```
|
||||
|
||||
* Ahh, whitespace. CoffeeScript’s compiled JS now tries to space things out and keep it readable, as you can see in the examples on this page.
|
||||
* You can now call `super` in class level methods in class bodies, and bound class methods now preserve their correct context.
|
||||
* JavaScript has always supported octal numbers `010 is 8`, and hexadecimal numbers `0xf is 15`, but CoffeeScript now also supports binary numbers: `0b10 is 2`.
|
||||
* The CoffeeScript module has been nested under a subdirectory to make it easier to `require` individual components separately, without having to use **npm**. For example, after adding the CoffeeScript folder to your path: `require('coffeescript/lexer')`
|
||||
* There’s a new “link” feature in Try CoffeeScript on this webpage. Use it to get a shareable permalink for your example script.
|
||||
* The `coffee --watch` feature now only works on Node.js 0.6.0 and higher, but now also works properly on Windows.
|
||||
* Lots of small bug fixes from **[@michaelficarra](https://github.com/michaelficarra)**, **[@geraldalewis](https://github.com/geraldalewis)**, **[@satyr](https://github.com/satyr)**, and **[@trevorburnham](https://github.com/trevorburnham)**.
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user