Compare commits

...

528 Commits
1.6.3 ... 1.9.2

Author SHA1 Message Date
Jeremy Ashkenas
46d16b5c49 #3942 -- revising changelog 2015-04-15 11:49:14 -04:00
Jeremy Ashkenas
d16cf19c15 Merge pull request #3942 from alubbe/master
1.9.2
2015-04-15 11:44:48 -04:00
Andreas Lubbe
edbb9a77e7 build & docs for 1.9.2 2015-04-15 17:26:30 +02:00
Andreas Lubbe
cc4c3b2606 added 1.9.2 changelog 2015-04-15 17:26:06 +02:00
Andreas Lubbe
3a2888f97a bumped version to 1.9.2 2015-04-15 17:25:49 +02:00
Jeremy Ashkenas
bd17cc9b3c Merge pull request #3892 from matthieubulte/master
Added checking on process.stdout to be compatible with browserify
2015-03-09 09:42:27 -04:00
Jeremy Ashkenas
0a3e3639dc Merge pull request #3706 from imcotton/script-data-src
Optionally to read data-src out from <script>
2015-03-09 09:41:32 -04:00
Cotton Hou
008bacf5d5 add compiled lib/browser.js 2015-03-09 15:59:10 +08:00
Cotton Hou
cc1b056b03 optionally to read data-src out from <script> 2015-03-09 15:37:09 +08:00
Matthieu Bulté
3548b4883e Added checking on process.stdout to be compatible with browserify 2015-03-09 08:30:01 +01:00
Michael Ficarra
37a376497c Merge pull request #3893 from josh/escape-literal-bracket-regexp
Escape literal ] in regexp
2015-03-08 22:18:16 -07:00
Joshua Peek
83744917b0 Escape literal ] in REGEX
] is not allowed in the PatternCharacter set
2015-03-08 21:59:09 -07:00
Jeremy Ashkenas
a548b70e8c Merge pull request #3661 from dtaniwaki/fix-deprecated-option
Use stdio option instead of customFds
2015-03-06 09:58:33 -05:00
Jeremy Ashkenas
c8147c046a Reverts #3758, Fixes #3863 -- kills the broken warning 2015-03-03 14:30:52 -05:00
Jeremy Ashkenas
4a7497b451 Merge pull request #3886 from jashkenas/revert-3885-escape-literal-bracket-regexp
Revert "Escape literal [ in regexp"
2015-02-26 16:05:25 -05:00
Jeremy Ashkenas
06aa329596 Revert "Escape literal [ in regexp" 2015-02-26 16:05:12 -05:00
Jeremy Ashkenas
9becb0e937 Merge pull request #3885 from josh/escape-literal-bracket-regexp
Escape literal [ in regexp
2015-02-26 14:49:24 -05:00
Joshua Peek
7f7765546f Escape literal [ in regexp
Improves compatibility with strict ES5 regexp syntax
2015-02-26 12:37:27 -06:00
Jeremy Ashkenas
c7a365b6f1 Merge pull request #3883 from alubbe/master
yield now behaves as expected around 'this'
2015-02-26 11:41:42 -05:00
Andreas Lubbe
84c125a71b yield now behaves as expected around 'this' - fixes https://github.com/jashkenas/coffeescript/issues/3882 2015-02-26 13:01:12 +01:00
Jeremy Ashkenas
06b74591e7 Merge pull request #3877 from gilesbowkett/ocd-test-description-details
added descriptions to tests which only had Issue numbers
2015-02-23 23:18:22 -05:00
Giles Bowkett
6645fbb895 added descriptions to tests which only had Issue numbers 2015-02-23 16:39:05 -07:00
Jeremy Ashkenas
c2758da9eb Merge pull request #3873 from Taritsyn/master
Fix getting of character at index
2015-02-23 10:36:47 -05:00
Jeremy Ashkenas
7a1c8fef0a Merge pull request #3872 from banyan/add-link-of-changelog
Update README.md and remove README
2015-02-23 10:36:01 -05:00
Andrey Taritsyn
71c59dddcc Fix getting of character at index 2015-02-22 19:08:15 +03:00
Kohei Hasegawa
ef6f90753a Delete README 2015-02-21 14:12:19 -05:00
Kohei Hasegawa
50fff63252 Add link of changelog 2015-02-21 13:59:35 -05:00
Jeremy Ashkenas
8f5c77c3ce Merge pull request #3871 from jcrben/doc_tweak
Replace references to jQuery's 'bind' with 'on'
2015-02-20 17:16:32 -05:00
Ben Creasy
88529bc339 Replace references to jQuery's 'bind' with 'on' 2015-02-20 14:02:47 -08:00
Jeremy Ashkenas
f37f9d1eda Merge pull request #3867 from sgentle/require-option
add -r/--require command line option
2015-02-19 14:06:51 -05:00
Sam Gentle
836175baab add -r/--require command line option 2015-02-20 02:58:10 +11:00
Jeremy Ashkenas
7395ac1d4f variable names 2015-02-18 15:48:45 -05:00
Jeremy Ashkenas
61988fe361 #3862 changelog 2015-02-18 15:46:14 -05:00
Jeremy Ashkenas
533ad8afe9 CoffeeScript 1.9.1 2015-02-18 15:43:33 -05:00
Jeremy Ashkenas
1961f06e08 Merge pull request #3861 from lydell/heredoc-undefined
Fix single-line heredocs starting with "undefined"
2015-02-18 14:06:09 -05:00
Simon Lydell
4503e2716e Fix single-line heredocs starting with "undefined" 2015-02-18 17:40:40 +01:00
Jeremy Ashkenas
e4d81005be Merge pull request #3854 from alubbe/fixyieldreturn
fixed yield return producing incorrect output when used outside of the last line
2015-02-17 15:47:24 -05:00
Andreas Lubbe
b6012c4617 improved yield return test 2015-02-17 19:11:06 +01:00
Andreas Lubbe
feee6954a6 fixed yield return producing incorrect output when used outside of the last line 2015-02-17 19:11:06 +01:00
Jeremy Ashkenas
fea058c53a Merge pull request #3858 from alubbe/master
fixed overly fragile repl test to work with 0.12
2015-02-17 10:49:43 -05:00
Andreas Lubbe
25d97aa136 fixed overly fragile repl test to work with 0.12, see https://github.com/jashkenas/coffeescript/issues/3855 2015-02-17 11:36:24 +01:00
Michael Ficarra
7c8849cc21 Merge pull request #3852 from alubbe/moretests
added a lot of ES6 generator tests
2015-02-15 11:46:10 -08:00
Andreas Lubbe
b362bd672c added a lot of ES6 generator tests 2015-02-15 20:35:22 +01:00
Michael Ficarra
a4f510501c Merge pull request #3853 from alubbe/fixyieldthrow
fixed being unable to use 'yield throw'
2015-02-15 10:55:17 -08:00
Andreas Lubbe
e3f6e19950 fixed being unable to use 'yield throw' 2015-02-15 19:01:00 +01:00
Jeremy Ashkenas
b49b41320e Merge pull request #3758 from DiThi/master
Prevent writing the same file several times (fixes #3753)
2015-02-12 14:27:06 -05:00
Alberto Torres Ruiz
6bc3157793 Prevent writing the same file several times (fixes #3753) 2015-02-12 20:20:35 +01:00
Jeremy Ashkenas
dc8a2b17d0 Merge pull request #3849 from lydell/regex-end-invalid-escape
Fix error message for invalid escape at end of regex
2015-02-12 13:55:10 -05:00
Jeremy Ashkenas
c3ae2328af Merge pull request #3850 from lydell/implicit-object-start-token
Fix #3846: Fix odd start token of implicit objects
2015-02-12 13:54:38 -05:00
Simon Lydell
57846ea5c0 Fix #3846: Fix odd start token of implicit objects
Now the same hack as for reserved identifier tokens in the lexer is used
instead.
2015-02-12 19:41:12 +01:00
Simon Lydell
3da88b9b3f Fix error message for invalid escape at end of regex 2015-02-12 19:26:41 +01:00
Jeremy Ashkenas
8130e63e43 Merge pull request #3802 from mapmeld/multiline_comment_fix
Allow multiline comment at end of an object definition [Fixes #3761]
2015-02-10 23:56:01 -05:00
Nick Doiron
dc44ebbdaa allow multiline comment inside of an object definition [Fixes #3761]
use more CoffeeScript syntax
2015-02-10 23:35:39 -05:00
Jeremy Ashkenas
88ad059d54 Merge pull request #3840 from lydell/dynakeys
Fix #3597: Allow interpolations in object keys
2015-02-10 10:43:26 -05:00
Simon Lydell
76c076db55 Fix #3597: Allow interpolations in object keys
The following is now allowed:

    o =
      a: 1
      b: 2
      "#{'c'}": 3
      "#{'d'}": 4
      e: 5
      "#{'f'}": 6
      g: 7

It compiles to:

    o = (
      obj = {
        a: 1,
        b: 2
      },
      obj["" + 'c'] = 3,
      obj["" + 'd'] = 4,
      obj.e = 5,
      obj["" + 'f'] = 6,
      obj.g = 7,
      obj
    );

- Closes #3039. Empty interpolations in object keys are now _supposed_ to be
  allowed.
- Closes #1131. No need to improve error messages for attempted key
  interpolation anymore.
- Implementing this required fixing the following bug: `("" + a): 1` used to
  error out on the colon, saying "unexpected colon". But really, it is the
  attempted object key that is unexpected. Now the error is on the opening
  parenthesis instead.
- However, the above fix broke some error message tests for regexes. The easiest
  way to fix this was to make a seemingly unrelated change: The error messages
  for unexpected identifiers, numbers, strings and regexes now say for example
  'unexpected string' instead of 'unexpected """some #{really long} string"""'.
  In other words, the tag _name_ is used instead of the tag _value_.
  This was way easier to implement, and is more helpful to the user. Using the
  tag value is good for operators, reserved words and the like, but not for
  tokens which can contain any text. For example, 'unexpected identifier' is
  better than 'unexpected expected' (if a variable called 'expected' was used
  erraneously).
- While writing tests for the above point I found a few minor bugs with string
  locations which have been fixed.
2015-02-09 17:32:37 +01:00
Michael Ficarra
5698e6c72a Merge pull request #3842 from arianf/master
Fixed copyright range to be updated to 2015
2015-02-08 13:56:05 -08:00
Arian Faurtosh
e0e4967ad8 Fixed copyright range to be updated to 2015 2015-02-08 11:28:51 -08:00
Michael Ficarra
53c7891599 Merge pull request #3841 from lydell/last
Replace `last array` helper with `[..., last] = array`
2015-02-08 10:22:09 -08:00
Simon Lydell
94a17cb74a Replace last array helper with [..., last] = array 2015-02-07 21:50:41 +01:00
Jeremy Ashkenas
5d139596f8 Merge pull request #3834 from lydell/better-lexer-errors
Improve lexer error messages
2015-02-06 12:17:26 -05:00
Simon Lydell
213225418a Improve lexer error messages
- Erraneous tokens are now fully underlined with ^:s.
- The error messages are now a bit more consistent.
2015-02-06 10:52:02 +01:00
Jeremy Ashkenas
3b3e52097a Merge pull request #3833 from lydell/escapes
Fix #3795: Never generate invalid strings and regexes
2015-02-05 11:32:00 -05:00
Simon Lydell
72ceec5680 Fix #3795: Never generate invalid strings and regexes
- Invalid `\x` and `\u` escapes now throw errors.
- U+2028 and U+2029 (which JavaScript treats as newline characters) are now
  escaped to `\u2028` and `\u2029`, respectively.
- Octal escapes are now forbidden not only in strings, but in regexes as well.
- `\0` escapes are now escaped if needed (so that they do not form an octal
  literal by mistake). Note that `\01` is an octal escape in a regex, while `\1`
  is a backreference. (Added a test for backreferences while at it.)
- Fixed a bug where newlines in strings weren't removed if preceded by an
  escaped character.
2015-02-05 17:23:03 +01:00
Michael Ficarra
5a220d4e13 Merge pull request #3830 from swang/fix_incorrect_token
Fix incorrect token representation
2015-02-04 21:40:45 -08:00
Shuan Wang
92e5ab2857 Fix incorrect token representation
The third element in a token should just be an object containing line
number and column info. This PR fixes the problem with one of the tokens
being set incorrectly.
2015-02-04 21:02:44 -08:00
Jeremy Ashkenas
64632e3332 Merge pull request #3827 from lydell/unexpected-regex
Improve error messages for unexpected regexes
2015-02-03 15:10:29 -05:00
Jeremy Ashkenas
c0e1f23f23 Merge pull request #3785 from lydell/super
Allow super in methods with dynamic names
2015-02-03 15:09:31 -05:00
Simon Lydell
ee8f889cbd Allow super in methods with dynamic names
As discussed in https://github.com/jashkenas/coffeescript/issues/3039#issuecomment-68916918.
This is the first step to implement dynamic object literal keys (see #3597).

This also fixes #1392.

In short, `super` is now allowed:

    # in class definitions:
    class A
      instanceMethod: -> super
      @staticMethod: -> super
      @staticMethod2 = -> super

    # in assignment where the next to last access is 'prototype':
    A::m = -> super
    A.prototype.m = -> super
    a.b()[5]::m = -> super
    A::[x()] = -> super
    class B
      @::m = -> super
2015-02-03 20:46:37 +01:00
Simon Lydell
ffa25aae77 Improve error messages for unexpected regexes 2015-02-03 20:42:50 +01:00
Jeremy Ashkenas
04b30a6cc4 Merge pull request #3786 from lydell/loop-safety
Fix #3778: Make for loops more consistent
2015-02-03 13:08:33 -05:00
Simon Lydell
996a171a4e Fix #3778: Make for loops more consistent
The following two lines might seem equivalent:

    for n in [1, 2, 3] by  a then a = 4; n
    for n in [1, 2, 3] by +a then a = 4; n

But they used not to be, because `+a` was cached into a `ref`, while the plain
`a` wasn’t. Now even simple identifiers are cached, making the two lines
equivalent as expected.
2015-02-03 19:05:07 +01:00
Jeremy Ashkenas
17a271af06 Merge pull request #3826 from lydell/string-locations
Fix #3822: Include delimiters in string/regex locations
2015-02-03 12:58:46 -05:00
Simon Lydell
f8c366c479 Fix #3822: Include delimiters in string/regex locations 2015-02-03 18:55:38 +01:00
Jeremy Ashkenas
934bd2acc7 Merge branch 'master' of github.com:jashkenas/coffeescript 2015-02-03 11:31:44 -05:00
Jeremy Ashkenas
dd0ec84ebe redoc 2015-02-03 11:31:43 -05:00
Jeremy Ashkenas
e9a372dff5 Merge pull request #3821 from lydell/no-underscore
Name generated variables without leading underscore
2015-01-30 14:56:22 -05:00
Simon Lydell
4d7a0d2470 Name generated variables without leading underscore
For example, `ref` not `_ref`. It's cleaner.

This also fixes #3816.
2015-01-30 20:33:03 +01:00
Jeremy Ashkenas
c2abe253a1 Revert "move changelog"
This reverts commit 3ddd3115eb.
2015-01-30 13:44:42 -05:00
Jeremy Ashkenas
3ddd3115eb move changelog 2015-01-30 11:43:05 -05:00
Jeremy Ashkenas
a3096eab91 #3819 changelog docs 2015-01-30 11:14:03 -05:00
Jeremy Ashkenas
3fd004b852 Fixes #3816 -- prettier internal variable names. 2015-01-29 16:24:30 -05:00
Jeremy Ashkenas
0a9c7a3257 docs 2015-01-29 14:58:49 -05:00
Jeremy Ashkenas
f7692c92ce more text tweaks 2015-01-29 12:25:25 -05:00
Jeremy Ashkenas
cdf69eb5bc Merge branch 'gh-pages' 2015-01-29 12:22:26 -05:00
Jeremy Ashkenas
9aeecf582b text tweak 2015-01-29 12:22:16 -05:00
Jeremy Ashkenas
e0ec8a51e4 CoffeeScript 1.9.0 2015-01-29 12:20:46 -05:00
Jeremy Ashkenas
a62e49311e removing the mkdirp test 2015-01-29 11:39:18 -05:00
Jeremy Ashkenas
9a38486d08 Merge pull request #3800 from ysmood/decouple_mkdirp
Decouple "mkdirp".
2015-01-29 11:38:27 -05:00
Jeremy Ashkenas
06e8be5d94 rebuilt browser just for testing 2015-01-29 11:16:01 -05:00
Yad Smood
90a1cbac49 Optimize the mkdirp test 2015-01-29 03:49:40 +08:00
Yad Smood
3d58b4cda1 Add test for mkdirp 2015-01-29 00:44:28 +08:00
Michael Ficarra
2f0724f0ad Merge pull request #3812 from xfq/patch-1
Update index.html.js
2015-01-27 20:39:47 -08:00
Xue Fuqiao
f288d20409 Update index.html.js
Node comes with npm installed and "npm" is not an abbreviation for "Node Package Manager".
2015-01-28 08:52:08 +08:00
Michael Ficarra
dca915af60 Merge pull request #3808 from lydell/api-break-fix
Fix broken CoffeeScript APIs
2015-01-26 09:43:04 -08:00
Simon Lydell
54a4560340 Fix broken CoffeeScript APIs
As evidenced in #3804, commit 8ab15d7 broke the CoffeeScript API. The REPL uses
those APIs, but wasn't updated in that commit. Still, that shouldn't have
_broken_ the REPL. The reason it broke is because the added _option_
'referencedVars' wasn't actually _optional;_ if it was omitted code that relies
on it being set broke. This commit defaults that option to an empty array, which
makes things behave exactly like before when the 'referencedVars' option is
omitted.
2015-01-26 18:21:02 +01:00
Michael Ficarra
518d7c16b7 Merge pull request #3807 from lydell/repl-fix
Fix #3804: Provide list of referenced vars to REPL
2015-01-26 08:35:38 -08:00
Simon Lydell
8ed691e266 Fix #3804: Provide list of referenced vars to REPL
Supersedes #3805. Here is a comparison of master, #3805 and this commit:

    # master
    $ bin/coffee
    coffee> 1 %% 2
    TypeError: Array.prototype.indexOf called on null or undefined

    # #3805
    $ bin/coffee
    coffee> 1 %% 2
    1
    coffee> (_results = null; i) for i in [1, 2, 3]
    TypeError: Cannot call method 'push' of null

    # this commit
    $ bin/coffee
    coffee> 1 %% 2
    1
    coffee> (_results = null; i) for i in [1, 2, 3]
    [ 1, 2, 3 ]
2015-01-26 17:18:35 +01:00
Yad Smood
74fc7128ab Decouple "mkdirp"
Make coffee completely independent.
2015-01-22 04:20:34 +08:00
Michael Ficarra
68c0e2dc0f Merge pull request #3798 from ogennadi/patch-1
Fixed broken link
2015-01-20 18:21:55 -08:00
Oge Nnadi
42dde38842 Fixed broken link 2015-01-20 12:45:27 -08:00
Michael Ficarra
7d6f6174d5 Merge pull request #3787 from lydell/single-token-interpolation
Fix #1316: Interpolate interpolations safely
2015-01-16 08:43:05 -08:00
Simon Lydell
05b3707506 Fix #1316: Interpolate interpolations safely
Instead of compiling to `"" + + (+"-");`, `"#{+}-"'` now gives an appropriate
error message:

    [stdin]:1:5: error: unexpected end of interpolation
    "#{+}-"
        ^

This is done by _always_ (instead of just sometimes) wrapping the interpolations
in parentheses in the lexer. Unnecessary parentheses won't be output anyway.

I got tired of updating the tests in test/location.coffee (which I had enough of
in #3770), which relies on implementation details (the exact amount of tokens
generated for a given string of code) to do their testing, so I refactored them
to be less fragile.
2015-01-16 17:19:42 +01:00
Michael Ficarra
5d1d1b7999 Merge pull request #3792 from lydell/issue-3194
Fix #3194: Make strings always uncallable
2015-01-15 22:34:57 -08:00
Simon Lydell
3db029f2c1 Make regexes always uncallable
No matter if they have interpolations or not.
2015-01-15 19:44:14 +01:00
Michael Ficarra
67aaa8b57f Merge pull request #3794 from lydell/jison-update
Make CoffeeScript work with jison 0.4.14+
2015-01-15 09:03:27 -08:00
Simon Lydell
28c07d30cb Make CoffeeScript work with jison 0.4.14+
Since zaach/jison commit 3548861b, `parser.lexer` is never modified anymore (a
copy of it is made, and that copy is modified instead). CoffeeScript itself
modifies `parser.lexer` and then accesses those modifications in the custom
`parser.yy.parseError` function, but that of course does not work anymore. This
commit puts the data that `parser.yy.parseError` needs directly on the `parser`
so that it is not lost.

Supersedes #3603. Fixes #3608 and zaach/jison#243.
2015-01-15 17:47:07 +01:00
Simon Lydell
fce502ac98 Fix #3194: Make strings always uncallable
No matter if they have interpolations or not.
2015-01-14 21:27:24 +01:00
Michael Ficarra
669e7fed10 Merge pull request #3791 from lydell/issue-3502
Fix #3502: Define param variables when expansion
2015-01-13 20:00:32 -08:00
Michael Ficarra
4bf45ff894 Merge pull request #3790 from lydell/scope-root
Get rid of `Scope.root` hack
2015-01-13 12:53:03 -08:00
Simon Lydell
4c2c472e07 Fix #3502: Define param variables when expansion 2015-01-13 21:26:11 +01:00
Simon Lydell
22f19522ff Get rid of Scope.root hack
Using the static property `Scope.root` for the top-level scope of a file is a
hack, which makes it impossible to have several independent `Scope` instances
at the same time (should we ever need that).

This commit makes every instance have a reference to its root instead.
2015-01-13 20:21:45 +01:00
Michael Ficarra
9fa77af576 Merge pull request #3784 from lydell/unique-generated-vars
Unique generated vars
2015-01-12 21:14:44 -08:00
Michael Ficarra
efd7ebb066 Merge pull request #3788 from lydell/unexpected-call-end
Better error message for unexpected CALL_END
2015-01-12 20:55:25 -08:00
Simon Lydell
62712060c0 Better error message for unexpected CALL_END 2015-01-12 20:40:59 +01:00
Simon Lydell
a46978640b Allow variables named like helper functions 2015-01-11 12:12:40 +01:00
Simon Lydell
8ab15d7372 Fix #1500, #1574, #3318: Name generated vars uniquely
Any variables generated by CoffeeScript are now made sure to be named to
something not present in the source code being compiled. This way you can no
longer interfere with them, either on purpose or by mistake. (#1500, #1574)

For example, `({a}, _arg) ->` now compiles correctly. (#1574)

As opposed to the somewhat complex implementations discussed in #1500, this
commit takes a very simple approach by saving all used variables names using a
single pass over the token stream. Any generated variables are then made sure
not to exist in that list.

`(@a) -> a` used to be equivalent to `(@a) -> @a`, but now throws a runtime
`ReferenceError` instead (unless `a` exists in an upper scope of course). (#3318)

`(@a) ->` used to compile to `(function(a) { this.a = a; })`. Now it compiles to
`(function(_at_a) { this.a = _at_a; })`. (But you cannot access `_at_a` either,
of course.)

Because of the above, `(@a, a) ->` is now valid; `@a` and `a` are not duplicate
parameters.

Duplicate this-parameters with a reserved word, such as `(@case, @case) ->`,
used to compile but now throws, just like regular duplicate parameters.
2015-01-10 23:25:01 +01:00
Joshua Peek
23a691ae87 Add test for reserved keywords as parameters 2015-01-10 23:23:26 +01:00
Michael Ficarra
bec8f27e8a Merge pull request #3782 from lydell/regex
Fix #3410, #3182: Allow regex to start with space or =
2015-01-10 07:52:02 -08:00
Michael Ficarra
ac2e540e1b Merge pull request #3777 from lydell/unary-plus-minus-refs
Fix #3598: Make unary + and - generate _refs
2015-01-09 18:12:52 -08:00
Michael Ficarra
e0ad0d795d Merge pull request #3783 from lydell/issue-3671
Fix #3671: Allow step in optimized range comprehensions
2015-01-09 17:54:55 -08:00
Simon Lydell
a63009fccb Fix #3671: Allow step in optimized range comprehensions
Allow the `by c` part in `for [a..b] by c then`.

Continue disallowing a `when d` part, since it makes no sense having a guard
that isn't given access to anything that changes on every iteration.
2015-01-10 02:31:56 +01:00
Simon Lydell
8fd6258a46 Fix #3410, #3182: Allow regex to start with space or =
A regex may not follow a specific set of tokens. These were already known before
in the `NOT_REGEX` and `NOT_SPACED_REGEX` arrays. (However, I've refactored them
to be more correct and to add a few missing tokens). In all other cases (except
after a spaced callable) a slash is the start of a regex, and may now start with
a space or an equals sign. It’s really that simple!

A slash after a spaced callable is the only ambigous case. We cannot know if
that's division or function application with a regex as the argument. The
spacing determines which is which:

Space on both sides:
- `a / b/i`  -> `a / b / i`
- `a /= b/i` -> `a /= b / i`

No spaces:
- `a/b/i`    -> `a / b / i`
- `a/=b/i`   -> `a /= b / i`

Space on the right side:
- `a/ b/i`   -> `a / b / i`
- `a/= b/i`  -> `a /= b / i`

Space on the left side:
- `a /b/i`   -> `a(/b/i)`
- `a /=b/i`  -> `a(/=b/i)`

The last case used to compile to `a /= b / i`, but that has been changed to be
consistent with the `/` operator. The last case really looks like a regex, so it
should be parsed as one.

Moreover, you may now also space the `/` and `/=` operators with other
whitespace characters than a space (such as tabs and non-breaking spaces) for
consistency.

Lastly, unclosed regexes are now reported as such, instead of generating some
other confusing error message.

It should perhaps also be noted that apart from escaping (such as `a /\ b/`) you
may now also use parentheses to disambiguate division and regex: `a (/ b/)`. See
https://github.com/jashkenas/coffeescript/issues/3182#issuecomment-26688427.
2015-01-10 01:48:00 +01:00
Simon Lydell
24398774fc Fix #3598: Make unary + and - generate _refs
Before commit c056c93e `Op::isComplex()` used to return true always. As far as I
understand, that commit attempts to exclude code such as `+1` and `-2` from
being marked as complex (and thus getting cached into `_ref` variables
sometimes). CoffeeScript is supposed to generate readable output so that choice
is understandable. However, it also excludes code such as `+a` (by mistake I
believe), which can cause `a` to be coerced multiple times. This commit fixes
this by only excluding unary + and - ops followed by a number.
2015-01-09 18:12:10 +01:00
Jeremy Ashkenas
e769423d52 Merge pull request #3774 from lydell/unicode-spaces
Fix #2516, #3560: Unicode space handling
2015-01-06 16:10:59 -05:00
Simon Lydell
9ec427ba80 Fix #2516, #3560: Unicode space handling
It is possible to match only valid JavaScript identifiers with a really long
regex (like coco and CoffeeScriptRedux does), but CoffeeScript uses a much
simpler one, which allows a bit too much.

Quoting jashkenas/coffeescript#1718 #issuecomment-2152464 @jashkenas:

> But it still seems very much across the "worth it" line. You'll get the
> SyntaxError as soon as it hits JS, and performance aside -- even the increase
> in filesize for our browser coffee-script.js lib seems too much, considering
> this is something no one ever does, apart from experimentation.

In short, CoffeeScript treats any non-ASCII character as part of an identifier.
However, unicode spaces should be excluded since having blank characters as part
of a _word_ is very confusing. This commit does so, while still keeping the
regex really simple.
2015-01-06 21:32:14 +01:00
Jeremy Ashkenas
c478f283f4 Merge pull request #3771 from mbrio/master
Fix issue #3498
2015-01-05 15:51:26 -05:00
Michael Diolosa
8e299b09cc Fix issue #3498 2015-01-05 15:40:04 -05:00
Michael Ficarra
b70f6571bd Merge pull request #3770 from lydell/interpolations
Refactor interpolation (and string and regex) handling in lexer
2015-01-04 12:12:56 -08:00
Simon Lydell
ae6df88c5c Point "missing )/}/]" errors to the unclosed (/{/[
Previously such errors pointed at the end of the input, which wasn't very
helpful. This is also consistent with unclosed strings, where the errors point
at the opening quote.

Note that this includes unclosed #{ (interpolations).
2015-01-04 07:51:53 +01:00
Simon Lydell
0dcff507fb Refactor interpolation (and string and regex) handling in lexer
- Fix #3394: Unclosed single-quoted strings (both regular ones and heredocs)
  used to pass through the lexer, causing a parsing error later, while
  double-quoted strings caused an error already in the lexing phase. Now both
  single and double-quoted unclosed strings error out in the lexer (which is the
  more logical option) with consistent error messages. This also fixes the last
  comment by @satyr in #3301.

- Similar to the above, unclosed heregexes also used to pass through the lexer
  and not error until in the parsing phase, which resulted in confusing error
  messages. This has been fixed, too.

- Fix #3348, by adding passing tests.

- Fix #3529: If a string starts with an interpolation, an empty string is no
  longer emitted before the interpolation (unless it is needed to coerce the
  interpolation into a string).

- Block comments cannot contain `*/`. Now the error message also shows exactly
  where the offending `*/`. This improvement might seem unrelated, but I had to
  touch that code anyway to refactor string and regex related code, and the
  change was very trivial. Moreover, it's consistent with the next two points.

- Regexes cannot start with `*`. Now the error message also shows exactly where
  the offending `*` is. (It might actually not be exatly at the start in
  heregexes.) It is a very minor improvement, but it was trivial to add.

- Octal escapes in strings are forbidden in CoffeeScript (just like in
  JavaScript strict mode). However, this used to be the case only for regular
  strings. Now they are also forbidden in heredocs. Moreover, the errors now
  point at the offending octal escape.

- Invalid regex flags are no longer allowed. This includes repeated modifiers
  and unknown ones. Moreover, invalid modifiers do not stop a heregex from
  being matched, which results in better error messages.

- Fix #3621: `///a#{1}///` compiles to `RegExp("a" + 1)`. So does
  `RegExp("a#{1}")`. Still, those two code snippets used to generate different
  tokens, which is a bit weird, but more importantly causes problems for
  coffeelint (see clutchski/coffeelint#340). This required lots of tests in
  test/location.coffee to be updated. Note that some updates to those tests are
  unrelated to this point; some have been updated to be more consistent (I
  discovered this because the refactored code happened to be seemingly more
  correct).

- Regular regex literals used to erraneously allow newlines to be escaped,
  causing invalid JavaScript output. This has been fixed.

- Heregexes may now be completely empty (`//////`), instead of erroring out with
  a confusing message.

- Fix #2388: Heredocs and heregexes used to be lexed simply, which meant that
  you couldn't nest a heredoc within a heredoc (double-quoted, that is) or a
  heregex inside a heregex.

- Fix #2321: If you used division inside interpolation and then a slash later in
  the string containing that interpolation, the division slash and the latter
  slash was erraneously matched as a regex. This has been fixed.

- Indentation inside interpolations in heredocs no longer affect how much
  indentation is removed from each line of the heredoc (which is more
  intuitive).

- Whitespace is now correctly trimmed from the start and end of strings in a few
  edge cases.

- Last but not least, the lexing of interpolated strings now seems to be more
  efficient. For a regular double-quoted string, we used to use a custom
  function to find the end of it (taking interpolations and interpolations
  within interpolations etc. into account). Then we used to re-find the
  interpolations and recursively lex their contents. In effect, the same string
  was processed twice, or even more in the case of deeper nesting of
  interpolations. Now the same string is processed just once.

- Code duplication between regular strings, heredocs, regular regexes and
  heregexes has been reduced.

- The above two points should result in more easily read code, too.
2015-01-04 07:47:09 +01:00
Jeremy Ashkenas
8e4fb1b937 Merge pull request #3748 from sscotth/master
Include logo .svg files
2014-12-03 10:20:32 -05:00
Scott
931b74e449 include logo .svg files 2014-12-02 18:33:07 -06:00
Jeremy Ashkenas
4199f4f325 Merge pull request #3734 from alubbe/master
fixed yield keyword not working in switch & for loop expressions
2014-11-21 18:38:11 -05:00
alubbe
5950d6328d added tests for yield in switch & for loop expressions 2014-11-21 23:14:53 +01:00
alubbe
a9fbf14adf fixed yield keyword not working in switch & for loop expressions 2014-11-21 22:52:09 +01:00
Jeremy Ashkenas
485aa8efcf add Die Alternative to books section 2014-11-17 13:43:41 -05:00
Jeremy Ashkenas
a563e8f8fe Merge pull request #3703 from bigtunacan/master
Add bower.json configuration
2014-10-29 17:05:25 -04:00
Joiey Seeley
4035e7caab Removed "mkdirp": "~0.3.5" from bower.json 2014-10-29 15:10:57 -05:00
Joiey Seeley
2c6e6ca870 Added an initial bower.json configuration file 2014-10-29 14:23:31 -05:00
Jeremy Ashkenas
f2a3f7507e Merge pull request #3521 from gscottolson/master
Retina favicon.ico
2014-10-27 17:18:33 -04:00
Jeremy Ashkenas
4f82e5912e Merge pull request #3677 from alubbe/master
implemented proper precedence for 'yield'
2014-10-13 11:41:36 -04:00
alubbe
dd5da7f5f2 implemented proper precedence for 'yield' 2014-10-13 03:32:02 +02:00
Anatoly Ressin
ec44aba71a Improved test readability + fixed integer divison 2014-10-12 22:32:02 +03:00
Anatoly Ressin
e8a4e93a72 Added failing test case for the yield precedence 2014-10-12 20:08:28 +03:00
dtaniwaki
1301390087 Use stdio option instead of customFds 2014-10-04 12:54:07 +09:00
Jeremy Ashkenas
158ca0d869 Merge pull request #3638 from lbeschastny/issue3638
Invalid block comments compilation
2014-09-23 14:52:03 -04:00
Jeremy Ashkenas
a78cbe78a1 Merge pull request #3240 from alubbe/master
using 'yield' automatically turns functions into generators
2014-09-19 16:38:41 -04:00
Leonid Beschastny
77d5b95260 Added test for jashkenas/coffee-script#3638 2014-09-17 15:02:18 +04:00
Leonid Beschastny
55e3b6b3c3 Fixed jashkenas/coffeescript#3638 - invalid block comments compilation 2014-09-17 15:02:10 +04:00
Andreas Lubbe
efca2861a6 added tests for yield, yield from, yield return and yield in if statements 2014-09-06 17:25:44 +02:00
Andreas Lubbe
781ea22d57 always wrap 'yield' in () to allow composability with all other operators 2014-09-06 17:12:25 +02:00
Andreas Lubbe
437b9ed65c added 'yield return' 2014-09-06 15:40:53 +02:00
Andreas Lubbe
c72556619f added 'yield from' 2014-09-06 13:53:21 +02:00
Andreas Lubbe
565d78f00b removed support for '->*" and '=>*' 2014-09-06 13:38:04 +02:00
Andreas Lubbe
75900660fd Merge remote-tracking branch 'A/master' 2014-09-06 11:32:25 +02:00
Michael Ficarra
b407a59baf Merge pull request #3618 from josh/update-site-example-projects
Refresh site Examples section
2014-08-28 00:40:35 -04:00
Joshua Peek
9dfd71b0e4 Add Atom to Examples 2014-08-27 21:24:42 -07:00
Joshua Peek
872092f6de Remove josh/nack from Examples 2014-08-27 21:21:25 -07:00
Michael Ficarra
8b066f125d Merge pull request #3616 from epmatsw/spelling
Quick spelling fixes
2014-08-26 19:46:34 -07:00
Will Stamper
94c467b520 Quick spelling fixes 2014-08-26 20:41:32 -05:00
Jeremy Ashkenas
53aa50f785 merged 2014-08-26 12:28:39 -04:00
Jeremy Ashkenas
81047d45ee CoffeeScript 1.8.0 2014-08-26 12:24:29 -04:00
Jeremy Ashkenas
9177676979 Merge pull request #3611 from lydell/release-1.8.0
Release 1.8.0
2014-08-26 12:20:18 -04:00
Simon Lydell
7cfba37f7c Update changelog for 1.8.0 2014-08-25 19:39:27 +02:00
Simon Lydell
ee8d105194 Rebuild docs 2014-08-23 16:08:39 +02:00
Michael Ficarra
6929441cb7 Merge pull request #3592 from mmotorny/master
Exit with an error code 1 if could not write a compiled JavaScript file ...
2014-08-17 22:07:07 -07:00
Maksym Motornyy
b5734028d9 Exit with an error code 1 if could not write a compiled JavaScript file or a source map
Currently CoffeeScript reports a success even if it failed to write a
compiled file to disk. This behavior confuses automated tools such as
test runners which may return false positives if a test failed to
compile because of a file lock.
2014-08-17 20:42:30 -07:00
Michael Ficarra
ab6f69c741 Merge pull request #3561 from yjo/js-map-file-ext
Use '.js.map' as file extension for created map files
2014-07-29 10:52:59 -07:00
Joe Lee-Moyet
2ec6e7e944 Use '.js.map' as file extension for created map files
Addresses jashkenas/coffeescript#3297
2014-07-29 17:28:08 +01:00
Nami-Doc
e8c96de269 Fix the "Examples" link on coffeescript.org
It now points to the "Trending repositories" of the month.
2014-07-23 22:21:14 +02:00
Nami-Doc
fbbda3f85f Fix the "Examples" link on coffeescript.org
It now points to the "Trending repositories" of the month.
2014-07-23 22:17:00 +02:00
Michael Ficarra
f96ab11feb Merge pull request #3545 from jordanbtucker/patch-1
`bin/cake` will be in `coffeescript`
2014-07-17 16:23:47 -07:00
jordanbtucker
5c1daf966a bin/cake will be in coffeescript
Since the name change, `bin/cake` will be in `coffeescript`, not `coffee-script`.
2014-07-17 15:04:40 -07:00
Michael Ficarra
df8529fbfb Merge pull request #3543 from ysmood/err_info_issue
Fixed an error formatting issue
2014-07-16 07:36:48 -07:00
Yad Smood
3465e7554d Fixed an error formatting issue f7b36054fc
When using tab for code indent, the error marker
will be wrongly positioned.
2014-07-16 17:56:07 +08:00
Yad Smood
f7b36054fc Add a test case for compiler error formatting.
Error formatting with mixed tab and space.
2014-07-16 17:50:15 +08:00
Michael Ficarra
3ec10df4a1 Merge pull request #3539 from minodisk/fix-heregex-interpolation
Fix wrong location issue in heregex interpolation
2014-07-13 21:10:03 -07:00
minodisk
deead4bfad Fix wrong location issue in heregex interpolation 2014-07-13 16:39:41 +09:00
Michael Ficarra
302aa6a457 Merge pull request #3533 from minodisk/fix-string-interpolation
Fix wrong location issue in "string" interpolation
2014-07-02 21:49:24 -07:00
minodisk
5920939e23 Fix wrong location issue in "string" interpolation 2014-07-03 13:11:20 +09:00
Michael Ficarra
2bab1b6aa1 Merge pull request #3524 from minodisk/master
Fix location data bug for string interpolations
2014-07-01 07:35:57 -07:00
minodisk
2b539ebea8 Fix wrong location issue in string interpolation starting with line break 2014-07-01 11:28:21 +09:00
dabbler0
159d562230 Fix off-by-one issue with string interpolation in lexer 2014-07-01 10:55:17 +09:00
Nami-Doc
eb030a2c73 Update link to "CoffeeScript Ristretto", fixes #3489 2014-06-26 17:10:11 +02:00
Nami-Doc
1157b32413 Update link to "CoffeeScript Ristretto", fixes #3489 2014-06-26 17:08:31 +02:00
G. Scott Olson
ba4157b5e2 Retina favicon.ico 2014-06-23 11:11:54 -04:00
Michael Ficarra
5a54d8ba6d Merge pull request #3509 from aviflax/patch-1
Remove sudo from install command in introduction
2014-06-09 08:21:27 -07:00
Avi Flax
f619416492 Remove typo
No idea how that got in there.
2014-06-06 13:46:41 -04:00
Avi Flax
2dd1ec3314 Remove sudo from install command in introduction
1. It just seems like a bad practice to encourage people to run npm with `sudo`
2. The doc wasn’t consistent with itself — down below in the full “Installation” section the same command did *not* include `sudo`
2014-06-06 09:26:18 -04:00
Michael Ficarra
4ad625a265 Merge pull request #3508 from bwin/patch-1
remove docco as dependency (still a devDependency)
2014-06-05 21:51:26 -07:00
Benjamin Winkler
df2b79fa56 remove docco as dependency (still a devDependency)
also changed version requirement notation for from `n.n.x` to `~n.n.n` like the others
2014-06-06 04:33:19 +02:00
Michael Ficarra
c4f9c3abf5 Merge pull request #3503 from datenreisender/handle-dotless-commands
Handle dotless commands in the REPL.
2014-06-03 23:22:15 -07:00
Marko Schulz
9410216b02 Make getCommandId() more readable. 2014-06-03 22:50:25 +02:00
Marko Schulz
233055a7ab Implement changes recommended in the pull request. 2014-06-03 11:29:03 +02:00
Marko Schulz
edf3c12fcc Handle dotless commands in the REPL.
Node 0.11 switched to storing the REPL commands dotless internally.
This fixes the problem brought up in #3450.
2014-06-02 13:24:57 +02:00
Michael Ficarra
1bb3c843e1 Merge pull request #3450 from ehuss/node11repl
Fix repl for Node 0.11.12.
2014-05-28 07:56:15 -07:00
Nami-Doc
48f2c2d0d2 Merge pull request #3494 from ELLIOTTCABLE/patch-1
Fix “list of open-source CoffeeScript on GitHub”
2014-05-24 10:57:17 +02:00
ELLIOTTCABLE
7e01672479 Fix “list of open-source CoffeeScript on GitHub”
Link's been broken with the recent GitHub re-arrangement. This is the closest thing I could find to what that link used to lead to.
2014-05-24 01:22:27 -05:00
Michael Ficarra
ddc023b28b Merge pull request #3492 from forty/master
Do not rely on properties order in scope tests
2014-05-21 07:49:39 -07:00
Quentin Barbe
c65f584112 Do not rely on properties order in scope tests 2014-05-21 16:40:44 +02:00
Jeremy Ashkenas
70a9a341ac Merge pull request #3491 from forty/master
Add tests to check that the FOR variable is defined after the loop
2014-05-20 17:48:26 -04:00
forty
c608901d5a Add tests to check that the FOR variable is defined after the loop 2014-05-20 23:37:33 +02:00
Jeremy Ashkenas
a5a1ea9157 Merge pull request #3477 from davidchambers/deprecate-join
command: deprecate --join
2014-05-12 10:59:17 -04:00
David Chambers
1cd48a9f5d command: deprecate --join 2014-05-11 22:41:39 -07:00
Jeremy Ashkenas
d8b7a55eb9 Merge pull request #3448 from leedm777/export-repl
Export the CoffeeScript REPL.
2014-05-08 16:08:45 -04:00
Jeremy Ashkenas
6ae21ae461 merged 2014-05-08 15:09:40 -04:00
Jeremy Ashkenas
f0764096e9 now that github supports renames, coffeescript, not coffee-script 2014-05-08 15:07:42 -04:00
Michael Ficarra
ade9620351 Merge pull request #3460 from datenreisender/correct-repl-help
Fix help for .load
2014-05-01 07:48:58 -07:00
Marko Schulz
3fdc3a4758 Fix help for .load 2014-05-01 14:54:43 +02:00
Eric Huss
03705c674f Fix repl for Node 0.11.12.
Node changed their repl so that it inherits from readline.Interface.
This means that `prompt` is now the rli function and not the original
prompt string.  This may be a little hacky, but I figure it would give
someone a start if they want to do a better fix.

The commit that changed this in Node is joyent/node@3ae0b17c76

This bug was mentioned in Issue #3395.
2014-04-19 01:18:21 -07:00
David M. Lee
576fe44ef8 Export the CoffeeScript REPL.
This is done by adding a root level wrapper script for
lib/coffee-script/repl, similar to how the register script is wrapped.
This allows user programs to embed a CoffeeScript REPL without digging
into CoffeeScript's internals.
2014-04-18 08:26:51 -05:00
Michael Ficarra
e02c8abb1a Merge pull request #3425 from charlierudolph/compile_errors
Display compile errors - rebase from @jeremybanks
2014-03-18 08:11:29 -05:00
Michael Ficarra
2723f1afe9 Merge pull request #3424 from charlierudolph/fix_index
Fix errors on index
2014-03-17 21:57:38 -05:00
Jeremy Banks
6114751d21 Display compile errors - rebase from @jeremybanks 2014-03-17 17:09:05 -07:00
charlierudolph
15b64addbf Fix errors on index
Extra quotations resulted in subtracting two strings and then a
javascript syntax error
2014-03-17 16:15:31 -07:00
Nami-Doc
4547612e50 Merge pull request #3418 from fcolas6013/patch-2
fix spell mistake on index.html.js
2014-03-15 22:24:54 +01:00
Fabrice Colas
9c15b13a96 fix spell mistake on index.html.js 2014-03-15 14:23:46 -07:00
Jeremy Ashkenas
63acf6a5ff Merge pull request #3355 from aroben/kill-isUndefined
Remove reference to never-defined .isUndefined property
2014-03-15 16:37:59 -04:00
Jeremy Ashkenas
3339c2f228 Merge pull request #3415 from matt-hickford/patch-1
Package with preferGlobal as appropriate for command-line application
2014-03-14 23:36:28 -04:00
Matt Hickford
c2db81d892 Package with preferGlobal as appropriate for command-line application
Per https://www.npmjs.org/doc/json.html#preferGlobal

> If your package is primarily a command-line application that should be installed globally, then set this value to true to provide a warning if it is installed locally.
>
> It doesn't actually prevent users from installing it locally, but it does help prevent some confusion if it doesn't work as expected.
2014-03-15 00:44:38 +00:00
Nami-Doc
8b15d8218d Merge pull request #3401 from sailxjx/master
fix a spell mistake in cakefile
2014-03-11 09:09:00 +01:00
sailxjx
bfc9d4d594 fix a spell mistake in cakefile 2014-03-11 15:11:02 +08:00
Michael Ficarra
ab5728c030 fix cake install; related: #3395, #3393 2014-03-03 13:24:20 -06:00
Michael Ficarra
dcf1556ffc Update README.md 2014-02-28 13:18:54 -06:00
Jeremy Ashkenas
53c53bd3e6 Update README.md 2014-02-28 07:59:24 -05:00
Jeremy Ashkenas
c2e1ab589c Delete README 2014-02-28 07:58:14 -05:00
Jeremy Ashkenas
75207a08ad Merge pull request #3393 from christianbundy/markdown-readme
Convert README to Markdown
2014-02-28 07:57:41 -05:00
Christian Bundy
a2dbfdc2f4 Convert README to Markdown 2014-02-27 22:19:04 -08:00
Michael Ficarra
0a82ac7d69 remove editorialisation 2014-02-22 23:20:06 -06:00
Michael Ficarra
a489006afb typo: mult-dot => multi-dot 2014-02-22 23:20:06 -06:00
Michael Ficarra
af08cfd37f add newlines to end of files 2014-02-22 23:20:06 -06:00
Michael Ficarra
9dc3a3df13 Merge pull request #3386 from blmarket/deprecate_warning
Fixes issue #3349, prints deprecation warning
2014-02-22 22:33:25 -06:00
Jeong, Heon
a82aecc008 Improved coding convention and messages. 2014-02-23 13:03:42 +09:00
Jeong, Heon
36a3e03048 Fixes issue #3349, prints deprecation warning
This patch fixes issue #3349, by prints deprecation warning for
users who depends on old(<1.7.0) implicit module registration.
2014-02-23 11:48:16 +09:00
Jeremy Ashkenas
fc8e9fd92a Merge pull request #3382 from davidchambers/time-elements
changelog: use time elements for release dates
2014-02-18 12:18:45 -05:00
David Chambers
c9e87f3044 changelog: use time elements for release dates 2014-02-18 08:49:46 -08:00
Michael Ficarra
bb319e2add Merge pull request #3381 from davidchambers/inline-css
changelog: replace inline CSS
2014-02-18 08:08:03 -06:00
David Chambers
81e2253a55 changelog: replace inline CSS 2014-02-17 21:45:49 -08:00
Michael Ficarra
c41a14f447 Merge pull request #3380 from madprgmr/master
Rudimentary fix for jashkenas/coffee-script#3379.
2014-02-17 17:56:36 -06:00
Sean Hussey
a323160d14 Rudimentary fix for jashkenas/coffee-script#3379. 2014-02-17 18:37:10 -05:00
Jeremy Ashkenas
a216f93b54 Merge pull request #3376 from davidchambers/anchors
change log improvements
2014-02-17 14:14:13 -05:00
David Chambers
551cf56ceb changelog: add missing compare view URLs 2014-02-16 18:09:17 -08:00
David Chambers
09446ad515 changelog: add anchor to each section
Add releaseHeader helper to avoid repetition.
2014-02-16 18:08:35 -08:00
Michael Ficarra
b31951980e Merge pull request #3368 from ricardobeat/cake-register-by-default
Cakefile: register .coffee extension by default
2014-02-09 22:19:41 -06:00
Ricardo Tomasi
e7ba29514d Register .coffee extension by default on Cakefile 2014-02-10 01:16:14 -02:00
Michael Ficarra
a2c0106b3f fixes #3363: modulo operator evaluation order 2014-02-08 20:56:34 -06:00
Michael Ficarra
4dfc75dede Merge pull request #3362 from epidemian/fix-modulo-coercion
Fix #3361, make %% coerce right operand only once
2014-02-08 10:38:58 -06:00
Demian Ferreiro
0ad30e9b3f Fix #3361, make %% coerce right operand only once
Force coercion of right operand once before doing arithmetic with it in the `__modulo` utility function.
2014-02-08 13:24:39 -03:00
Jeremy Ashkenas
46f55d1bb4 Merge pull request #3360 from lydell/install-docs
Improve installation documentation
2014-02-07 10:53:51 -05:00
Simon Lydell
27f1976159 Improve installation documentation
- Simplify the command to install latest master.

- Promote using `--save` when installing locally, since it automatically
  locks the minor version, protecting users from accidentally installing
  breaking updates.
2014-02-07 16:30:52 +01:00
Michael Ficarra
816241d9a1 Merge pull request #3359 from lydell/v8-consistent-stacktraces
Make patched stack traces’ prelude consistent with V8
2014-02-07 09:00:45 -06:00
Simon Lydell
4bbd63c883 Make patched stack traces’ prelude consistent with V8
In V8, the `stack` property of errors contains a prelude and then the
stack trace. The contents of the prelude depends on whether the error
has a message or not.

If the error has _not_ got a message, the prelude contains the name of the
error and a newline.

If the error _has_ got a message, the prelude contains the name of the
error, a colon, a space, the message and a newline.

In other words, the prelude consists of `error.toString() + "\n"`

Before, coffee-script’s patched stack traces worked exactly like that,
except that it _always_ added a colon and a space after the name of the
error.

This fix is important because it allows for easy and consistent
consumption of the stack trace only:

`stack = error.stack[error.toString().length..]`
2014-02-07 13:01:01 +01:00
Adam Roben
e9a0512663 Remove reference to never-defined .isUndefined property
This was added in f4a7cca075 to fix #1038
for CoffeeScript 1.0.1. `.isUndefined` was removed in
caf3da2f66 but this code was never
updated. That actually caused the behavior of this code to change
(trailing `undefined` and `return undefined` statements no longer got
optimized away) when CoffeeScript 1.3.2 was released, but the new
behavior was deemed correct in
https://github.com/jashkenas/coffee-script/issues/1038#issuecomment-14427560.
2014-02-06 09:23:16 -05:00
Adam Roben
8980647f32 Add tests for the optimization of trailing return statements
This documents current behavior. When #1038 was fixed, we also optimized
away trailing "undefined" and "return undefined", but that is no longer
the case.
2014-02-06 09:21:35 -05:00
Michael Ficarra
eda4f0c55b Merge remote-tracking branch 'origin/gh-pages' 2014-02-01 21:07:10 -06:00
Michael Ficarra
ed928928f6 use npm-installed docco rather than relying on globally installed docco 2014-02-01 21:06:21 -06:00
Michael Ficarra
5f28319cb1 update "latest version" documentation link to 1.7.1 2014-01-29 23:24:06 -06:00
Michael Ficarra
6b0ee127da recompile documentation with 1.7.1 2014-01-29 23:21:44 -06:00
Michael Ficarra
5e31672793 Merge branch 'master' into gh-pages 2014-01-29 23:21:00 -06:00
Michael Ficarra
4ab8503e5a CoffeeScript 1.7.1 2014-01-29 23:19:36 -06:00
Michael Ficarra
cc4cc8e652 update changelog for 1.7.1 2014-01-29 23:07:27 -06:00
Michael Ficarra
52b89d5b03 rebuild annotated source documentation 2014-01-29 22:54:00 -06:00
Michael Ficarra
094a0cbe95 add docco as npm dependency so it doesn't have to be installed globally 2014-01-29 22:52:49 -06:00
Michael Ficarra
f8eca2e822 Merge branch 'master' into gh-pages 2014-01-29 22:51:23 -06:00
Jeremy Ashkenas
114eccb459 Merge pull request #3340 from benbria/master
Fix a typo causing module.paths to be always set as the cwd.
2014-01-29 10:29:55 -08:00
Geoffry Song
38bd879a9a Fix a typo causing module.paths to be always set as the cwd.
`options.fileName` was used instead of `options.filename`.
2014-01-29 13:23:19 -05:00
Jeremy Ashkenas
a73a6e24a6 Merge pull request #3337 from roryokane/fix-operator-docs-commas
In docs, move commas out of code
2014-01-28 18:45:17 -08:00
Rory O’Kane
b4d35f13a4 In docs, move commas, part 2
I had missed that the next line had comma-separated operators, too.
2014-01-28 21:09:08 -05:00
Rory O’Kane
3fcaebb007 In docs, move commas out of code
The commas separating these three keywords are not code themselves – not what the user would write – so they should be outside of the `<tt>` tags.

Edits the table in the section [Operators and Aliases](http://coffeescript.org/#operators).
2014-01-28 21:01:22 -05:00
Jeremy Ashkenas
3357b6cf2c index.html 2014-01-28 20:49:26 -05:00
Rory O’Kane
6df8d92499 Fix markup in math operator documentation
In the documentation, surround the new operators with `<tt>` tags instead of Markdown-style backticks, since this is HTML.
2014-01-28 20:49:20 -05:00
Jeremy Ashkenas
e543eb5101 index.html 2014-01-28 20:49:09 -05:00
Jeremy Ashkenas
7c4f842501 Merge pull request #3336 from roryokane/fix-math-operator-docs-markup
Fix markup in math operator documentation
2014-01-28 17:47:32 -08:00
Rory O’Kane
a5fef52751 Fix markup in math operator documentation
In the documentation, surround the new operators with `<tt>` tags instead of Markdown-style backticks, since this is HTML.
2014-01-28 18:56:43 -05:00
dannguyen
ef7b3a75e0 Just a small typo in 1.7.0 changelog 2014-01-28 16:47:42 -05:00
Jeremy Ashkenas
734fcedc06 Merge pull request #3334 from dannguyen/patch-1
Just a small typo in 1.7.0 changelog
2014-01-28 13:46:39 -08:00
dannguyen
e4c8bcf8f6 Just a small typo in 1.7.0 changelog 2014-01-28 16:36:04 -05:00
Jeremy Ashkenas
a3ae0c5c75 CoffeeScript 1.7.0 2014-01-28 14:05:38 -05:00
Jeremy Ashkenas
46895419b3 Merge pull request #3333 from xixixao/release1.7.0
Implement #3332
2014-01-28 10:59:22 -08:00
xixixao
4f6a4bab30 Removed idle styles 2014-01-28 18:57:37 +00:00
xixixao
9e5ffaea69 Use actual _.template instead of custom one 2014-01-28 18:56:43 +00:00
xixixao
928d2d7f4a Extras compiled with 1.7.0 2014-01-28 03:35:09 +00:00
xixixao
10293df1f9 Recompile source with 1.7.0 version 2014-01-28 03:34:00 +00:00
xixixao
41c4c822ba Recompile documentation js files with 1.7.0 version 2014-01-28 03:33:03 +00:00
xixixao
6030ac3a23 Fixes in documentation 2014-01-28 03:30:06 +00:00
xixixao
f42329ca0a Use Node instead of Ruby for documentation 2014-01-28 03:17:12 +00:00
Jeremy Ashkenas
570529f526 Fixing tests for browser. 2014-01-27 11:55:20 -05:00
Jeremy Ashkenas
8b8436d794 Merge pull request #3326 from xixixao/release1.7.0
Prepare 1.7.0 release
2014-01-27 08:42:58 -08:00
Jeremy Ashkenas
b0594aad3e Merge pull request #3331 from xixixao/inlineobjectchain
Fixes chaining after inline implicit objects
2014-01-26 14:15:09 -08:00
xixixao
04b0b94a8c Fixes chaining after inline implicit objects 2014-01-26 22:11:10 +00:00
xixixao
e1f46cfb9b Prepare 1.7.0 release 2014-01-26 18:32:12 +00:00
Michael Ficarra
cc1b74f11b Merge pull request #3329 from xixixao/issue3325
Fixes #3325: implicit indendation error messages
2014-01-25 22:00:24 -08:00
xixixao
104b4666fe Fix indendation error messages 2014-01-26 05:25:13 +00:00
Michael Ficarra
835fc84330 Merge pull request #3328 from xixixao/issue3216
Fixes #3216 for declarations in object literals
2014-01-25 21:05:34 -08:00
Michael Ficarra
a5d6285cfd forgotten compilation from parent commit 2014-01-25 22:54:25 -06:00
xixixao
c2727d964c Fix for declarations in object literals 2014-01-26 04:41:30 +00:00
Andreas Lubbe
f375394381 Merge https://github.com/jashkenas/coffee-script
Conflicts:
	lib/coffee-script/lexer.js
	lib/coffee-script/parser.js
	lib/coffee-script/rewriter.js
	src/lexer.coffee
	src/rewriter.coffee
2014-01-25 19:37:35 -08:00
Michael Ficarra
d687d52f9e Merge pull request #2887 from epidemian/more-math-operators
Add new mathematical operators
2014-01-24 13:18:29 -08:00
Demian Ferreiro
6a43de789f Simplify modulo tests 2014-01-24 17:55:50 -03:00
Demian Ferreiro
1288786fdc Make modulo operator convert arguments to numbers 2014-01-24 16:08:39 -03:00
Demian Ferreiro
2b4421fca1 Merge branch 'master' into more-math-operators
Conflicts:
	lib/coffee-script/grammar.js
	lib/coffee-script/lexer.js
	lib/coffee-script/nodes.js
	lib/coffee-script/parser.js
	test/regexps.coffee
2014-01-24 15:40:28 -03:00
Jeremy Ashkenas
6bdd52733e Merge pull request #3327 from xixixao/forexpansion
Fix expansion in destructuring inside comprehensions
2014-01-24 10:24:51 -08:00
xixixao
bd6b4142fe Fix expansion in destructuring inside comprehensions 2014-01-24 18:20:45 +00:00
Jeremy Ashkenas
daa6ad5470 Merge pull request #3268 from xixixao/issue156
Implement #156, Added expansion to destructuring
2014-01-24 08:33:42 -08:00
xixixao
369e0545c0 Added expansion to destructuring 2014-01-24 16:00:34 +00:00
Michael Ficarra
5f31a3d60e Merge pull request #3324 from xixixao/issue1871
Fixes #1871, close implicit objects in implicit returns
2014-01-23 15:24:10 -08:00
xixixao
8b976acac1 Fixes #1871, close implicit objects in implicit returns 2014-01-23 23:12:12 +00:00
Jeremy Ashkenas
b00962db1a Merge pull request #3322 from xixixao/issue1099
Fix #1099, remove in empty array optimization
2014-01-23 07:16:00 -08:00
xixixao
26dcf025f4 Remove in empty array optimization 2014-01-23 15:09:25 +00:00
Jeremy Ashkenas
d2f90d2236 Merge pull request #3320 from xixixao/issue1275
Fix #1275
2014-01-22 10:54:18 -08:00
xixixao
c3391e1dd8 Fix 1275 2014-01-22 18:33:44 +00:00
Jeremy Ashkenas
b3463a1378 Merge pull request #3319 from xixixao/issue1096
Fix 1096, 1131, 1828: Improve error messages for generated tokens
2014-01-22 05:29:03 -08:00
xixixao
f0463e9981 Improve error messages for generated tokens 2014-01-22 02:54:09 +00:00
Jeremy Ashkenas
1cc583b382 Merge pull request #3317 from xixixao/chainafteroutdent
Chaining semantics after arguments with outdent
2014-01-21 14:27:32 -08:00
xixixao
39cb8815f7 Fixed chaining semantics after outdent 2014-01-21 22:00:57 +00:00
Michael Ficarra
21db08a23d add missing implicit object literal test
ref michaelficarra/CoffeeScriptRedux#266 and 670a1f5f78 (diff-2)
2014-01-12 11:16:27 -06:00
Michael Ficarra
1f301d8c07 Merge pull request #3292 from marchaefner/CLI
`coffee DIR` executes `DIR/index.coffee`
2013-12-29 14:24:02 -08:00
Andreas Lubbe
1e377ed59b 'yield*' now works as expected 2013-12-27 22:12:04 -08:00
Andreas Lubbe
64e78a2bec updated lexer to allow 'yield*' 2013-12-26 01:16:02 -08:00
Jeremy Ashkenas
35f185440f Merge pull request #3293 from marchaefner/master
Fix `child_process.fork` patch
2013-12-23 22:19:55 -08:00
Michael Ficarra
5ce0c84907 Merge pull request #3284 from xixixao/issue3056
Fix multiple postfix conditionals
2013-12-23 22:08:34 -08:00
Andreas Lubbe
25b1eee293 first attempt at including 'yield*' 2013-12-23 19:32:25 -08:00
Marc Häfner
a6891e4feb Fix child_process.fork patch
* Preserve `options` when called without `args`
  * Don't use `coffee` script as `execPath` (Fixes #2919)
2013-12-24 02:05:53 +01:00
Marc Häfner
8a3ebb9181 CLI: Run index.coffee when called on a directory 2013-12-24 01:53:27 +01:00
Andreas Lubbe
dab4ae9416 '->*' and '=>*' now produce generators 2013-12-19 18:08:25 -08:00
Andreas Lubbe
56b04a58dc first attempt at using '->*" and '=>*' for generators 2013-12-19 14:21:14 -08:00
Michael Ficarra
308299fe04 Merge pull request #3285 from xixixao/formatutils
Format utilities using single quoted literals
2013-12-16 20:08:05 -08:00
xixixao
1cc8463b9c Formatted utilities using single quoted literals 2013-12-17 03:36:49 +01:00
xixixao
d7862647d9 Fix multiple postfix conditionals 2013-12-17 03:31:19 +01:00
Nami-Doc
6c786f0fb7 Merge pull request #3283 from Fritz-Lium/patch-1
the page lists only top 100 contributors
2013-12-14 03:31:43 -08:00
Fritz-Lium
cc345def46 the page list only top 100 contributors 2013-12-14 19:31:04 +08:00
Michael Ficarra
818983b6a4 Merge pull request #3280 from xixixao/issue3271
Examples: Back to non-naked constructor, @, preincrement, comprehension bracketing...
2013-12-09 14:31:23 -08:00
xixixao
b859d92d2c Back to non-naked constructor, @, preincrement, comprehension bracketing, idioms: calls, comprehensions, interpolations 2013-12-09 22:28:34 +00:00
Jeremy Ashkenas
8cd9ba168d Merge pull request #3279 from michaelficarra/fix-require.extensions-registration
fix require.extensions registration
2013-12-08 13:26:15 -08:00
Michael Ficarra
08a57898a7 add CoffeeScript.register method for require.extensions registration 2013-12-08 14:21:18 -06:00
Michael Ficarra
ba4743cc83 fix auto and manual require.extensions registration; ref #3141
You can now `require('coffee-script/register')` to manually register,
and the compiler auto-registers when directly running a coffee file.
2013-12-08 14:19:10 -06:00
Jeremy Ashkenas
94e22ab819 Merge pull request #3275 from marchaefner/CLI
Fix --watch handling of deleted sources
2013-12-07 22:28:19 -08:00
Michael Ficarra
c1b46f777f Merge pull request #3277 from boundvariable/master
Add CoffeeScript in Action book link
2013-12-06 08:04:46 -08:00
Patrick Lee
81cf9ca00f Add CoffeeScript in Action book link 2013-12-07 00:58:43 +11:00
Nami-Doc
96f087ca6b Merge pull request #3276 from xixixao/issue1495fixup
Fixup #3263: Prevent loop collection in endAllImplicitCalls
2013-12-05 13:55:38 -08:00
xixixao
bc975e556e Prevent loop collection in endAllImplicitCalls 2013-12-05 21:53:42 +00:00
Andreas Lubbe
e1000205fd Merge github.com:jashkenas/coffee-script 2013-12-05 11:56:34 -08:00
Andreas Lubbe
c02a403f2e fixed misspelling in Cakefile 2013-12-04 21:49:17 -08:00
Marc Häfner
6804c1065b Fix: EPERM when deleting watched dirs in Windows
* Suppress `EPERM` from watchers
  * Suppress `EPERM` from `fs.unlink`
2013-12-04 17:12:24 +01:00
Marc Häfner
74cf54a84f Prettify watch 2013-12-04 14:50:36 +01:00
Andreas Lubbe
f4b850d59c further improved readability of cakefile generator check 2013-12-02 23:33:16 -08:00
Marc Häfner
73af30b5d8 Fixes #3267 -- Remove source maps of deleted source files 2013-12-01 12:03:22 +01:00
Marc Häfner
54633aee3f Remove unnecessary parameter 2013-12-01 11:35:03 +01:00
Andreas Lubbe
85c7fffd1a improved readability of cakefile generator check 2013-11-30 20:51:53 -08:00
Andreas Lubbe
9d29a830df entire generator test file is now ignored if generators are not available 2013-11-30 12:26:32 -08:00
Andreas Lubbe
74a92db173 improved readability of generator test 2013-11-30 11:45:19 -08:00
Andreas Lubbe
d712a6c0f4 npm run-script test-harmony executes generator tests 2013-11-29 20:59:22 -08:00
Andreas Lubbe
7906a2b6c1 removed yield from the reserved words 2013-11-29 20:58:43 -08:00
Andreas Lubbe
f11ca9888f added a test for generators 2013-11-29 20:58:26 -08:00
Marc Häfner
26200f4640 Improve HEREDOC regexp
* Exclude trailing blank line from the match group
  * Fix backslash handling
2013-11-28 16:46:00 +01:00
Marc Häfner
13f205404c Merge pull request #3261 from xixixao/issue1273
Fix #1273, Handle backslashes at the end of heredocs
2013-11-28 07:32:20 -08:00
Jeremy Ashkenas
563f14b178 Merge pull request #3263 from xixixao/issue1495
Implement #1495,  Method call chaining
2013-11-27 22:58:46 -08:00
xixixao
5e4cca90a3 Fix #3264, missing leading whitespace before interpolation in heredoc 2013-11-27 20:53:20 +00:00
xixixao
a61b6ee925 Fixed leading whitespace before interpolation in simple strings 2013-11-27 20:29:45 +00:00
xixixao
b11d956d53 Added compilation regression test 2013-11-27 12:58:14 +00:00
xixixao
ee9febe399 Handle nested calls and function oneliners when chaining 2013-11-27 04:57:44 +00:00
xixixao
15a70f863c Implemented method call chaining 2013-11-27 03:41:52 +00:00
Michael Ficarra
4eee9c318e Merge pull request #3262 from xixixao/issue1766
Fix #1766, Add negative slice end index into docs
2013-11-26 19:10:46 -08:00
xixixao
ac6a76ee10 Add negative slice end index into docs 2013-11-27 01:01:32 +00:00
xixixao
42aa8d256c Handle backslashes at the end of heredocs 2013-11-26 19:29:13 +00:00
Marc Häfner
873ed071d4 Fixes #3259 -- Use placeholders when adding params to scope
Don't register nested variables of complex parameters as parameters of the compiled function. Use the computed placeholder name instead.
2013-11-26 14:23:20 +01:00
Jeremy Ashkenas
210376f7a9 Merge pull request #3256 from xixixao/issue3249
Implements #3249, #1994 Escape newlines in heredocs with backslashes
2013-11-24 10:54:53 -08:00
xixixao
35d327a304 Escape newlines in heredocs with backslashes 2013-11-24 18:37:11 +00:00
Jeremy Ashkenas
e3e8b1c501 Merge pull request #3255 from marchaefner/CLI
CLI fixes and refactoring
2013-11-23 18:31:27 -08:00
Marc Häfner
52a54a7681 Fix and simplify management of sources in CLI
* Move all source path filtering to `compilePath`
  * Restrict modification of `sources` to
    * `compilePath` for adding
    * `removeSource` for removing
  * Don't add unfiltered paths to `sources` (and remove them later on)
2013-11-23 07:54:35 +01:00
Marc Häfner
1fe28c1fc9 Simplify and rename unwatchDir (to removeSourceDir) 2013-11-23 06:55:57 +01:00
Marc Häfner
89efd05a3f Make timeout callback in watchDir synchronous 2013-11-23 06:49:41 +01:00
Marc Häfner
caafafcf4d Simplify removeSource and make it synchronous 2013-11-23 06:49:13 +01:00
Marc Häfner
81d8224b9a Remove path.exists* as fallback for fs.exists* 2013-11-23 06:42:39 +01:00
Marc Häfner
22c85e216f Use absolute paths in CLI
* Use absolute paths for source files and target paths
  * Memorize and explicitly check for watched directories
  * Make path comparison and construction more precise and clear
  * Remove now unnecessary check for special relative paths
2013-11-23 06:41:08 +01:00
Michael Ficarra
f047ba52b2 Merge pull request #3250 from xixixao/issue3229
Fix multiple escaped backslashes in literal strings
2013-11-19 20:32:41 -08:00
xixixao
130899a39f Fix multiple escaped backslashes in literal strings 2013-11-19 23:44:39 +00:00
Jeremy Ashkenas
6847400ccb Merge pull request #3246 from xixixao/issue3229
Implements #3229 - Changed multiline string literals
2013-11-18 16:42:10 -08:00
xixixao
1102567b0c Handle escaped backslashes 2013-11-19 00:04:17 +00:00
xixixao
8c6647849b Don't rely on multiline in other tests 2013-11-18 16:26:48 +00:00
xixixao
de42ad0e1c More test cases 2013-11-18 15:25:11 +00:00
xixixao
073d025fac Better method name and fixed regexps for IE 2013-11-18 15:13:40 +00:00
xixixao
efe8c68c75 Changed multiline string literals 2013-11-18 04:32:15 +00:00
Andreas Lubbe
9941050120 using 'yield' automatically turns functions into generators 2013-11-15 22:19:31 +01:00
Andreas Lubbe
dafc7bdea5 added 'yield' to the unary keywords 2013-11-15 22:16:28 +01:00
Andreas Lubbe
f51cbd7117 removed 'yield' from the reserved keywords 2013-11-15 22:15:31 +01:00
Jeremy Ashkenas
45d97b3dfe Remove old Node pre-0.6 warning. 2013-11-15 14:26:47 -05:00
Jeremy Ashkenas
fcc88ca472 Revert "add: Stat polling support while fs.watch doesn't work."
This reverts commit 2853e718f2.
2013-11-15 14:26:16 -05:00
Jeremy Ashkenas
187ebd0374 Revert "mov: Change the option name --polling to --watch-polling, and only leaves the long option name."
This reverts commit 08f6c65c3b.
2013-11-15 14:26:05 -05:00
Jeremy Ashkenas
c4999efda7 Revert "fix: opts.polling changed to opts[watch-polling]"
This reverts commit 52789f5b19.
2013-11-15 14:25:55 -05:00
Jeremy Ashkenas
b6231e50c3 Merge pull request #3212 from ysmood/issue3210
add: Stat polling support while `fs.watch` doesn't work.
2013-11-15 11:09:50 -08:00
Marc Häfner
592aa33577 Fixes #2367 -- super in for-loop 2013-11-15 06:35:04 +01:00
Marc Häfner
544c99a9ad Fix error location for illegal pure statements 2013-11-15 05:37:34 +01:00
Jeremy Ashkenas
de0e3baf1f Merge pull request #3237 from marchaefner/fixSuper
Fix super-related tagging of `Code` nodes
2013-11-14 19:25:50 -08:00
Marc Häfner
aea0f2533b Fixes #3232 -- Tag all class properties static
(and remove duplicate `context` assigment)
2013-11-15 03:44:26 +01:00
Marc Häfner
138c25fe5f Cleanup and extend METHOD_DEF
* Fixes #2949: Detect reserved names (not only for instance methods)
  * Don't assign names which might result in incorrect `super` calls
2013-11-12 16:53:09 +01:00
Jeremy Ashkenas
e0195756dc Merge pull request #3234 from marchaefner/issue3087
Fixes #3087 -- Use `fs.*Sync` for CLI compilation
2013-11-10 04:19:49 -08:00
Marc Häfner
96ae98fade Fixes #3087 -- Use fs.*Sync for CLI compilation
* Make `compilePath` synchronous
 * Remove unused variable
2013-11-10 08:36:29 +01:00
Nami-Doc
efb9809d3b Merge pull request #3233 from xixixao/issue2953cleanup
Clean up `Method calls on splice endpoints`
2013-11-09 16:20:13 -08:00
xixixao
0dada3dd27 Remove unnecessary type conversions to Number 2013-11-10 00:13:52 +00:00
xixixao
849c8e8ef4 Remove unnecessary existential check 2013-11-10 00:13:14 +00:00
Jeremy Ashkenas
9e9c83f788 Merge pull request #3228 from marchaefner/fixClassCompilation
Avoid unnecessary wrapping of some bound functions
2013-11-05 18:47:01 -08:00
Marc Häfner
d41d87a874 Avoid unnecessary wrapping of some bound functions 2013-11-03 03:14:13 +01:00
Jeremy Ashkenas
ab40571ffc Merge pull request #3227 from marchaefner/fixClassCompilation
Fix scope of external constructor reference / Refactor `Closure`
2013-11-01 13:08:27 -07:00
Marc Häfner
5d13d14de9 Closes #3008 -- Fix scope of constructor reference
* Make scope of `Code` nodes accessible (prior to `compileNode`)
* Use correct scope for reference of external constructor.
* Remove unreachable code.
2013-11-01 01:13:10 +01:00
Marc Häfner
1df8abf1cb Refactor closure compilation
* Break up `Closure` and merge `Closure.wrap` into `Base.compileClosure`
* Construct class closure directly in `Class.compileNode`
* Reuse `isLiteralArguments` in `Range.compileArray`
* Move all helpers to bottom of file
* Add test for #3063
2013-10-31 23:25:11 +01:00
Jeremy Ashkenas
45b60c9a52 Merge pull request #3224 from marchaefner/fixClassCompilation
Minor fixes for class compilation
2013-10-28 17:51:23 -07:00
Marc Häfner
091bc56a96 Code cleanup in Class
* Don't insert unnecessary `_ref` (in the wrong scope)
* Improve code prettiness. (Reverts most of 903e9c99)
2013-10-29 00:01:20 +01:00
Yad Smood
52789f5b19 fix: opts.polling changed to opts[watch-polling] 2013-10-27 01:04:03 +08:00
Marc Häfner
9ba1d41ec8 Fix: __extends helper above directive prologue 2013-10-26 06:54:54 +02:00
Jeremy Ashkenas
5456bd5f89 Merge pull request #3218 from marchaefner/issue3059
Escapable linebreaks in heregexes
2013-10-23 16:03:32 -07:00
Marc Häfner
0d662c3ad2 Missing parentheses 2013-10-24 00:43:29 +02:00
Marc Häfner
fa76e2dd21 Escapable linebreaks in heregexes 2013-10-24 00:36:46 +02:00
Yad Smood
08f6c65c3b mov: Change the option name --polling to --watch-polling, and only leaves the long option name.
opt: Optimize the comment of the `--watch-polling` option.
2013-10-23 00:52:40 +08:00
Jeremy Ashkenas
54840c0cbf Merge pull request #3214 from marchaefner/issue3059
Escaped whitespace and slashes in Heregexes
2013-10-22 09:35:00 -07:00
Marc Häfner
91ac3fa031 Escaped whitespace and slashes in Heregexes
* Resolves #3059: Don't remove escaped whitespace.
* Fixes #2238: Prevent escaping slashes that are already escaped.
* Fix detection of end of heregex with escaped slashes.
2013-10-22 18:08:17 +02:00
Yad Smood
2853e718f2 add: Stat polling support while fs.watch doesn't work.
Add a new cli option: -g --polling [SPAN]

    If state polling mode is enabled, use it.
    Else use the native api.

    This is useful while watching remote directory.
    Such as the `fs.watch` won't catch the SMB server's file change event.
2013-10-21 15:26:20 +08:00
Jeremy Ashkenas
c22707cd53 Fixes #2941 -- don't destroy extensionless filenames for --join 2013-10-20 19:09:55 -03:00
Jeremy Ashkenas
351c875576 merged in stricter noncallables 2013-10-20 18:49:30 -03:00
Jeremy Ashkenas
35b64d7f18 Merge pull request #3211 from marchaefner/issue2181
Fix compilation for conditional assignment
2013-10-20 14:16:38 -07:00
Jeremy Ashkenas
db87d817e8 Merge pull request #3012 from imcotton/parallel-loading
Script loading parallelized in browser
2013-10-20 14:10:40 -07:00
Jeremy Ashkenas
f3c5cc6774 Fixes #3019 - Documentation tweak to default argument meaning. 2013-10-20 18:08:28 -03:00
Marc Häfner
4cc2c305a4 Fixes #2181 -- conditional assignment as subexpression
* Parenthesize compilation of `||=` and `&&=` (when needed).
* Fix variable caching for `?=`
2013-10-20 22:59:01 +02:00
Jeremy Ashkenas
a5513c45d0 Fixes #3047 -- Fixes module.paths when running directly with no explicit passed-in files. 2013-10-20 17:50:13 -03:00
Jeremy Ashkenas
c820e0241e Fixes #3053 - error for mismatched own/for-in without an index. 2013-10-20 17:40:50 -03:00
Jeremy Ashkenas
eb2ac2c64d Fixes #3063 -- wait a moment so that an error can be raised. 2013-10-20 17:04:52 -03:00
Jeremy Ashkenas
59cf19fd1c Fixes #3072 -- tweak process.argv to match when running REPL 2013-10-20 16:53:08 -03:00
Jeremy Ashkenas
d5a25d138d Fixes #3089 -- don't mutate options passed in to compile() 2013-10-20 16:21:06 -03:00
Jeremy Ashkenas
a7ecd80c92 Merge pull request #3096 from marchaefner/issue2994
Disallow single-line `IF expr ELSE` without `THEN`
2013-10-20 12:13:39 -07:00
Jeremy Ashkenas
465cffc675 Merge pull request #3113 from mklement0/make-repl-use-global-context
Make the REPL *CLI* use the global context to be consistent with the node REPL *CLI*.
2013-10-20 09:17:07 -07:00
Jeremy Ashkenas
302a46d093 Merge pull request #3132 from caitp/issue-3132
Format block-comments better
2013-10-20 09:08:40 -07:00
Jeremy Ashkenas
392767a04e Fixes #3143 -- Potential memory leaks caused by use of fat arrow next to other (non-fat-arrow-using) long-lived closures. 2013-10-20 12:53:18 -03:00
Jeremy Ashkenas
928f949761 Fixes #3160 -- a missing bit of locationData 2013-10-20 12:15:15 -03:00
Jeremy Ashkenas
8bb833d858 Merge pull request #3165 from grschafer/master
Fix constructor_destructuring docs example to alert a defined value
2013-10-20 08:04:44 -07:00
Jeremy Ashkenas
2b03fa9077 Fixes #3166 -- add a (simpler) flag to suppress the generated header. 2013-10-20 12:03:37 -03:00
Jeremy Ashkenas
cfdb774da9 CoffeeScript REPL should be able to require coffeescript files. 2013-10-20 11:22:23 -03:00
Jeremy Ashkenas
b173a377a6 Fixes #3208. You now have to require 'coffee-script/extensions' in order to be able to auto-require CoffeeScript files. 2013-10-20 11:08:13 -03:00
Jeremy Ashkenas
581af4540a Merge pull request #3193 from celwell/master
fixed ascii art inconsistencies in coffee's water vapor
2013-10-04 04:04:10 -07:00
Christopher Elwell
18e5b6b199 fixed ascii art inconsistencies in coffee's water vapor 2013-10-03 19:02:28 -07:00
Michael Ficarra
6da2306fe2 Merge pull request #3189 from mal/issue3186
Fixes #3186
2013-09-29 07:42:36 -07:00
Mal Graty
a8e4b78803 Fixes #3186 2013-09-29 15:28:58 +01:00
Nami-Doc
a3be1f6e48 Merge pull request #3174 from a3gis/master
Accept all format of numbers in ranges
2013-09-24 11:20:57 -07:00
a3gis
89ef3d4117 accept all format of numbers in ranges 2013-09-24 19:15:31 +01:00
Jeremy Ashkenas
4cf75ec027 Forgot to update the .erb as well. 2013-09-24 09:52:00 -03:00
Jeremy Ashkenas
830c294aea Add new Packt book. 2013-09-22 14:56:33 -03:00
a3gis
bb86e54ece accept all format of numbers in ranges 2013-09-21 00:51:12 +01:00
Caitlin Potter
359e17277f Merge pull request #1 from sjorek/issue-3132
Enhancement: Add more block-comment related tests
2013-09-17 10:12:31 -07:00
Stephan Jorek
89f5f9d59d added more block-comment related tests for single-line block-comments and jsdoc-like @doctags-comments. 2013-09-17 18:09:15 +02:00
Greg Schafer
26c0f7ca2d Fix constructor_destructuring example to alert a defined value 2013-09-14 14:34:53 -05:00
Michael Ficarra
40c1086efa Merge pull request #3151 from kchmck/master
Fix some inconsistent indentation
2013-09-03 16:33:27 -07:00
Mick Koch
999a3db499 Fix some inconsistent indentation
Some places used 4 spaces instead of 2
2013-09-03 19:02:18 -04:00
Michael Klement
50e13f62f2 Merge branch 'make-repl-use-global-context' of https://github.com/mklement0/coffee-script into make-repl-use-global-context 2013-09-03 18:35:21 -04:00
Michael Klement
fceff1729c Make the REPL *CLI* use the global context so as to be consistent with the node REPL CLI.
Make the REPL *CLI* use the global context so as to (a) be consistent
with the `node` REPL CLI and, therefore, (b) make packages that modify
native prototypes (such as 'colors' and 'sugar') work as expected.

Note that, by contrast, programmatic use (`require 'repl'`) will
continue to default to a NON-global context - again, consistent with
node's behavior.
2013-09-03 18:19:43 -04:00
Michael Ficarra
1765a7ae0c Merge pull request #3150 from mklement0/fix-repl-module-global-context-support
Fix: support for consumers of the REPL *module* being able to opt into using the global context ...
2013-09-03 14:47:22 -07:00
Michael Klement
ae79ff9fa3 Merge branch 'make-repl-use-global-context' of https://github.com/mklement0/coffee-script into make-repl-use-global-context 2013-09-03 17:28:03 -04:00
Michael Klement
3e9d01d6c6 Make the REPL *CLI* use the global context so as to be consistent with the node REPL CLI.
Make the REPL *CLI* use the global context so as to (a) be consistent
with the `node` REPL CLI and, therefore, (b) make packages that modify
native prototypes (such as 'colors' and 'sugar') work as expected.

Note that, by contrast, programmatic use (`require 'repl'`) will
continue to default to a NON-global context - again, consistent with
node's behavior.
2013-09-03 17:27:13 -04:00
Michael Klement
ae4535d639 Fix: support for consumers of the REPL *module* being able to opt into using the global context via option .useGlobal.
Note that, at least for now, CoffeeScript's own REPL *CLI* still uses a
non-global context, rendering modules such as `color`, which attempt to
modify the prototypes of JavaScript primitives, ineffective. By
contrast, node's own CLI does use the global context.
2013-09-03 16:41:27 -04:00
a3gis
c5120c7980 fix exit code when using --nodejs option 2013-09-02 16:11:22 -05:00
Jeremy Ashkenas
92e83489fc Merge pull request #3146 from phillipalexander/fix-underscore-docs
Fix broken formatting in underscore.coffee docs
2013-09-02 13:33:26 -07:00
Caitlin Potter
1b7491d63d Fixes #3132 - Improve rendering of block-comments 2013-08-23 20:53:18 -04:00
Phillip Alexander
ce14ad764a Fix formatting issues in underscore.coffee documentation (generated html)
Use docco to regenerate documentation for underscore.coffee.
2013-08-20 09:57:52 -07:00
Jeremy Ashkenas
96e807c677 Improve license part of package.json ;) 2013-08-19 16:10:25 +02:00
Michael Klement
70994d4b50 Refactored inline-if into more readable multi-line statement. 2013-08-07 11:40:11 -04:00
Michael Klement
675095efbe Amended - Make the REPL *CLI* use the global context so as to be consistent with the node REPL CLI.
(My apologies: In the previous commit I accidentally made `useGlobal:
yes` the default for _programmatic_ use also, but the intent was to
only do it for the stand-alone *CLI*.)

Make the REPL *CLI* use the global context so as to (a) be consistent
with the `node` REPL CLI and, therefore, (b) make packages that modify
native prototypes (such as 'colors' and 'sugar') work as expected.

Note that, by contrast, programmatic use (`require 'repl'`) will
continue to default to a NON-global context - again, consistent with
node's behavior.
2013-08-07 08:59:27 -04:00
Michael Klement
0235d12927 Make the REPL use the global context to be consistent with the node REPL.
This will make packages that modify prototypes - e.g. 'colors', 'sugar'
- work as expected.

To verify that the `node` REPL uses the global context, execute `global
=== module.exports.repl.context`.

Note: Tests pass, except `cluster.coffee`, which, however, failed even
before these modifications.
2013-08-06 21:28:34 -04:00
Michael Ficarra
9d24a3420d Merge pull request #3111 from benbria/master
Issue #3092: Fix column numbers in sourcemaps to not be essentially random.
2013-08-06 13:52:52 -07:00
Jason Walton
3ad332d5d4 Issue #3092: Fix column numbers in sourcemaps to not be essentially random. 2013-08-06 16:25:23 -04:00
Michael Ficarra
15517df417 Merge pull request #3107 from mal/issue2957
Fork with binary of coffee-script in use, rather than global
2013-08-02 15:44:55 -07:00
Mal Graty
3c2f0d174e Use coffee binary of coffee that overrode fork
This solves two potential problems when it comes to forking:

    1) Forking will now work correctly even when `coffee` is not installed
       globally.
    2) Forking when using a locally installed version of `coffee` will fork
       using that version, and not fallback to a globally installed version.

Fixes #2957
2013-08-02 23:10:45 +01:00
Jeremy Ashkenas
8cf6f62ea4 Merge pull request #3100 from epidemian/issue3023
Fix #3023, Change how error messages are shown
2013-08-02 13:05:37 -07:00
Demian Ferreiro
9e716b310d Avoid using a getter for the compiler error's "stack" property
Instead, set the "stack" property manually when the error gets updated on re-throws.
2013-08-02 01:52:36 -03:00
Michael Ficarra
e44bf9ae81 Merge pull request #3104 from davidchambers/recompile
recompile
2013-08-01 14:17:14 -07:00
David Chambers
f5f99b3022 recompile 2013-08-01 14:14:12 -07:00
Jeremy Ashkenas
dc3d70e696 cleaning up mkdirp bit. 2013-08-01 11:12:41 -04:00
Jeremy Ashkenas
77fded3c5e Merge pull request #3101 from FredyC/master
Fixed deep directory creation for command line utility
2013-08-01 08:11:07 -07:00
FredyC
e644f7244d Using original existence check with mkdirp call on failure 2013-08-01 17:03:32 +02:00
FredyC
457cdfde26 Fixed deep directory creation for command line utility 2013-08-01 11:17:27 +02:00
Marc Häfner
910e38749c Merge removeMidExpressionNewlines into addImplicitIndentation
and rename it to `normalizeLines`
2013-07-31 22:12:44 +02:00
Demian Ferreiro
2b4a37296f Override the SyntaxError's "stack" property instead of deleting it
This makes the "stack" property more useful when it's shown on other Node.js applications that compile CoffeeScript (e.g. testing libraries) and should fix #3023. A minimal example:

    $ node -e 'require("coffee-script").compile("class class")'

    /usr/lib/node_modules/coffee-script/lib/coffee-script/coffee-script.js:41
            throw err;
                  ^
    [stdin]:1:7: error: unexpected CLASS
    class class
          ^^^^^
2013-07-31 09:24:43 -03:00
Demian Ferreiro
3f9cdcf1fa Change how error messages are shown
Instead of throwing the syntax errors with their source file location and needing to then catch them and call a `prettyErrorMessage` function in order to get the formatted error message, now syntax errors know how to pretty-print themselves (their `toString` method gets overridden).

An intermediate `catch` & re-`throw` is needed at the level of `CoffeeScript.compile` and friends. But the benefit of this approach is that now libraries that use the `CoffeeScript` object directly don't need to bother catching the possible compilation errors and calling a special function in order to get the nice error messages; they can just print the error itself (or let it bubble up) and the error will know how to pretty-print itself.
2013-07-31 08:27:49 -03:00
Marc Häfner
4342bedd2f Fix multi-line if-else in single-line expression.
* When searching for the closing token of a single-line expression, ignore TERMINATORS that will subsequently be removed.
* Add a test.
2013-07-31 12:18:50 +02:00
Marc Häfner
fdd5796f5e Disallow single-line IF expr ELSE without THEN
* Supplement missing block before `ELSE` token only for multi-line `if`.
* Don't prematurely remove `TERMINATOR` before `ELSE` (so we can  differentiate single- and multi-line forms).
* Cleanup: Remove `WHEN` from `EXPRESSION_CLOSE`. (Only `LEADING_WHEN` tokens are preceded by a `TERMINATOR`.)
* Cleanup: Remove really old, inapplicable text from comment.
2013-07-30 19:31:46 +02:00
Jeremy Ashkenas
f48aa44386 Merge pull request #3094 from epidemian/compile-js
Update compiled JS
2013-07-29 23:17:38 -07:00
Demian Ferreiro
51c625205b Update compiled JS 2013-07-30 01:06:41 -03:00
Michael Ficarra
e581f7d2f0 Merge pull request #3051 from CaseyLeask/source-map-syntax-update
Updated the Source Maps syntax
2013-07-04 07:03:00 -07:00
Cotton Hou
3aa646e425 rebuild for PR #3012 2013-06-28 09:40:22 +08:00
Cotton Hou
92208fec44 simplify logic and changing less from before 2013-06-28 09:28:20 +08:00
Cotton Hou
cdc603c794 remove logic redundancy 2013-06-28 09:28:20 +08:00
Cotton Hou
46d8902004 parallelized script loading in browser, yet order remain 2013-06-28 09:28:20 +08:00
Casey Leask
34c1704286 Removed multi-line comment wrapping 2013-06-26 13:11:13 +00:00
Casey Leask
19767a0f10 Updated the Source Maps syntax 2013-06-26 12:34:21 +00:00
Nami-Doc
0c9f0fd099 Merge pull request #3049 from dpatti/extensions-scope
Avoid variable scope collision with extensions
2013-06-24 15:14:01 -07:00
Doug Patti
7f1088054c Avoid variable scope collision with extensions
In #3031, an extensions variable was introduced with file-level scope
that defined the filetypes that CoffeeScript can compile. However, the
Module::load patching calls findExtension() which uses a local variable
called "extensions", which was overriding the outer level one and
causing getSourceMap() to fail.
2013-06-24 18:13:04 -04:00
Nami-Doc
ef5f58e30e Merge pull request #3045 from marchaefner/master
Fix path separator issues in tests.
2013-06-22 06:04:46 -07:00
Marc Häfner
13024e6911 Fix path separator issues in tests. 2013-06-22 14:57:23 +02:00
Nami-Doc
32e8e562ea Merge pull request #3043 from imcotton/reference-check
check existence of "path" for browser execution
2013-06-21 10:08:49 -07:00
Cotton Hou
7fdac5c3b9 check existence of "path" for browser execution 2013-06-22 00:58:30 +08:00
Jeremy Ashkenas
b68fd9d76e Merge pull request #3042 from marchaefner/issue2844
Avoid excessive AST traversal in `updateLocationDataIfMissing`.
2013-06-20 22:33:50 -07:00
Marc Häfner
25c6001a6c Speed up updateLocationDataIfMissing.
* Avoid excessive search for missing `locationData`
  * Fix `locationData` for `ELSE IF`.
2013-06-21 02:47:29 +02:00
Jeremy Ashkenas
7250fdd576 Merge pull request #3031 from alexgorbatchev/stack-trace-patch-optimizations-2
Stack trace patch optimizations
2013-06-16 02:37:33 -07:00
Jeremy Ashkenas
b7f8443052 Merge pull request #3034 from marchaefner/baseIndent
Better handling of initial indent at file start.
2013-06-16 02:35:06 -07:00
Marc Häfner
4fd5e9a3ab Better handling of initial indent at file start.
* Detect initial indentation before the first token and enforce it.
  * Don't add `INDENT` token (or the matching `OUTDENT, TERMINATOR`).
2013-06-14 00:28:45 +02:00
Alex Gorbatchev
3785996c44 Made stack patch test less brittle. 2013-06-13 13:50:05 -07:00
Alex Gorbatchev
eb0a222eea Using more standard convention for patched stack line numbers. 2013-06-13 12:58:04 -07:00
Alex Gorbatchev
3d761e73e3 Removed unnecessary source map generation during require() and made stack line number patching on by default. 2013-06-13 12:54:20 -07:00
Alex Gorbatchev
cc3b4e8080 Removed not used variable. 2013-06-13 12:23:06 -07:00
Michael Ficarra
ba7cb3ab69 fix #3029 2013-06-13 13:38:13 -05:00
Michael Ficarra
054443c46e rebuild #3029 2013-06-13 13:35:40 -05:00
Jeremy Ashkenas
c8dae22cb0 Merge pull request #3029 from wangxian/master
fix block comment format "\n"
2013-06-13 10:55:52 -07:00
木頭
183ec48308 fix block comment 2013-06-13 07:44:17 +08:00
Jeremy Ashkenas
13187b0199 Merge pull request #2856 from epidemian/issue2849
Fixes #2849: use correct filename and code in require()d sources
2013-06-09 00:40:18 -07:00
Demian Ferreiro
3c880bf601 Move a try/catch from compile to loadFile
This try/catch should only be necessary for dynamically loaded files. Also added a lengthier explanation of why this try/catch is needed.
2013-06-09 02:54:34 -03:00
Demian Ferreiro
8e90aaefc1 Merge branch 'master' into issue2849
Conflicts:
	lib/coffee-script/coffee-script.js
	src/coffee-script.coffee
2013-06-09 02:40:53 -03:00
Michael Ficarra
426ae97e49 Merge pull request #3014 from mset/master
base path for compilation can be './' as well as '.'
2013-06-03 06:27:38 -07:00
Marek Setnicka
f277a43645 Bug fix. When coffee is invoked with the -c parameter and './' value, first two characters of the directory into which the compiled files are stored get chopped off.
Example: if compilation invoked like this: 'coffee -o ../lib/ -cw ./', then
Source file: ./OutputFolder/file.coffee, compiled output: ./../lib/tputFolder/
The code only expected '.' to mark the local folder. However, './' is equally valid.
2013-06-03 13:51:26 +01:00
Jeremy Ashkenas
2e408648aa renaming import test files to avoid risking the disfavor of .gitignore 2013-06-02 10:57:18 +04:00
Jeremy Ashkenas
f2f10e85a8 Revert "remove cake build:ultraviolet"
This reverts commit 2e6a781014.
2013-06-02 09:45:11 +04:00
Michal Srb
e7ebdce60f Fix #2953. Method calls on splice endpoints 2013-04-23 05:42:37 +02:00
Michal Srb
fd61476106 Fix #1069. Non-callable literals shouldn't compile 2013-04-23 04:28:45 +02:00
Demian Ferreiro
d57b1aab10 Add power operator to the list of tokens that force a line continuation if they appear at the end of a line 2013-03-25 20:41:14 -03:00
Demian Ferreiro
22e8856b4d Add floor division // and modulo %% operators, and compound forms of the new operators
Also kill the empty regex :(
2013-03-25 03:19:05 -03:00
Demian Ferreiro
08b59aef8a Make power operator have higher precedence than unary operators: +, -, ~, ! 2013-03-25 00:05:04 -03:00
Demian Ferreiro
fbc019171c Make power operator compilation use proper AST nodes 2013-03-25 00:02:21 -03:00
Demian Ferreiro
e237abff84 Merge branch 'power-operator' of git://github.com/charliesome/coffee-script into more-math-operators
Conflicts:
	src/nodes.coffee
	test/operators.coffee
2013-03-24 22:47:46 -03:00
Demian Ferreiro
c0d1f22487 Add test for compiler errors on require()d files 2013-03-21 03:11:31 -03:00
Demian Ferreiro
67fd84fc1d Fixes #2849: now the compilation errors thrown by CoffeeScript.compile will include the correct filename and source code information 2013-03-19 04:27:34 -03:00
charliesome
3bd4dea305 fix the precedence test so it's actually meaningful 2012-01-11 21:37:06 +11:00
charliesome
a4249fd573 power operator + tests 2012-01-11 17:14:23 +11:00
178 changed files with 15933 additions and 11236 deletions

View File

@@ -1,9 +1,9 @@
## How to contribute to CoffeeScript
* Before you open a ticket or send a pull request, [search](https://github.com/jashkenas/coffee-script/issues) for previous discussions about the same feature or issue. Add to the earlier ticket if you find one.
* Before you open a ticket or send a pull request, [search](https://github.com/jashkenas/coffeescript/issues) for previous discussions about the same feature or issue. Add to the earlier ticket if you find one.
* Before sending a pull request for a feature, be sure to have [tests](https://github.com/jashkenas/coffee-script/tree/master/test).
* Before sending a pull request for a feature, be sure to have [tests](https://github.com/jashkenas/coffeescript/tree/master/test).
* Use the same coding style as the rest of the [codebase](https://github.com/jashkenas/coffee-script/tree/master/src). If you're just getting started with CoffeeScript, there's a nice [style guide](https://github.com/polarmobile/coffeescript-style-guide).
* 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 `coffee-script.js` file. We'll do those things before cutting a new release.

View File

@@ -1,5 +1,6 @@
fs = require 'fs'
path = require 'path'
_ = require 'underscore'
CoffeeScript = require './lib/coffee-script'
{spawn, exec} = require 'child_process'
helpers = require './lib/coffee-script/helpers'
@@ -41,6 +42,56 @@ run = (args, cb) ->
log = (message, color, explanation) ->
console.log color + message + reset + ' ' + (explanation or '')
codeFor = ->
counter = 0
hljs = require 'highlight.js'
hljs.configure classPrefix: ''
(file, executable = false, showLoad = true) ->
counter++
return unless fs.existsSync "documentation/js/#{file}.js"
cs = fs.readFileSync "documentation/coffee/#{file}.coffee", 'utf-8'
js = fs.readFileSync "documentation/js/#{file}.js", 'utf-8'
js = js.replace /^\/\/ generated.*?\n/i, ''
cshtml = "<pre><code>#{hljs.highlight('coffeescript', cs).value}</code></pre>"
jshtml = "<pre><code>#{hljs.highlight('javascript', js).value}</code></pre>"
append = if executable is yes then '' else "alert(#{executable});"
if executable and executable != yes
cs.replace /(\S)\s*\Z/m, "$1\n\nalert #{executable}"
run = if executable is true then 'run' else "run: #{executable}"
name = "example#{counter}"
script = "<script>window.#{name} = #{JSON.stringify cs}</script>"
load = if showLoad then "<div class='minibutton load' onclick='javascript: loadConsole(#{name});'>load</div>" else ''
button = if executable then "<div class='minibutton ok' onclick='javascript: #{js};#{append}'>#{run}</div>" else ''
"<div class='code'>#{cshtml}#{jshtml}#{script}#{load}#{button}<br class='clear' /></div>"
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}"
releaseHeader = (date, version, prevVersion) -> """
<div class="anchor" id="#{version}"></div>
<b class="header">
#{prevVersion and "<a href=\"https://github.com/jashkenas/coffeescript/compare/#{prevVersion}...#{version}\">#{version}</a>" or version}
<span class="timestamp"> &mdash; <time datetime="#{date}">#{formatDate date}</time></span>
</b>
"""
option '-p', '--prefix [DIR]', 'set the installation prefix for `cake install`'
task 'install', 'install CoffeeScript into /usr/local (or --prefix)', (options) ->
@@ -53,7 +104,7 @@ task 'install', 'install CoffeeScript into /usr/local (or --prefix)', (options)
console.log "Linking 'coffee' to #{bin}/coffee"
exec([
"mkdir -p #{lib} #{bin}"
"cp -rf bin lib LICENSE README package.json src #{lib}"
"cp -rf bin lib LICENSE README.md package.json src #{lib}"
"ln -sfn #{lib}/bin/coffee #{bin}/coffee"
"ln -sfn #{lib}/bin/cake #{bin}/cake"
"mkdir -p ~/.node_libraries"
@@ -84,7 +135,6 @@ task 'build:parser', 'rebuild the Jison parser (run build first)', ->
parser = require('./lib/coffee-script/grammar').parser
fs.writeFile 'lib/coffee-script/parser.js', parser.generate()
task 'build:browser', 'rebuild the merged script for inclusion in the browser', ->
code = ''
for name in ['helpers', 'rewriter', 'lexer', 'parser', 'scope', 'nodes', 'sourcemap', 'coffee-script', 'browser']
@@ -118,17 +168,28 @@ task 'build:browser', 'rebuild the merged script for inclusion in the browser',
task 'doc:site', 'watch and continually rebuild the documentation for the website', ->
exec 'rake doc', (err) ->
throw err if err
source = 'documentation/index.html.js'
exec 'bin/coffee -bc -o documentation/js documentation/coffee/*.coffee'
do renderIndex = ->
codeSnippetCounter = 0
rendered = _.template fs.readFileSync(source, 'utf-8'),
codeFor: codeFor()
releaseHeader: releaseHeader
fs.writeFileSync 'index.html', rendered
log "compiled", green, "#{source}"
fs.watchFile source, interval: 200, renderIndex
log "watching..." , green
task 'doc:source', 'rebuild the internal documentation', ->
exec 'docco src/*.*coffee && cp -rf docs documentation && rm -r docs', (err) ->
exec 'node_modules/.bin/docco src/*.*coffee && cp -rf docs documentation && rm -r docs', (err) ->
throw err if err
task 'doc:underscore', 'rebuild the Underscore.coffee documentation page', ->
exec 'docco examples/underscore.coffee && cp -rf docs documentation && rm -r docs', (err) ->
exec 'node_modules/.bin/docco examples/underscore.coffee && cp -rf docs documentation && rm -r docs', (err) ->
throw err if err
task 'bench', 'quick benchmark of compilation time', ->
@@ -155,6 +216,7 @@ task 'bench', 'quick benchmark of compilation time', ->
# Run the CoffeeScript test suite.
runTests = (CoffeeScript) ->
CoffeeScript.register()
startTime = Date.now()
currentFile = null
passedTests = 0
@@ -214,6 +276,12 @@ runTests = (CoffeeScript) ->
# Run every test in the `test` folder, recording failures.
files = fs.readdirSync 'test'
# Ignore generators test file if generators are not available
generatorsAreAvailable = '--harmony' in process.execArgv or
'--harmony-generators' in process.execArgv
files.splice files.indexOf('generators.coffee'), 1 if not generatorsAreAvailable
for file in files when helpers.isCoffee file
literate = helpers.isLiterate file
currentFile = filename = path.join 'test', file

View File

@@ -1,4 +1,4 @@
Copyright (c) 2009-2013 Jeremy Ashkenas
Copyright (c) 2009-2015 Jeremy Ashkenas
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation

51
README
View File

@@ -1,51 +0,0 @@
{
} } {
{ { } }
} }{ {
{ }{ } } _____ __ __
( }{ }{ { ) / ____| / _|/ _|
.- { { } { }} -. | | ___ | |_| |_ ___ ___
( ( } { } { } } ) | | / _ \| _| _/ _ \/ _ \
|`-..________ ..-'| | |___| (_) | | | || __/ __/
| | \_____\___/|_| |_| \___|\___|
| ;--.
| (__ \ _____ _ _
| | ) ) / ____| (_) | |
| |/ / | (___ ___ _ __ _ _ __ | |_
| ( / \___ \ / __| '__| | '_ \| __|
| |/ ____) | (__| | | | |_) | |_
| | |_____/ \___|_| |_| .__/ \__|
`-.._________..-' | |
|_|
CoffeeScript is a little language that compiles into JavaScript.
Install Node.js, and then the CoffeeScript compiler:
sudo bin/cake install
Or, if you have the Node Package Manager installed:
npm install -g coffee-script
(Leave off the -g if you don't wish to install globally.)
Execute a script:
coffee /path/to/script.coffee
Compile a script:
coffee -c /path/to/script.coffee
For documentation, usage, and examples, see:
http://coffeescript.org/
To suggest a feature, report a bug, or general discussion:
http://github.com/jashkenas/coffee-script/issues/
If you'd like to chat, drop by #coffeescript on Freenode IRC,
or on webchat.freenode.net.
The source repository:
git://github.com/jashkenas/coffee-script.git
All contributors are listed here:
http://github.com/jashkenas/coffee-script/contributors

62
README.md Normal file
View File

@@ -0,0 +1,62 @@
{
} } {
{ { } }
} }{ {
{ }{ } } _____ __ __
{ }{ }{ { } / ____| / _|/ _|
.- { { } { }} -. | | ___ | |_| |_ ___ ___
( { } { } { } } ) | | / _ \| _| _/ _ \/ _ \
|`-..________ ..-'| | |___| (_) | | | || __/ __/
| | \_____\___/|_| |_| \___|\___|
| ;--.
| (__ \ _____ _ _
| | ) ) / ____| (_) | |
| |/ / | (___ ___ _ __ _ _ __ | |_
| ( / \___ \ / __| '__| | '_ \| __|
| |/ ____) | (__| | | | |_) | |_
| | |_____/ \___|_| |_| .__/ \__|
`-.._________..-' | |
|_|
CoffeeScript is a little language that compiles into JavaScript.
## Installation
If you have the node package manager, npm, installed:
```shell
npm install -g coffee-script
```
Leave off the `-g` if you don't wish to install globally. If you don't wish to use npm:
```shell
git clone https://github.com/jashkenas/coffeescript.git
sudo coffeescript/bin/cake install
```
## Getting Started
Execute a script:
```shell
coffee /path/to/script.coffee
```
Compile a script:
```shell
coffee -c /path/to/script.coffee
```
For documentation, usage, and examples, see: http://coffeescript.org/
To suggest a feature or report a bug: http://github.com/jashkenas/coffeescript/issues
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
Our lovely and talented contributors are listed here: http://github.com/jashkenas/coffeescript/contributors

View File

@@ -1,79 +0,0 @@
require 'rubygems'
require 'erb'
require 'fileutils'
require 'rake/testtask'
require 'json'
desc "Build the documentation page"
task :doc do
source = 'documentation/index.html.erb'
child = fork { exec "bin/coffee -bcw -o documentation/js documentation/coffee/*.coffee" }
at_exit { Process.kill("INT", child) }
Signal.trap("INT") { exit }
loop do
mtime = File.stat(source).mtime
if !@mtime || mtime > @mtime
rendered = ERB.new(File.read(source)).result(binding)
File.open('index.html', 'w+') {|f| f.write(rendered) }
end
@mtime = mtime
sleep 1
end
end
desc "Build coffee-script-source gem"
task :gem do
require 'rubygems'
require 'rubygems/package'
gemspec = Gem::Specification.new do |s|
s.name = 'coffee-script-source'
s.version = JSON.parse(File.read('package.json'))["version"]
s.date = Time.now.strftime("%Y-%m-%d")
s.homepage = "http://jashkenas.github.com/coffee-script/"
s.summary = "The CoffeeScript Compiler"
s.description = <<-EOS
CoffeeScript is a little language that compiles into JavaScript.
Underneath all of those embarrassing braces and semicolons,
JavaScript has always had a gorgeous object model at its heart.
CoffeeScript is an attempt to expose the good parts of JavaScript
in a simple way.
EOS
s.files = [
'lib/coffee_script/coffee-script.js',
'lib/coffee_script/source.rb'
]
s.authors = ['Jeremy Ashkenas']
s.email = 'jashkenas@gmail.com'
s.rubyforge_project = 'coffee-script-source'
s.license = "MIT"
end
file = File.open("coffee-script-source.gem", "w")
Gem::Package.open(file, 'w') do |pkg|
pkg.metadata = gemspec.to_yaml
path = "lib/coffee_script/source.rb"
contents = <<-ERUBY
module CoffeeScript
module Source
def self.bundled_path
File.expand_path("../coffee-script.js", __FILE__)
end
end
end
ERUBY
pkg.add_file_simple(path, 0644, contents.size) do |tar_io|
tar_io.write(contents)
end
contents = File.read("extras/coffee-script.js")
path = "lib/coffee_script/coffee-script.js"
pkg.add_file_simple(path, 0644, contents.size) do |tar_io|
tar_io.write(contents)
end
end
end

27
bower.json Normal file
View File

@@ -0,0 +1,27 @@
{
"name": "coffee-script",
"version": "1.9.2",
"main": [
"lib/coffee-script/coffee-script.js"
],
"description": "Unfancy JavaScript",
"keywords": [
"javascript",
"language",
"coffeescript",
"compiler"
],
"devDependencies": {
"uglify-js": "~2.2",
"jison": ">=0.2.0",
"highlight.js": "~8.0.0",
"underscore": "~1.5.2",
"docco": "~0.6.2"
},
"author": {
"name": "Jeremy Ashkenas"
},
"ignore": [
"test"
]
}

View File

@@ -0,0 +1,8 @@
$ 'body'
.click (e) ->
$ '.box'
.fadeIn 'fast'
.addClass '.active'
.css 'background', 'white'

View File

@@ -2,3 +2,5 @@ class Person
constructor: (options) ->
{@name, @age, @height} = options
tim = new Person age: 4

View File

@@ -0,0 +1,7 @@
text = "Every literary critic believes he will
outwit history and have the last word"
[first, ..., last] = text.split " "

View File

@@ -2,5 +2,5 @@ Account = (customer, cart) ->
@customer = customer
@cart = cart
$('.shopping_cart').bind 'click', (event) =>
$('.shopping_cart').on 'click', (event) =>
@customer.purchase @cart

View File

@@ -0,0 +1,8 @@
perfectSquares = ->
num = 0
loop
num += 1
yield num * num
return
window.ps or= perfectSquares()

View File

@@ -2,8 +2,8 @@ numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9]
start = numbers[0..2]
middle = numbers[3...6]
middle = numbers[3...-2]
end = numbers[6..]
end = numbers[-2..]
copy = numbers[..]

View File

@@ -1,8 +1,6 @@
mobyDick = "Call me Ishmael. Some years ago --
never mind how long precisely -- having little
or no money in my purse, and nothing particular
to interest me on shore, I thought I would sail
about a little and see the watery part of the
world..."
never mind how long precisely -- having little
or no money in my purse, and nothing particular
to interest me on shore, I thought I would sail
about a little and see the watery part of the
world..."

View File

@@ -81,14 +81,15 @@ code, pre, tt, textarea {
padding-left: 0;
}
.timestamp {
font-size: 12px;
font-size: 11px;
font-weight: normal;
color: black;
text-transform: uppercase;
}
div.anchor {
position: relative;
top: -90px;
margin: 0 0 -20px;
}
.timestamp small {
font-size: 11px;
text-transform: uppercase;
}
div.code {
position: relative;
background: #fff;
@@ -154,22 +155,6 @@ div.code {
#logo img {
margin: 5px 0 0 3px;
}
#error {
position: absolute;
-webkit-border-radius: 2px; -moz-border-radius: 2px; border-radius: 2px;
-webkit-border-top-left-radius: 0; -moz-border-radius-topleft: 0; border-top-left-radius: 0;
-webkit-border-bottom-left-radius: 0; -moz-border-radius-bottomleft: 0; border-bottom-left-radius: 0;
right: 0px; top: 0px; left: 726px; bottom: 0;
padding: 0 0 0 15px;
background: #fdcdcc;
background: -webkit-gradient(linear, left top, left bottom, from(#ffedec), to(#ff9a95));
background: -moz-linear-gradient(top, #f8f8f8, #dadada);
color: #862322;
font-size: 10px;
line-height: 50px;
overflow: hidden;
text-transform: uppercase;
}
.navigation {
height: 50px;
font-size: 11px;
@@ -321,6 +306,9 @@ div.code {
margin-bottom: 0;
top: 10px; left: 10px; right: 10px; bottom: 15px;
}
#repl_results.error {
color: red
}
#repl_source_wrap {
margin-left: 5px;
width: 47%; right: 50%;
@@ -383,3 +371,9 @@ div.code {
background-image: url(../images/button_bg_dark.gif);
text-shadow: none;
}
.minibutton.error {
opacity: 0.5;
color: #600;
cursor: not-allowed;
}

View File

@@ -1,64 +0,0 @@
pre.idle .InheritedClass {
}
pre.idle .TypeName {
color: #21439C;
}
pre.idle .Number {
}
pre.idle .LibraryVariable {
color: #A535AE;
}
pre.idle .Storage {
color: #FF5600;
}
pre.idle .line-numbers {
background-color: #BAD6FD;
color: #000000;
}
pre.idle {
background-color: #FFFFFF;
color: #000000;
}
pre.idle .StringInterpolation {
color: #990000;
}
pre.idle .TagName {
}
pre.idle .LibraryConstant {
color: #A535AE;
}
pre.idle .FunctionArgument {
color: #0076ad;
}
pre.idle .BuiltInConstant {
color: #A535AE;
}
pre.idle .Invalid {
background-color: #990000;
color: #FFFFFF;
}
pre.idle .LibraryClassType {
color: #A535AE;
}
pre.idle .LibraryFunction {
color: #A535AE;
}
pre.idle .TagAttribute {
}
pre.idle .Keyword {
color: #FF5600;
}
pre.idle .UserDefinedConstant {
}
pre.idle .String {
color: #00A33F;
}
pre.idle .FunctionName {
color: #21439C;
}
pre.idle .Variable {
color: #A535AE;
}
pre.idle .Comment {
color: #919191;
}

View File

@@ -0,0 +1,66 @@
/* http://jmblog.github.com/color-themes-for-google-code-highlightjs */
/* Original code:; http://softwaremaniacs.org/media/soft/highlight/styles/tomorrow.css */
/* But forked for CoffeeScript */
.tomorrow-comment, pre .comment, pre .title {
color: #8e908c;
}
.tomorrow-red, pre .variable, pre .tag, pre .regexp, pre .ruby .constant, pre .xml .tag .title, pre .xml .pi, pre .xml .doctype, pre .html .doctype, pre .css .id, pre .css .class, pre .css .pseudo {
color: #c82829;
}
.tomorrow-orange, pre .number, pre .preprocessor, pre .built_in, pre .params, pre .constant {
color: #000000;
}
.tomorrow-yellow, pre .class, pre .ruby .class .title, pre .css .rules .attribute {
color: #eab700;
}
.tomorrow-green, pre .string, pre .value, pre .inheritance, pre .header, pre .ruby .symbol, pre .xml .cdata {
color: #718c00;
}
.tomorrow-aqua, pre .css .hexcolor {
color: #3e999f;
}
.tomorrow-blue, pre .function, pre .function .title, pre .python .decorator, pre .python .title, pre .ruby .function .title, pre .ruby .title .keyword, pre .perl .sub, pre .javascript .title, pre .coffeescript .title {
color: #21439C;
}
.tomorrow-purple, pre .keyword, pre .reserved, pre .javascript .function {
color: #FF5600;
}
pre .subst {
color: #A535AE;
}
pre .literal {
color: #A535AE;
}
pre .property {
color: #A535AE;
}
pre .class .title {
color: #21439C;
}
pre code {
display: block;
background: white;
color: #000000;
}
pre .coffeescript .javascript,
pre .javascript .xml,
pre .tex .formula,
pre .xml .javascript,
pre .xml .vbscript,
pre .xml .css,
pre .xml .cdata {
opacity: 0.5;
}

View File

@@ -16,78 +16,85 @@
<a class="large" href="javascript:void(0);">Jump To &hellip;</a>
<a class="small" href="javascript:void(0);">+</a>
<div id="jump_wrapper">
<div id="jump_page">
<div id="jump_page_wrapper">
<div id="jump_page">
<a class="source" href="browser.html">
browser.coffee
</a>
<a class="source" href="browser.html">
browser.coffee
</a>
<a class="source" href="cake.html">
cake.coffee
</a>
<a class="source" href="cake.html">
cake.coffee
</a>
<a class="source" href="coffee-script.html">
coffee-script.coffee
</a>
<a class="source" href="coffee-script.html">
coffee-script.coffee
</a>
<a class="source" href="command.html">
command.coffee
</a>
<a class="source" href="command.html">
command.coffee
</a>
<a class="source" href="grammar.html">
grammar.coffee
</a>
<a class="source" href="grammar.html">
grammar.coffee
</a>
<a class="source" href="helpers.html">
helpers.coffee
</a>
<a class="source" href="helpers.html">
helpers.coffee
</a>
<a class="source" href="index.html">
index.coffee
</a>
<a class="source" href="index.html">
index.coffee
</a>
<a class="source" href="lexer.html">
lexer.coffee
</a>
<a class="source" href="lexer.html">
lexer.coffee
</a>
<a class="source" href="nodes.html">
nodes.coffee
</a>
<a class="source" href="nodes.html">
nodes.coffee
</a>
<a class="source" href="optparse.html">
optparse.coffee
</a>
<a class="source" href="optparse.html">
optparse.coffee
</a>
<a class="source" href="repl.html">
repl.coffee
</a>
<a class="source" href="register.html">
register.coffee
</a>
<a class="source" href="rewriter.html">
rewriter.coffee
</a>
<a class="source" href="repl.html">
repl.coffee
</a>
<a class="source" href="scope.html">
scope.litcoffee
</a>
<a class="source" href="rewriter.html">
rewriter.coffee
</a>
<a class="source" href="sourcemap.html">
sourcemap.litcoffee
</a>
<a class="source" href="scope.html">
scope.litcoffee
</a>
<a class="source" href="sourcemap.html">
sourcemap.litcoffee
</a>
</div>
</div>
</li>
</ul>
@@ -111,14 +118,13 @@
<p>This <strong>Browser</strong> compatibility layer extends core CoffeeScript functions
to make things work smoothly when compiling code directly in the browser.
We add support for loading remote Coffee scripts via <strong>XHR</strong>, and
<code>text/coffeescript</code> script tags, source maps via data-URLs, and so on.
</p>
<code>text/coffeescript</code> script tags, source maps via data-URLs, and so on.</p>
</div>
<div class="content"><div class='highlight'><pre>
CoffeeScript = require <span class="string">'./coffee-script'</span>
CoffeeScript.require = require
CoffeeScript = <span class="hljs-built_in">require</span> <span class="hljs-string">'./coffee-script'</span>
CoffeeScript.<span class="hljs-built_in">require</span> = <span class="hljs-built_in">require</span>
compile = CoffeeScript.compile</pre></div></div>
</li>
@@ -130,13 +136,12 @@ compile = CoffeeScript.compile</pre></div></div>
<div class="pilwrap ">
<a class="pilcrow" href="#section-2">&#182;</a>
</div>
<p>Use standard JavaScript <code>eval</code> to eval code.
</p>
<p>Use standard JavaScript <code>eval</code> to eval code.</p>
</div>
<div class="content"><div class='highlight'><pre>CoffeeScript.<span class="function"><span class="title">eval</span></span> = (code, options = {}) -&gt;
options.bare ?= <span class="literal">on</span>
<div class="content"><div class='highlight'><pre>CoffeeScript.<span class="hljs-function"><span class="hljs-title">eval</span> = <span class="hljs-params">(code, options = {})</span> -&gt;</span>
options.bare ?= <span class="hljs-literal">on</span>
eval compile code, options</pre></div></div>
</li>
@@ -148,14 +153,13 @@ compile = CoffeeScript.compile</pre></div></div>
<div class="pilwrap ">
<a class="pilcrow" href="#section-3">&#182;</a>
</div>
<p>Running code does not provide access to this scope.
</p>
<p>Running code does not provide access to this scope.</p>
</div>
<div class="content"><div class='highlight'><pre>CoffeeScript.<span class="function"><span class="title">run</span></span> = (code, options = {}) -&gt;
options.bare = <span class="literal">on</span>
options.shiftLine = <span class="literal">on</span>
<div class="content"><div class='highlight'><pre>CoffeeScript.<span class="hljs-function"><span class="hljs-title">run</span> = <span class="hljs-params">(code, options = {})</span> -&gt;</span>
options.bare = <span class="hljs-literal">on</span>
options.shiftLine = <span class="hljs-literal">on</span>
Function(compile code, options)()</pre></div></div>
</li>
@@ -167,12 +171,11 @@ compile = CoffeeScript.compile</pre></div></div>
<div class="pilwrap ">
<a class="pilcrow" href="#section-4">&#182;</a>
</div>
<p>If we&#39;re not in a browser environment, we&#39;re finished with the public API.
</p>
<p>If were not in a browser environment, were finished with the public API.</p>
</div>
<div class="content"><div class='highlight'><pre><span class="keyword">return</span> <span class="keyword">unless</span> window?</pre></div></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>
</li>
@@ -183,19 +186,18 @@ compile = CoffeeScript.compile</pre></div></div>
<div class="pilwrap ">
<a class="pilcrow" href="#section-5">&#182;</a>
</div>
<p>Include source maps where possible. If we&#39;ve got a base64 encoder, a
JSON serializer, and tools for escaping unicode characters, we&#39;re good to go.
Ported from <a href="https://developer.mozilla.org/en-US/docs/DOM/window.btoa">https://developer.mozilla.org/en-US/docs/DOM/window.btoa</a>
</p>
<p>Include source maps where possible. If weve got a base64 encoder, a
JSON serializer, and tools for escaping unicode characters, were good to go.
Ported from <a href="https://developer.mozilla.org/en-US/docs/DOM/window.btoa">https://developer.mozilla.org/en-US/docs/DOM/window.btoa</a></p>
</div>
<div class="content"><div class='highlight'><pre><span class="keyword">if</span> btoa? <span class="keyword">and</span> JSON? <span class="keyword">and</span> unescape? <span class="keyword">and</span> encodeURIComponent?
<span class="function"><span class="title">compile</span></span> = (code, options = {}) -&gt;
options.sourceMap = <span class="literal">true</span>
options.inline = <span class="literal">true</span>
<div class="content"><div class='highlight'><pre><span class="hljs-keyword">if</span> btoa? <span class="hljs-keyword">and</span> JSON? <span class="hljs-keyword">and</span> unescape? <span class="hljs-keyword">and</span> encodeURIComponent?
<span class="hljs-function"><span class="hljs-title">compile</span> = <span class="hljs-params">(code, options = {})</span> -&gt;</span>
options.sourceMap = <span class="hljs-literal">true</span>
options.inline = <span class="hljs-literal">true</span>
{js, v3SourceMap} = CoffeeScript.compile code, options
<span class="string">"<span class="subst">#{js}</span>\n//@ sourceMappingURL=data:application/json;base64,<span class="subst">#{btoa unescape encodeURIComponent v3SourceMap}</span>\n//@ sourceURL=coffeescript"</span></pre></div></div>
<span class="hljs-string">"<span class="hljs-subst">#{js}</span>\n//# sourceMappingURL=data:application/json;base64,<span class="hljs-subst">#{btoa unescape encodeURIComponent v3SourceMap}</span>\n//# sourceURL=coffeescript"</span></pre></div></div>
</li>
@@ -206,27 +208,27 @@ Ported from <a href="https://developer.mozilla.org/en-US/docs/DOM/window.btoa">h
<div class="pilwrap ">
<a class="pilcrow" href="#section-6">&#182;</a>
</div>
<p>Load a remote script from the current domain via XHR.
</p>
<p>Load a remote script from the current domain via XHR.</p>
</div>
<div class="content"><div class='highlight'><pre>CoffeeScript.<span class="function"><span class="title">load</span></span> = (url, callback, options = {}) -&gt;
<div class="content"><div class='highlight'><pre>CoffeeScript.<span class="hljs-function"><span class="hljs-title">load</span> = <span class="hljs-params">(url, callback, options = {}, hold = <span class="hljs-literal">false</span>)</span> -&gt;</span>
options.sourceFiles = [url]
xhr = <span class="keyword">if</span> window.ActiveXObject
<span class="keyword">new</span> window.ActiveXObject(<span class="string">'Microsoft.XMLHTTP'</span>)
<span class="keyword">else</span>
<span class="keyword">new</span> window.XMLHttpRequest()
xhr.open <span class="string">'GET'</span>, url, <span class="literal">true</span>
xhr.overrideMimeType <span class="string">'text/plain'</span> <span class="keyword">if</span> <span class="string">'overrideMimeType'</span> <span class="keyword">of</span> xhr
xhr.<span class="function"><span class="title">onreadystatechange</span></span> = -&gt;
<span class="keyword">if</span> xhr.readyState <span class="keyword">is</span> <span class="number">4</span>
<span class="keyword">if</span> xhr.status <span class="keyword">in</span> [<span class="number">0</span>, <span class="number">200</span>]
CoffeeScript.run xhr.responseText, options
<span class="keyword">else</span>
<span class="keyword">throw</span> <span class="keyword">new</span> Error <span class="string">"Could not load <span class="subst">#{url}</span>"</span>
callback() <span class="keyword">if</span> callback
xhr.send <span class="literal">null</span></pre></div></div>
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>)
<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
xhr.<span class="hljs-function"><span class="hljs-title">onreadystatechange</span> = -&gt;</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>
callback param <span class="hljs-keyword">if</span> callback
xhr.send <span class="hljs-literal">null</span></pre></div></div>
</li>
@@ -239,29 +241,39 @@ Ported from <a href="https://developer.mozilla.org/en-US/docs/DOM/window.btoa">h
</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>.
This happens on page load.
</p>
This happens on page load.</p>
</div>
<div class="content"><div class='highlight'><pre><span class="function"><span class="title">runScripts</span></span> = -&gt;
scripts = window.document.getElementsByTagName <span class="string">'script'</span>
coffeetypes = [<span class="string">'text/coffeescript'</span>, <span class="string">'text/literate-coffeescript'</span>]
coffees = (s <span class="keyword">for</span> s <span class="keyword">in</span> scripts <span class="keyword">when</span> s.type <span class="keyword">in</span> coffeetypes)
index = <span class="number">0</span>
length = coffees.length
<span class="keyword">do</span> <span class="function"><span class="title">execute</span></span> = -&gt;
script = coffees[index++]
mediatype = script?.type
<span class="keyword">if</span> mediatype <span class="keyword">in</span> coffeetypes
options = {literate: mediatype <span class="keyword">is</span> <span class="string">'text/literate-coffeescript'</span>}
<span class="keyword">if</span> script.src
CoffeeScript.load script.src, execute, options
<span class="keyword">else</span>
options.sourceFiles = [<span class="string">'embedded'</span>]
CoffeeScript.run script.innerHTML, options
execute()
<span class="literal">null</span></pre></div></div>
<div class="content"><div class='highlight'><pre><span class="hljs-function"><span class="hljs-title">runScripts</span> = -&gt;</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>]
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> = -&gt;</span>
param = coffees[index]
<span class="hljs-keyword">if</span> param <span class="hljs-keyword">instanceof</span> Array
CoffeeScript.run param...
index++
execute()
<span class="hljs-keyword">for</span> script, i <span class="hljs-keyword">in</span> coffees
<span class="hljs-keyword">do</span> <span class="hljs-function"><span class="hljs-params">(script, i)</span> -&gt;</span>
options = <span class="hljs-attribute">literate</span>: 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>)
<span class="hljs-keyword">if</span> source
CoffeeScript.load source,
<span class="hljs-function"><span class="hljs-params">(param)</span> -&gt;</span>
coffees[i] = param
execute()
options
<span class="hljs-literal">true</span>
<span class="hljs-keyword">else</span>
options.sourceFiles = [<span class="hljs-string">'embedded'</span>]
coffees[i] = [script.innerHTML, options]
execute()</pre></div></div>
</li>
@@ -272,15 +284,14 @@ This happens on page load.
<div class="pilwrap ">
<a class="pilcrow" href="#section-8">&#182;</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.</p>
</div>
<div class="content"><div class='highlight'><pre><span class="keyword">if</span> window.addEventListener
window.addEventListener <span class="string">'DOMContentLoaded'</span>, runScripts, <span class="literal">no</span>
<span class="keyword">else</span>
window.attachEvent <span class="string">'onload'</span>, runScripts</pre></div></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>
</li>

View File

@@ -16,78 +16,85 @@
<a class="large" href="javascript:void(0);">Jump To &hellip;</a>
<a class="small" href="javascript:void(0);">+</a>
<div id="jump_wrapper">
<div id="jump_page">
<div id="jump_page_wrapper">
<div id="jump_page">
<a class="source" href="browser.html">
browser.coffee
</a>
<a class="source" href="browser.html">
browser.coffee
</a>
<a class="source" href="cake.html">
cake.coffee
</a>
<a class="source" href="cake.html">
cake.coffee
</a>
<a class="source" href="coffee-script.html">
coffee-script.coffee
</a>
<a class="source" href="coffee-script.html">
coffee-script.coffee
</a>
<a class="source" href="command.html">
command.coffee
</a>
<a class="source" href="command.html">
command.coffee
</a>
<a class="source" href="grammar.html">
grammar.coffee
</a>
<a class="source" href="grammar.html">
grammar.coffee
</a>
<a class="source" href="helpers.html">
helpers.coffee
</a>
<a class="source" href="helpers.html">
helpers.coffee
</a>
<a class="source" href="index.html">
index.coffee
</a>
<a class="source" href="index.html">
index.coffee
</a>
<a class="source" href="lexer.html">
lexer.coffee
</a>
<a class="source" href="lexer.html">
lexer.coffee
</a>
<a class="source" href="nodes.html">
nodes.coffee
</a>
<a class="source" href="nodes.html">
nodes.coffee
</a>
<a class="source" href="optparse.html">
optparse.coffee
</a>
<a class="source" href="optparse.html">
optparse.coffee
</a>
<a class="source" href="repl.html">
repl.coffee
</a>
<a class="source" href="register.html">
register.coffee
</a>
<a class="source" href="rewriter.html">
rewriter.coffee
</a>
<a class="source" href="repl.html">
repl.coffee
</a>
<a class="source" href="scope.html">
scope.litcoffee
</a>
<a class="source" href="rewriter.html">
rewriter.coffee
</a>
<a class="source" href="sourcemap.html">
sourcemap.litcoffee
</a>
<a class="source" href="scope.html">
scope.litcoffee
</a>
<a class="source" href="sourcemap.html">
sourcemap.litcoffee
</a>
</div>
</div>
</li>
</ul>
@@ -111,12 +118,9 @@
<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="http://github.com/280north/jake">Jake</a>)
for CoffeeScript. You define tasks with names and descriptions in a Cakefile,
and can call them from the command line, or invoke them from other tasks.
</p>
and can call them from the command line, or invoke them from other tasks.</p>
<p>Running <code>cake</code> with no arguments will print out a list of all the tasks in the
current directory&#39;s Cakefile.
</p>
current directorys Cakefile.</p>
</div>
@@ -129,18 +133,15 @@ current directory&#39;s Cakefile.
<div class="pilwrap ">
<a class="pilcrow" href="#section-2">&#182;</a>
</div>
<p>External dependencies.
</p>
<p>External dependencies.</p>
</div>
<div class="content"><div class='highlight'><pre>fs = require <span class="string">'fs'</span>
path = require <span class="string">'path'</span>
helpers = require <span class="string">'./helpers'</span>
optparse = require <span class="string">'./optparse'</span>
CoffeeScript = require <span class="string">'./coffee-script'</span>
existsSync = fs.existsSync <span class="keyword">or</span> path.existsSync</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">'./coffee-script'</span></pre></div></div>
</li>
@@ -151,15 +152,11 @@ existsSync = fs.existsSync <span class="keyword">or</span> path.existsSync</pr
<div class="pilwrap ">
<a class="pilcrow" href="#section-3">&#182;</a>
</div>
<p>Keep track of the list of defined tasks, the accepted options, and so on.
</p>
<p>Register .coffee extension</p>
</div>
<div class="content"><div class='highlight'><pre>tasks = {}
options = {}
switches = []
oparse = <span class="literal">null</span></pre></div></div>
<div class="content"><div class='highlight'><pre>CoffeeScript.register()</pre></div></div>
</li>
@@ -170,12 +167,14 @@ oparse = <span class="literal">null</span></pre></div></div>
<div class="pilwrap ">
<a class="pilcrow" href="#section-4">&#182;</a>
</div>
<p>Mixin the top-level Cake functions for Cakefiles to use directly.
</p>
<p>Keep track of the list of defined tasks, the accepted options, and so on.</p>
</div>
<div class="content"><div class='highlight'><pre>helpers.extend global,</pre></div></div>
<div class="content"><div class='highlight'><pre>tasks = {}
options = {}
switches = []
oparse = <span class="hljs-literal">null</span></pre></div></div>
</li>
@@ -186,15 +185,11 @@ oparse = <span class="literal">null</span></pre></div></div>
<div class="pilwrap ">
<a class="pilcrow" href="#section-5">&#182;</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>
<p>Mixin the top-level Cake functions for Cakefiles to use directly.</p>
</div>
<div class="content"><div class='highlight'><pre> task: (name, description, action) -&gt;
[action, description] = [description, action] <span class="keyword">unless</span> action
tasks[name] = {name, description, action}</pre></div></div>
<div class="content"><div class='highlight'><pre>helpers.extend <span class="hljs-built_in">global</span>,</pre></div></div>
</li>
@@ -205,15 +200,14 @@ and the function to run as the action itself.
<div class="pilwrap ">
<a class="pilcrow" href="#section-6">&#182;</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
as the first argument to the action.
</p>
<p>Define a Cake task with a short name, an optional sentence description,
and the function to run as the action itself.</p>
</div>
<div class="content"><div class='highlight'><pre> option: (letter, flag, description) -&gt;
switches.push [letter, flag, description]</pre></div></div>
<div class="content"><div class='highlight'><pre> <span class="hljs-attribute">task</span>: <span class="hljs-function"><span class="hljs-params">(name, description, action)</span> -&gt;</span>
[action, description] = [description, action] <span class="hljs-keyword">unless</span> action
tasks[name] = {name, description, action}</pre></div></div>
</li>
@@ -224,14 +218,14 @@ as the first argument to the action.
<div class="pilwrap ">
<a class="pilcrow" href="#section-7">&#182;</a>
</div>
<p>Invoke another task in the current Cakefile.
</p>
<p>Define an option that the Cakefile accepts. The parsed options hash,
containing all of the command-line options passed, will be made available
as the first argument to the action.</p>
</div>
<div class="content"><div class='highlight'><pre> invoke: (name) -&gt;
missingTask name <span class="keyword">unless</span> tasks[name]
tasks[name].action options</pre></div></div>
<div class="content"><div class='highlight'><pre> <span class="hljs-attribute">option</span>: <span class="hljs-function"><span class="hljs-params">(letter, flag, description)</span> -&gt;</span>
switches.push [letter, flag, description]</pre></div></div>
</li>
@@ -242,26 +236,13 @@ as the first argument to the action.
<div class="pilwrap ">
<a class="pilcrow" href="#section-8">&#182;</a>
</div>
<p>Run <code>cake</code>. Executes all of the tasks you pass, in order. Note that Node&#39;s
asynchrony may cause tasks to execute in a different order than you&#39;d expect.
If no tasks are passed, print the help screen. Keep a reference to the
original directory name, when running Cake tasks from subdirectories.
</p>
<p>Invoke another task in the current Cakefile.</p>
</div>
<div class="content"><div class='highlight'><pre>exports.<span class="function"><span class="title">run</span></span> = -&gt;
global.__originalDirname = fs.realpathSync <span class="string">'.'</span>
process.chdir cakefileDirectory __originalDirname
args = process.argv[<span class="number">2.</span>.]
CoffeeScript.run fs.readFileSync(<span class="string">'Cakefile'</span>).toString(), filename: <span class="string">'Cakefile'</span>
oparse = <span class="keyword">new</span> optparse.OptionParser switches
<span class="keyword">return</span> printTasks() <span class="keyword">unless</span> args.length
<span class="keyword">try</span>
options = oparse.parse(args)
<span class="keyword">catch</span> e
<span class="keyword">return</span> fatalError <span class="string">"<span class="subst">#{e}</span>"</span>
invoke arg <span class="keyword">for</span> arg <span class="keyword">in</span> options.arguments</pre></div></div>
<div class="content"><div class='highlight'><pre> <span class="hljs-attribute">invoke</span>: <span class="hljs-function"><span class="hljs-params">(name)</span> -&gt;</span>
missingTask name <span class="hljs-keyword">unless</span> tasks[name]
tasks[name].action options</pre></div></div>
</li>
@@ -272,21 +253,25 @@ original directory name, when running Cake tasks from subdirectories.
<div class="pilwrap ">
<a class="pilcrow" href="#section-9">&#182;</a>
</div>
<p>Display the list of Cake tasks in a format similar to <code>rake -T</code>
</p>
<p>Run <code>cake</code>. Executes all of the tasks you pass, in order. Note that Nodes
asynchrony may cause tasks to execute in a different order than youd expect.
If no tasks are passed, print the help screen. Keep a reference to the
original directory name, when running Cake tasks from subdirectories.</p>
</div>
<div class="content"><div class='highlight'><pre><span class="function"><span class="title">printTasks</span></span> = -&gt;
relative = path.relative <span class="keyword">or</span> path.resolve
cakefilePath = path.join relative(__originalDirname, process.cwd()), <span class="string">'Cakefile'</span>
console.log <span class="string">"<span class="subst">#{cakefilePath}</span> defines the following tasks:\n"</span>
<span class="keyword">for</span> name, task <span class="keyword">of</span> tasks
spaces = <span class="number">20</span> - name.length
spaces = <span class="keyword">if</span> spaces &gt; <span class="number">0</span> <span class="keyword">then</span> Array(spaces + <span class="number">1</span>).join(<span class="string">' '</span>) <span class="keyword">else</span> <span class="string">''</span>
desc = <span class="keyword">if</span> task.description <span class="keyword">then</span> <span class="string">"# <span class="subst">#{task.description}</span>"</span> <span class="keyword">else</span> <span class="string">''</span>
console.log <span class="string">"cake <span class="subst">#{name}</span><span class="subst">#{spaces}</span> <span class="subst">#{desc}</span>"</span>
console.log oparse.help() <span class="keyword">if</span> switches.length</pre></div></div>
<div class="content"><div class='highlight'><pre><span class="hljs-built_in">exports</span>.<span class="hljs-function"><span class="hljs-title">run</span> = -&gt;</span>
<span class="hljs-built_in">global</span>.__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(), <span class="hljs-attribute">filename</span>: <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>
invoke arg <span class="hljs-keyword">for</span> arg <span class="hljs-keyword">in</span> options.arguments</pre></div></div>
</li>
@@ -297,17 +282,20 @@ original directory name, when running Cake tasks from subdirectories.
<div class="pilwrap ">
<a class="pilcrow" href="#section-10">&#182;</a>
</div>
<p>Print an error and exit when attempting to use an invalid task/option.
</p>
<p>Display the list of Cake tasks in a format similar to <code>rake -T</code></p>
</div>
<div class="content"><div class='highlight'><pre><span class="function"><span class="title">fatalError</span></span> = (message) -&gt;
console.error message + <span class="string">'\n'</span>
console.log <span class="string">'To see a list of all tasks/options, run "cake"'</span>
process.exit <span class="number">1</span>
<span class="function"><span class="title">missingTask</span></span> = (task) -&gt; fatalError <span class="string">"No such task: <span class="subst">#{task}</span>"</span></pre></div></div>
<div class="content"><div class='highlight'><pre><span class="hljs-function"><span class="hljs-title">printTasks</span> = -&gt;</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>
<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 &gt; <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>
</li>
@@ -318,17 +306,36 @@ original directory name, when running Cake tasks from subdirectories.
<div class="pilwrap ">
<a class="pilcrow" href="#section-11">&#182;</a>
</div>
<p>When <code>cake</code> is invoked, search in the current and all parent directories
to find the relevant Cakefile.
</p>
<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="function"><span class="title">cakefileDirectory</span></span> = (dir) -&gt;
<span class="keyword">return</span> dir <span class="keyword">if</span> existsSync path.join dir, <span class="string">'Cakefile'</span>
parent = path.normalize path.join dir, <span class="string">'..'</span>
<span class="keyword">return</span> cakefileDirectory parent <span class="keyword">unless</span> parent <span class="keyword">is</span> dir
<span class="keyword">throw</span> <span class="keyword">new</span> Error <span class="string">"Cakefile not found in <span class="subst">#{process.cwd()}</span>"</span></pre></div></div>
<div class="content"><div class='highlight'><pre><span class="hljs-function"><span class="hljs-title">fatalError</span> = <span class="hljs-params">(message)</span> -&gt;</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>
process.exit <span class="hljs-number">1</span>
<span class="hljs-function"><span class="hljs-title">missingTask</span> = <span class="hljs-params">(task)</span> -&gt;</span> fatalError <span class="hljs-string">"No such task: <span class="hljs-subst">#{task}</span>"</span></pre></div></div>
</li>
<li id="section-12">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-12">&#182;</a>
</div>
<p>When <code>cake</code> is invoked, search in the current and all parent directories
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> -&gt;</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>
</li>

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -21,11 +21,11 @@
}
@font-face {
font-family: 'novecento-bold';
src: url('public/fonts/novecento-bold.eot');
src: url('public/fonts/novecento-bold.eot?#iefix') format('embedded-opentype'),
url('public/fonts/novecento-bold.woff') format('woff'),
url('public/fonts/novecento-bold.ttf') format('truetype');
font-family: 'roboto-black';
src: url('public/fonts/roboto-black.eot');
src: url('public/fonts/roboto-black.eot?#iefix') format('embedded-opentype'),
url('public/fonts/roboto-black.woff') format('woff'),
url('public/fonts/roboto-black.ttf') format('truetype');
font-weight: normal;
font-style: normal;
}
@@ -67,7 +67,7 @@ h1, h2, h3, h4, h5, h6 {
color: #112233;
line-height: 1em;
font-weight: normal;
font-family: "novecento-bold";
font-family: "roboto-black";
text-transform: uppercase;
margin: 30px 0 15px 0;
}
@@ -75,10 +75,13 @@ h1, h2, h3, h4, h5, h6 {
h1 {
margin-top: 40px;
}
h2 {
font-size: 1.26em;
}
hr {
border: 0;
background: 1px solid #ddd;
background: 1px #ddd;
height: 1px;
margin: 20px 0;
}
@@ -180,9 +183,18 @@ ul.sections > li > div {
display: block;
}
#jump_page_wrapper{
position: fixed;
right: 0;
top: 0;
bottom: 0;
}
#jump_page {
padding: 5px 0 3px;
margin: 0 0 25px 25px;
max-height: 100%;
overflow: auto;
}
#jump_page .source {
@@ -213,7 +225,6 @@ ul.sections > li > div {
}
ul.sections > li > div.content {
background: #f5f5ff;
overflow-x:auto;
-webkit-box-shadow: inset 0 0 5px #e5e5ee;
box-shadow: inset 0 0 5px #e5e5ee;
@@ -314,7 +325,6 @@ ul.sections > li > div {
ul.sections > li > div.content {
padding: 13px;
vertical-align: top;
background: #f5f5ff;
border: none;
-webkit-box-shadow: none;
box-shadow: none;
@@ -384,126 +394,125 @@ pre code {
background: #f8f8ff
}
pre .comment,
pre .template_comment,
pre .diff .header,
pre .javadoc {
pre .hljs-comment,
pre .hljs-template_comment,
pre .hljs-diff .hljs-header,
pre .hljs-javadoc {
color: #408080;
font-style: italic
}
pre .keyword,
pre .assignment,
pre .literal,
pre .css .rule .keyword,
pre .winutils,
pre .javascript .title,
pre .lisp .title,
pre .subst,
pre .reserved {
pre .hljs-keyword,
pre .hljs-assignment,
pre .hljs-literal,
pre .hljs-css .hljs-rule .hljs-keyword,
pre .hljs-winutils,
pre .hljs-javascript .hljs-title,
pre .hljs-lisp .hljs-title,
pre .hljs-subst {
color: #954121;
/*font-weight: bold*/
}
pre .number,
pre .hexcolor {
pre .hljs-number,
pre .hljs-hexcolor {
color: #40a070
}
pre .string,
pre .tag .value,
pre .phpdoc,
pre .tex .formula {
pre .hljs-string,
pre .hljs-tag .hljs-value,
pre .hljs-phpdoc,
pre .hljs-tex .hljs-formula {
color: #219161;
}
pre .title,
pre .id {
pre .hljs-title,
pre .hljs-id {
color: #19469D;
}
pre .params {
pre .hljs-params {
color: #00F;
}
pre .javascript .title,
pre .lisp .title,
pre .subst {
pre .hljs-javascript .hljs-title,
pre .hljs-lisp .hljs-title,
pre .hljs-subst {
font-weight: normal
}
pre .class .title,
pre .haskell .label,
pre .tex .command {
pre .hljs-class .hljs-title,
pre .hljs-haskell .hljs-label,
pre .hljs-tex .hljs-command {
color: #458;
font-weight: bold
}
pre .tag,
pre .tag .title,
pre .rules .property,
pre .django .tag .keyword {
pre .hljs-tag,
pre .hljs-tag .hljs-title,
pre .hljs-rules .hljs-property,
pre .hljs-django .hljs-tag .hljs-keyword {
color: #000080;
font-weight: normal
}
pre .attribute,
pre .variable,
pre .instancevar,
pre .lisp .body {
pre .hljs-attribute,
pre .hljs-variable,
pre .hljs-instancevar,
pre .hljs-lisp .hljs-body {
color: #008080
}
pre .regexp {
pre .hljs-regexp {
color: #B68
}
pre .class {
pre .hljs-class {
color: #458;
font-weight: bold
}
pre .symbol,
pre .ruby .symbol .string,
pre .ruby .symbol .keyword,
pre .ruby .symbol .keymethods,
pre .lisp .keyword,
pre .tex .special,
pre .input_number {
pre .hljs-symbol,
pre .hljs-ruby .hljs-symbol .hljs-string,
pre .hljs-ruby .hljs-symbol .hljs-keyword,
pre .hljs-ruby .hljs-symbol .hljs-keymethods,
pre .hljs-lisp .hljs-keyword,
pre .hljs-tex .hljs-special,
pre .hljs-input_number {
color: #990073
}
pre .builtin,
pre .constructor,
pre .built_in,
pre .lisp .title {
pre .hljs-builtin,
pre .hljs-constructor,
pre .hljs-built_in,
pre .hljs-lisp .hljs-title {
color: #0086b3
}
pre .preprocessor,
pre .pi,
pre .doctype,
pre .shebang,
pre .cdata {
pre .hljs-preprocessor,
pre .hljs-pi,
pre .hljs-doctype,
pre .hljs-shebang,
pre .hljs-cdata {
color: #999;
font-weight: bold
}
pre .deletion {
pre .hljs-deletion {
background: #fdd
}
pre .addition {
pre .hljs-addition {
background: #dfd
}
pre .diff .change {
pre .hljs-diff .hljs-change {
background: #0086b3
}
pre .chunk {
pre .hljs-chunk {
color: #aaa
}
pre .tex .formula {
pre .hljs-tex .hljs-formula {
opacity: 0.5;
}

File diff suppressed because it is too large Load Diff

View File

@@ -16,78 +16,85 @@
<a class="large" href="javascript:void(0);">Jump To &hellip;</a>
<a class="small" href="javascript:void(0);">+</a>
<div id="jump_wrapper">
<div id="jump_page">
<div id="jump_page_wrapper">
<div id="jump_page">
<a class="source" href="browser.html">
browser.coffee
</a>
<a class="source" href="browser.html">
browser.coffee
</a>
<a class="source" href="cake.html">
cake.coffee
</a>
<a class="source" href="cake.html">
cake.coffee
</a>
<a class="source" href="coffee-script.html">
coffee-script.coffee
</a>
<a class="source" href="coffee-script.html">
coffee-script.coffee
</a>
<a class="source" href="command.html">
command.coffee
</a>
<a class="source" href="command.html">
command.coffee
</a>
<a class="source" href="grammar.html">
grammar.coffee
</a>
<a class="source" href="grammar.html">
grammar.coffee
</a>
<a class="source" href="helpers.html">
helpers.coffee
</a>
<a class="source" href="helpers.html">
helpers.coffee
</a>
<a class="source" href="index.html">
index.coffee
</a>
<a class="source" href="index.html">
index.coffee
</a>
<a class="source" href="lexer.html">
lexer.coffee
</a>
<a class="source" href="lexer.html">
lexer.coffee
</a>
<a class="source" href="nodes.html">
nodes.coffee
</a>
<a class="source" href="nodes.html">
nodes.coffee
</a>
<a class="source" href="optparse.html">
optparse.coffee
</a>
<a class="source" href="optparse.html">
optparse.coffee
</a>
<a class="source" href="repl.html">
repl.coffee
</a>
<a class="source" href="register.html">
register.coffee
</a>
<a class="source" href="rewriter.html">
rewriter.coffee
</a>
<a class="source" href="repl.html">
repl.coffee
</a>
<a class="source" href="scope.html">
scope.litcoffee
</a>
<a class="source" href="rewriter.html">
rewriter.coffee
</a>
<a class="source" href="sourcemap.html">
sourcemap.litcoffee
</a>
<a class="source" href="scope.html">
scope.litcoffee
</a>
<a class="source" href="sourcemap.html">
sourcemap.litcoffee
</a>
</div>
</div>
</li>
</ul>
@@ -108,10 +115,9 @@
<div class="pilwrap ">
<a class="pilcrow" href="#section-1">&#182;</a>
</div>
<p>This file contains the common helper functions that we&#39;d like to share among
<p>This file contains the common helper functions that wed like to share among
the <strong>Lexer</strong>, <strong>Rewriter</strong>, and the <strong>Nodes</strong>. Merge objects, flatten
arrays, count characters, that sort of thing.
</p>
arrays, count characters, that sort of thing.</p>
</div>
@@ -124,13 +130,12 @@ arrays, count characters, that sort of thing.
<div class="pilwrap ">
<a class="pilcrow" href="#section-2">&#182;</a>
</div>
<p>Peek at the beginning of a given string to see if it matches a sequence.
</p>
<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.<span class="function"><span class="title">starts</span></span> = (string, literal, start) -&gt;
literal <span class="keyword">is</span> string.substr start, literal.length</pre></div></div>
<div class="content"><div class='highlight'><pre><span class="hljs-built_in">exports</span>.<span class="hljs-function"><span class="hljs-title">starts</span> = <span class="hljs-params">(string, literal, start)</span> -&gt;</span>
literal <span class="hljs-keyword">is</span> string.substr start, literal.length</pre></div></div>
</li>
@@ -141,14 +146,13 @@ arrays, count characters, that sort of thing.
<div class="pilwrap ">
<a class="pilcrow" href="#section-3">&#182;</a>
</div>
<p>Peek at the end of a given string to see if it matches a sequence.
</p>
<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.<span class="function"><span class="title">ends</span></span> = (string, literal, back) -&gt;
<div class="content"><div class='highlight'><pre><span class="hljs-built_in">exports</span>.<span class="hljs-function"><span class="hljs-title">ends</span> = <span class="hljs-params">(string, literal, back)</span> -&gt;</span>
len = literal.length
literal <span class="keyword">is</span> string.substr string.length - len - (back <span class="keyword">or</span> <span class="number">0</span>), len</pre></div></div>
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>
</li>
@@ -159,12 +163,11 @@ arrays, count characters, that sort of thing.
<div class="pilwrap ">
<a class="pilcrow" href="#section-4">&#182;</a>
</div>
<p>Repeat a string <code>n</code> times.
</p>
<p>Repeat a string <code>n</code> times.</p>
</div>
<div class="content"><div class='highlight'><pre>exports.repeat = <span class="function"><span class="title">repeat</span></span> = (str, n) -&gt;</pre></div></div>
<div class="content"><div class='highlight'><pre><span class="hljs-built_in">exports</span>.repeat = <span class="hljs-function"><span class="hljs-title">repeat</span> = <span class="hljs-params">(str, n)</span> -&gt;</span></pre></div></div>
</li>
@@ -175,15 +178,14 @@ arrays, count characters, that sort of thing.
<div class="pilwrap ">
<a class="pilcrow" href="#section-5">&#182;</a>
</div>
<p>Use clever algorithm to have O(log(n)) string concatenation operations.
</p>
<p>Use clever algorithm to have O(log(n)) string concatenation operations.</p>
</div>
<div class="content"><div class='highlight'><pre> res = <span class="string">''</span>
<span class="keyword">while</span> n &gt; <span class="number">0</span>
res += str <span class="keyword">if</span> n &amp; <span class="number">1</span>
n &gt;&gt;&gt;= <span class="number">1</span>
<div class="content"><div class='highlight'><pre> res = <span class="hljs-string">''</span>
<span class="hljs-keyword">while</span> n &gt; <span class="hljs-number">0</span>
res += str <span class="hljs-keyword">if</span> n &amp; <span class="hljs-number">1</span>
n &gt;&gt;&gt;= <span class="hljs-number">1</span>
str += str
res</pre></div></div>
@@ -196,13 +198,12 @@ arrays, count characters, that sort of thing.
<div class="pilwrap ">
<a class="pilcrow" href="#section-6">&#182;</a>
</div>
<p>Trim out all falsy values from an array.
</p>
<p>Trim out all falsy values from an array.</p>
</div>
<div class="content"><div class='highlight'><pre>exports.<span class="function"><span class="title">compact</span></span> = (array) -&gt;
item <span class="keyword">for</span> item <span class="keyword">in</span> array <span class="keyword">when</span> item</pre></div></div>
<div class="content"><div class='highlight'><pre><span class="hljs-built_in">exports</span>.<span class="hljs-function"><span class="hljs-title">compact</span> = <span class="hljs-params">(array)</span> -&gt;</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>
@@ -213,15 +214,14 @@ arrays, count characters, that sort of thing.
<div class="pilwrap ">
<a class="pilcrow" href="#section-7">&#182;</a>
</div>
<p>Count the number of occurrences of a string in a string.
</p>
<p>Count the number of occurrences of a string in a string.</p>
</div>
<div class="content"><div class='highlight'><pre>exports.<span class="function"><span class="title">count</span></span> = (string, substr) -&gt;
num = pos = <span class="number">0</span>
<span class="keyword">return</span> <span class="number">1</span>/<span class="number">0</span> <span class="keyword">unless</span> substr.length
num++ <span class="keyword">while</span> pos = <span class="number">1</span> + string.indexOf substr, pos
<div class="content"><div class='highlight'><pre><span class="hljs-built_in">exports</span>.<span class="hljs-function"><span class="hljs-title">count</span> = <span class="hljs-params">(string, substr)</span> -&gt;</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
num</pre></div></div>
</li>
@@ -235,12 +235,11 @@ arrays, count characters, that sort of thing.
</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
options hash to propagate down the tree without polluting other branches.
</p>
options hash to propagate down the tree without polluting other branches.</p>
</div>
<div class="content"><div class='highlight'><pre>exports.<span class="function"><span class="title">merge</span></span> = (options, overrides) -&gt;
<div class="content"><div class='highlight'><pre><span class="hljs-built_in">exports</span>.<span class="hljs-function"><span class="hljs-title">merge</span> = <span class="hljs-params">(options, overrides)</span> -&gt;</span>
extend (extend {}, options), overrides</pre></div></div>
</li>
@@ -252,13 +251,12 @@ options hash to propagate down the tree without polluting other branches.
<div class="pilwrap ">
<a class="pilcrow" href="#section-9">&#182;</a>
</div>
<p>Extend a source object with the properties of another object (shallow copy).
</p>
<p>Extend a source object with the properties of another object (shallow copy).</p>
</div>
<div class="content"><div class='highlight'><pre>extend = exports.<span class="function"><span class="title">extend</span></span> = (object, properties) -&gt;
<span class="keyword">for</span> key, val <span class="keyword">of</span> properties
<div class="content"><div class='highlight'><pre>extend = <span class="hljs-built_in">exports</span>.<span class="hljs-function"><span class="hljs-title">extend</span> = <span class="hljs-params">(object, properties)</span> -&gt;</span>
<span class="hljs-keyword">for</span> key, val <span class="hljs-keyword">of</span> properties
object[key] = val
object</pre></div></div>
@@ -272,17 +270,16 @@ options hash to propagate down the tree without polluting other branches.
<a class="pilcrow" href="#section-10">&#182;</a>
</div>
<p>Return a flattened version of an array.
Handy for getting a list of <code>children</code> from the nodes.
</p>
Handy for getting a list of <code>children</code> from the nodes.</p>
</div>
<div class="content"><div class='highlight'><pre>exports.flatten = <span class="function"><span class="title">flatten</span></span> = (array) -&gt;
<div class="content"><div class='highlight'><pre><span class="hljs-built_in">exports</span>.flatten = <span class="hljs-function"><span class="hljs-title">flatten</span> = <span class="hljs-params">(array)</span> -&gt;</span>
flattened = []
<span class="keyword">for</span> element <span class="keyword">in</span> array
<span class="keyword">if</span> element <span class="keyword">instanceof</span> Array
<span class="hljs-keyword">for</span> element <span class="hljs-keyword">in</span> array
<span class="hljs-keyword">if</span> element <span class="hljs-keyword">instanceof</span> Array
flattened = flattened.concat flatten element
<span class="keyword">else</span>
<span class="hljs-keyword">else</span>
flattened.push element
flattened</pre></div></div>
@@ -296,14 +293,13 @@ Handy for getting a list of <code>children</code> from the nodes.
<a class="pilcrow" href="#section-11">&#182;</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>
looking for a particular method in an options hash.</p>
</div>
<div class="content"><div class='highlight'><pre>exports.<span class="function"><span class="title">del</span></span> = (obj, key) -&gt;
<div class="content"><div class='highlight'><pre><span class="hljs-built_in">exports</span>.<span class="hljs-function"><span class="hljs-title">del</span> = <span class="hljs-params">(obj, key)</span> -&gt;</span>
val = obj[key]
<span class="keyword">delete</span> obj[key]
<span class="hljs-keyword">delete</span> obj[key]
val</pre></div></div>
</li>
@@ -315,12 +311,13 @@ looking for a particular method in an options hash.
<div class="pilwrap ">
<a class="pilcrow" href="#section-12">&#182;</a>
</div>
<p>Gets the last item of an array(-like) object.
</p>
<p>Typical Array::some</p>
</div>
<div class="content"><div class='highlight'><pre>exports.last = <span class="function"><span class="title">last</span></span> = (array, back) -&gt; array[array.length - (back <span class="keyword">or</span> <span class="number">0</span>) - <span class="number">1</span>]</pre></div></div>
<div class="content"><div class='highlight'><pre><span class="hljs-built_in">exports</span>.some = <span class="hljs-attribute">Array</span>::some ? <span class="hljs-function"><span class="hljs-params">(fn)</span> -&gt;</span>
<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
<span class="hljs-literal">false</span></pre></div></div>
</li>
@@ -331,14 +328,22 @@ looking for a particular method in an options hash.
<div class="pilwrap ">
<a class="pilcrow" href="#section-13">&#182;</a>
</div>
<p>Typical Array::some
</p>
<p>Simple function for inverting Literate CoffeeScript code by putting the
documentation in comments, producing a string of CoffeeScript code that
can be compiled “normally”.</p>
</div>
<div class="content"><div class='highlight'><pre>exports.some = Array::some ? (fn) -&gt;
<span class="keyword">return</span> <span class="literal">true</span> <span class="keyword">for</span> e <span class="keyword">in</span> <span class="keyword">this</span> <span class="keyword">when</span> fn e
<span class="literal">false</span></pre></div></div>
<div class="content"><div class='highlight'><pre><span class="hljs-built_in">exports</span>.<span class="hljs-function"><span class="hljs-title">invertLiterate</span> = <span class="hljs-params">(code)</span> -&gt;</span>
maybe_code = <span class="hljs-literal">true</span>
lines = <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> maybe_code <span class="hljs-keyword">and</span> <span class="hljs-regexp">/^([ ]{4}|[ ]{0,3}\t)/</span>.test line
line
<span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> maybe_code = <span class="hljs-regexp">/^\s*$/</span>.test line
line
<span class="hljs-keyword">else</span>
<span class="hljs-string">'# '</span> + line
lines.join <span class="hljs-string">'\n'</span></pre></div></div>
</li>
@@ -349,23 +354,19 @@ looking for a particular method in an options hash.
<div class="pilwrap ">
<a class="pilcrow" href="#section-14">&#182;</a>
</div>
<p>Simple function for inverting Literate CoffeeScript code by putting the
documentation in comments, producing a string of CoffeeScript code that
can be compiled &quot;normally&quot;.
</p>
<p>Merge two jison-style location data objects together.
If <code>last</code> is not provided, this will simply return <code>first</code>.</p>
</div>
<div class="content"><div class='highlight'><pre>exports.<span class="function"><span class="title">invertLiterate</span></span> = (code) -&gt;
maybe_code = <span class="literal">true</span>
lines = <span class="keyword">for</span> line <span class="keyword">in</span> code.split(<span class="string">'\n'</span>)
<span class="keyword">if</span> maybe_code <span class="keyword">and</span> <span class="regexp">/^([ ]{4}|[ ]{0,3}\t)/</span>.test line
line
<span class="keyword">else</span> <span class="keyword">if</span> maybe_code = <span class="regexp">/^\s*$/</span>.test line
line
<span class="keyword">else</span>
<span class="string">'# '</span> + line
lines.join <span class="string">'\n'</span></pre></div></div>
<div class="content"><div class='highlight'><pre><span class="hljs-function"><span class="hljs-title">buildLocationData</span> = <span class="hljs-params">(first, last)</span> -&gt;</span>
<span class="hljs-keyword">if</span> <span class="hljs-keyword">not</span> last
first
<span class="hljs-keyword">else</span>
<span class="hljs-attribute">first_line</span>: first.first_line
<span class="hljs-attribute">first_column</span>: first.first_column
<span class="hljs-attribute">last_line</span>: last.last_line
<span class="hljs-attribute">last_column</span>: last.last_column</pre></div></div>
</li>
@@ -376,20 +377,18 @@ can be compiled &quot;normally&quot;.
<div class="pilwrap ">
<a class="pilcrow" href="#section-15">&#182;</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>
<p>This returns a function which takes an object as a parameter, and if that
object is an AST node, updates that objects locationData.
The object is returned either way.</p>
</div>
<div class="content"><div class='highlight'><pre><span class="function"><span class="title">buildLocationData</span></span> = (first, last) -&gt;
<span class="keyword">if</span> <span class="keyword">not</span> last
first
<span class="keyword">else</span>
first_line: first.first_line
first_column: first.first_column
last_line: last.last_line
last_column: last.last_column</pre></div></div>
<div class="content"><div class='highlight'><pre><span class="hljs-built_in">exports</span>.<span class="hljs-function"><span class="hljs-title">addLocationDataFn</span> = <span class="hljs-params">(first, last)</span> -&gt;</span>
<span class="hljs-function"><span class="hljs-params">(obj)</span> -&gt;</span>
<span class="hljs-keyword">if</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-string">'updateLocationDataIfMissing'</span>])
obj.updateLocationDataIfMissing buildLocationData(first, last)
<span class="hljs-keyword">return</span> obj</pre></div></div>
</li>
@@ -400,19 +399,20 @@ If <code>last</code> is not provided, this will simply return <code>first</code>
<div class="pilwrap ">
<a class="pilcrow" href="#section-16">&#182;</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&#39;s locationData.
The object is returned either way.
</p>
<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>exports.<span class="function"><span class="title">addLocationDataFn</span></span> = (first, last) -&gt;
(obj) -&gt;
<span class="keyword">if</span> ((<span class="keyword">typeof</span> obj) <span class="keyword">is</span> <span class="string">'object'</span>) <span class="keyword">and</span> (!!obj[<span class="string">'updateLocationDataIfMissing'</span>])
obj.updateLocationDataIfMissing buildLocationData(first, last)
<div class="content"><div class='highlight'><pre><span class="hljs-built_in">exports</span>.<span class="hljs-function"><span class="hljs-title">locationDataToString</span> = <span class="hljs-params">(obj)</span> -&gt;</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="keyword">return</span> obj</pre></div></div>
<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>
@@ -423,21 +423,19 @@ The object is returned either way.
<div class="pilwrap ">
<a class="pilcrow" href="#section-17">&#182;</a>
</div>
<p>Convert jison location data to a string.
<code>obj</code> can be a token, or a locationData.
</p>
<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>exports.<span class="function"><span class="title">locationDataToString</span></span> = (obj) -&gt;
<span class="keyword">if</span> (<span class="string">"2"</span> <span class="keyword">of</span> obj) <span class="keyword">and</span> (<span class="string">"first_line"</span> <span class="keyword">of</span> obj[<span class="number">2</span>]) <span class="keyword">then</span> locationData = obj[<span class="number">2</span>]
<span class="keyword">else</span> <span class="keyword">if</span> <span class="string">"first_line"</span> <span class="keyword">of</span> obj <span class="keyword">then</span> locationData = obj
<span class="keyword">if</span> locationData
<span class="string">"<span class="subst">#{locationData.first_line + <span class="number">1</span>}</span>:<span class="subst">#{locationData.first_column + <span class="number">1</span>}</span>-"</span> +
<span class="string">"<span class="subst">#{locationData.last_line + <span class="number">1</span>}</span>:<span class="subst">#{locationData.last_column + <span class="number">1</span>}</span>"</span>
<span class="keyword">else</span>
<span class="string">"No location data"</span></pre></div></div>
<div class="content"><div class='highlight'><pre><span class="hljs-built_in">exports</span>.<span class="hljs-function"><span class="hljs-title">baseFileName</span> = <span class="hljs-params">(file, stripExt = <span class="hljs-literal">no</span>, useWinPathSep = <span class="hljs-literal">no</span>)</span> -&gt;</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>) &gt;= <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 &gt; <span class="hljs-number">1</span>
parts.join(<span class="hljs-string">'.'</span>)</pre></div></div>
</li>
@@ -448,20 +446,11 @@ The object is returned either way.
<div class="pilwrap ">
<a class="pilcrow" href="#section-18">&#182;</a>
</div>
<p>A <code>.coffee.md</code> compatible version of <code>basename</code>, that returns the file sans-extension.
</p>
<p>Determine if a filename represents a CoffeeScript file.</p>
</div>
<div class="content"><div class='highlight'><pre>exports.<span class="function"><span class="title">baseFileName</span></span> = (file, stripExt = <span class="literal">no</span>, useWinPathSep = <span class="literal">no</span>) -&gt;
pathSep = <span class="keyword">if</span> useWinPathSep <span class="keyword">then</span> <span class="regexp">/\\|\// else /\//</span>
parts = file.split(pathSep)
file = parts[parts.length - <span class="number">1</span>]
<span class="keyword">return</span> file <span class="keyword">unless</span> stripExt
parts = file.split(<span class="string">'.'</span>)
parts.pop()
parts.pop() <span class="keyword">if</span> parts[parts.length - <span class="number">1</span>] <span class="keyword">is</span> <span class="string">'coffee'</span> <span class="keyword">and</span> parts.length &gt; <span class="number">1</span>
parts.join(<span class="string">'.'</span>)</pre></div></div>
<div class="content"><div class='highlight'><pre><span class="hljs-built_in">exports</span>.<span class="hljs-function"><span class="hljs-title">isCoffee</span> = <span class="hljs-params">(file)</span> -&gt;</span> <span class="hljs-regexp">/\.((lit)?coffee|coffee\.md)$/</span>.test file</pre></div></div>
</li>
@@ -472,12 +461,11 @@ The object is returned either way.
<div class="pilwrap ">
<a class="pilcrow" href="#section-19">&#182;</a>
</div>
<p>Determine if a filename represents a CoffeeScript file.
</p>
<p>Determine if a filename represents a Literate CoffeeScript file.</p>
</div>
<div class="content"><div class='highlight'><pre>exports.<span class="function"><span class="title">isCoffee</span></span> = (file) -&gt; <span class="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>.<span class="hljs-function"><span class="hljs-title">isLiterate</span> = <span class="hljs-params">(file)</span> -&gt;</span> <span class="hljs-regexp">/\.(litcoffee|coffee\.md)$/</span>.test file</pre></div></div>
</li>
@@ -488,12 +476,17 @@ The object is returned either way.
<div class="pilwrap ">
<a class="pilcrow" href="#section-20">&#182;</a>
</div>
<p>Determine if a filename represents a Literate CoffeeScript file.
</p>
<p>Throws a SyntaxError from a given location.
The errors <code>toString</code> will return an error message following the “standard”
format <filename>:<line>:<col>: <message> plus the line with the error and a
marker showing where the error is.</p>
</div>
<div class="content"><div class='highlight'><pre>exports.<span class="function"><span class="title">isLiterate</span></span> = (file) -&gt; <span class="regexp">/\.(litcoffee|coffee\.md)$/</span>.test file</pre></div></div>
<div class="content"><div class='highlight'><pre><span class="hljs-built_in">exports</span>.<span class="hljs-function"><span class="hljs-title">throwSyntaxError</span> = <span class="hljs-params">(message, location)</span> -&gt;</span>
error = <span class="hljs-keyword">new</span> SyntaxError message
error.location = location
error.toString = syntaxErrorToString</pre></div></div>
</li>
@@ -504,18 +497,15 @@ The object is returned either way.
<div class="pilwrap ">
<a class="pilcrow" href="#section-21">&#182;</a>
</div>
<p>Throws a SyntaxError with a source file location data attached to it in a
property called <code>location</code>.
</p>
<p>Instead of showing the compilers stacktrace, show our custom error message
(this is useful when the error bubbles up in Node.js applications that
compile CoffeeScript for example).</p>
</div>
<div class="content"><div class='highlight'><pre>exports.<span class="function"><span class="title">throwSyntaxError</span></span> = (message, location) -&gt;
location.last_line ?= location.first_line
location.last_column ?= location.first_column
error = <span class="keyword">new</span> SyntaxError message
error.location = location
<span class="keyword">throw</span> error</pre></div></div>
<div class="content"><div class='highlight'><pre> error.stack = error.toString()
<span class="hljs-keyword">throw</span> error</pre></div></div>
</li>
@@ -526,20 +516,12 @@ property called <code>location</code>.
<div class="pilwrap ">
<a class="pilcrow" href="#section-22">&#182;</a>
</div>
<p>Creates a nice error message like, following the &quot;standard&quot; format
</p>
<p><filename>:<line>:<col>: <message> plus the line with the error and a marker
showing where the error is.
</p>
<p>Update a compiler SyntaxError with source code information if it didnt have
it already.</p>
</div>
<div class="content"><div class='highlight'><pre>exports.<span class="function"><span class="title">prettyErrorMessage</span></span> = (error, fileName, code, useColors) -&gt;
<span class="keyword">return</span> error.stack <span class="keyword">or</span> <span class="string">"<span class="subst">#{error}</span>"</span> <span class="keyword">unless</span> error.location
{first_line, first_column, last_line, last_column} = error.location
codeLine = code.split(<span class="string">'\n'</span>)[first_line]
start = first_column</pre></div></div>
<div class="content"><div class='highlight'><pre><span class="hljs-built_in">exports</span>.<span class="hljs-function"><span class="hljs-title">updateSyntaxError</span> = <span class="hljs-params">(error, code, filename)</span> -&gt;</span></pre></div></div>
</li>
@@ -550,24 +532,26 @@ showing where the error is.
<div class="pilwrap ">
<a class="pilcrow" href="#section-23">&#182;</a>
</div>
<p>Show only the first line on multi-line errors.
</p>
<p>Avoid screwing up the <code>stack</code> property of other errors (i.e. possible bugs).</p>
</div>
<div class="content"><div class='highlight'><pre> end = <span class="keyword">if</span> first_line <span class="keyword">is</span> last_line <span class="keyword">then</span> last_column + <span class="number">1</span> <span class="keyword">else</span> codeLine.length
marker = repeat(<span class="string">' '</span>, start) + repeat(<span class="string">'^'</span>, end - start)
<div class="content"><div class='highlight'><pre> <span class="hljs-keyword">if</span> error.toString <span class="hljs-keyword">is</span> syntaxErrorToString
error.code <span class="hljs-keyword">or</span>= code
error.filename <span class="hljs-keyword">or</span>= filename
error.stack = error.toString()
error
<span class="keyword">if</span> useColors
<span class="function"><span class="title">colorize</span></span> = (str) -&gt; <span class="string">"\x1B[1;31m<span class="subst">#{str}</span>\x1B[0m"</span>
codeLine = codeLine[...start] + colorize(codeLine[start...end]) + codeLine[end..]
marker = colorize marker
<span class="hljs-function"><span class="hljs-title">syntaxErrorToString</span> = -&gt;</span>
<span class="hljs-keyword">return</span> <span class="hljs-attribute">Error</span>::toString.call @ <span class="hljs-keyword">unless</span> <span class="hljs-property">@code</span> <span class="hljs-keyword">and</span> <span class="hljs-property">@location</span>
message = <span class="string">"""
<span class="subst">#{fileName}</span>:<span class="subst">#{first_line + <span class="number">1</span>}</span>:<span class="subst">#{first_column + <span class="number">1</span>}</span>: error: <span class="subst">#{error.message}</span>
<span class="subst">#{codeLine}</span>
<span class="subst">#{marker}</span>
"""</span></pre></div></div>
{first_line, first_column, last_line, last_column} = <span class="hljs-property">@location</span>
last_line ?= first_line
last_column ?= first_column
filename = <span class="hljs-property">@filename</span> <span class="hljs-keyword">or</span> <span class="hljs-string">'[stdin]'</span>
codeLine = <span class="hljs-property">@code</span>.split(<span class="hljs-string">'\n'</span>)[first_line]
start = first_column</pre></div></div>
</li>
@@ -578,14 +562,47 @@ showing where the error is.
<div class="pilwrap ">
<a class="pilcrow" href="#section-24">&#182;</a>
</div>
<p>Uncomment to add stacktrace.
message += &quot;\n#{error.stack}&quot;
</p>
<p>Show only the first line on multi-line errors.</p>
</div>
<div class="content"><div class='highlight'><pre>
message</pre></div></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>
</li>
<li id="section-25">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-25">&#182;</a>
</div>
<p>Check to see if were running on a color-enabled TTY.</p>
</div>
<div class="content"><div class='highlight'><pre> <span class="hljs-keyword">if</span> process?
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> <span class="hljs-property">@colorful</span> ? colorsEnabled
<span class="hljs-function"><span class="hljs-title">colorize</span> = <span class="hljs-params">(str)</span> -&gt;</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-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">#{<span class="hljs-property">@message</span>}</span>
<span class="hljs-subst">#{codeLine}</span>
<span class="hljs-subst">#{marker}</span>
"""</span>
<span class="hljs-built_in">exports</span>.<span class="hljs-function"><span class="hljs-title">nameWhitespaceCharacter</span> = <span class="hljs-params">(string)</span> -&gt;</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>
</li>

View File

@@ -16,78 +16,85 @@
<a class="large" href="javascript:void(0);">Jump To &hellip;</a>
<a class="small" href="javascript:void(0);">+</a>
<div id="jump_wrapper">
<div id="jump_page">
<div id="jump_page_wrapper">
<div id="jump_page">
<a class="source" href="browser.html">
browser.coffee
</a>
<a class="source" href="browser.html">
browser.coffee
</a>
<a class="source" href="cake.html">
cake.coffee
</a>
<a class="source" href="cake.html">
cake.coffee
</a>
<a class="source" href="coffee-script.html">
coffee-script.coffee
</a>
<a class="source" href="coffee-script.html">
coffee-script.coffee
</a>
<a class="source" href="command.html">
command.coffee
</a>
<a class="source" href="command.html">
command.coffee
</a>
<a class="source" href="grammar.html">
grammar.coffee
</a>
<a class="source" href="grammar.html">
grammar.coffee
</a>
<a class="source" href="helpers.html">
helpers.coffee
</a>
<a class="source" href="helpers.html">
helpers.coffee
</a>
<a class="source" href="index.html">
index.coffee
</a>
<a class="source" href="index.html">
index.coffee
</a>
<a class="source" href="lexer.html">
lexer.coffee
</a>
<a class="source" href="lexer.html">
lexer.coffee
</a>
<a class="source" href="nodes.html">
nodes.coffee
</a>
<a class="source" href="nodes.html">
nodes.coffee
</a>
<a class="source" href="optparse.html">
optparse.coffee
</a>
<a class="source" href="optparse.html">
optparse.coffee
</a>
<a class="source" href="repl.html">
repl.coffee
</a>
<a class="source" href="register.html">
register.coffee
</a>
<a class="source" href="rewriter.html">
rewriter.coffee
</a>
<a class="source" href="repl.html">
repl.coffee
</a>
<a class="source" href="scope.html">
scope.litcoffee
</a>
<a class="source" href="rewriter.html">
rewriter.coffee
</a>
<a class="source" href="sourcemap.html">
sourcemap.litcoffee
</a>
<a class="source" href="scope.html">
scope.litcoffee
</a>
<a class="source" href="sourcemap.html">
sourcemap.litcoffee
</a>
</div>
</div>
</li>
</ul>
@@ -108,12 +115,11 @@
<div class="pilwrap ">
<a class="pilcrow" href="#section-1">&#182;</a>
</div>
<p>Loader for CoffeeScript as a Node.js library.
</p>
<p>Loader for CoffeeScript as a Node.js library.</p>
</div>
<div class="content"><div class='highlight'><pre>exports[key] = val <span class="keyword">for</span> key, val <span class="keyword">of</span> require <span class="string">'./coffee-script'</span></pre></div></div>
<div class="content"><div class='highlight'><pre><span class="hljs-built_in">exports</span>[key] = val <span class="hljs-keyword">for</span> key, val <span class="hljs-keyword">of</span> <span class="hljs-built_in">require</span> <span class="hljs-string">'./coffee-script'</span></pre></div></div>
</li>

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -16,78 +16,85 @@
<a class="large" href="javascript:void(0);">Jump To &hellip;</a>
<a class="small" href="javascript:void(0);">+</a>
<div id="jump_wrapper">
<div id="jump_page">
<div id="jump_page_wrapper">
<div id="jump_page">
<a class="source" href="browser.html">
browser.coffee
</a>
<a class="source" href="browser.html">
browser.coffee
</a>
<a class="source" href="cake.html">
cake.coffee
</a>
<a class="source" href="cake.html">
cake.coffee
</a>
<a class="source" href="coffee-script.html">
coffee-script.coffee
</a>
<a class="source" href="coffee-script.html">
coffee-script.coffee
</a>
<a class="source" href="command.html">
command.coffee
</a>
<a class="source" href="command.html">
command.coffee
</a>
<a class="source" href="grammar.html">
grammar.coffee
</a>
<a class="source" href="grammar.html">
grammar.coffee
</a>
<a class="source" href="helpers.html">
helpers.coffee
</a>
<a class="source" href="helpers.html">
helpers.coffee
</a>
<a class="source" href="index.html">
index.coffee
</a>
<a class="source" href="index.html">
index.coffee
</a>
<a class="source" href="lexer.html">
lexer.coffee
</a>
<a class="source" href="lexer.html">
lexer.coffee
</a>
<a class="source" href="nodes.html">
nodes.coffee
</a>
<a class="source" href="nodes.html">
nodes.coffee
</a>
<a class="source" href="optparse.html">
optparse.coffee
</a>
<a class="source" href="optparse.html">
optparse.coffee
</a>
<a class="source" href="repl.html">
repl.coffee
</a>
<a class="source" href="register.html">
register.coffee
</a>
<a class="source" href="rewriter.html">
rewriter.coffee
</a>
<a class="source" href="repl.html">
repl.coffee
</a>
<a class="source" href="scope.html">
scope.litcoffee
</a>
<a class="source" href="rewriter.html">
rewriter.coffee
</a>
<a class="source" href="sourcemap.html">
sourcemap.litcoffee
</a>
<a class="source" href="scope.html">
scope.litcoffee
</a>
<a class="source" href="sourcemap.html">
sourcemap.litcoffee
</a>
</div>
</div>
</li>
</ul>
@@ -111,7 +118,7 @@
</div>
<div class="content"><div class='highlight'><pre>{repeat} = require <span class="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>
@@ -123,18 +130,15 @@
<a class="pilcrow" href="#section-2">&#182;</a>
</div>
<p>A simple <strong>OptionParser</strong> class to parse option flags from the command-line.
Use it like so:
</p>
<pre><code>parser = new OptionParser switches, helpBanner
options = parser.parse process.argv</code></pre>
<p>The first non-option is considered to be the start of the file (and file
option) list, and all subsequent arguments are left unparsed.
</p>
Use it like so:</p>
<pre><code>parser = <span class="hljs-keyword">new</span> OptionParser switches, helpBanner
options = parser.parse process.argv
</code></pre><p>The first non-option is considered to be the start of the file (and file
option) list, and all subsequent arguments are left unparsed.</p>
</div>
<div class="content"><div class='highlight'><pre>exports.OptionParser = <span class="class"><span class="keyword">class</span> <span class="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>
@@ -145,17 +149,14 @@ option) list, and all subsequent arguments are left unparsed.
<div class="pilwrap ">
<a class="pilcrow" href="#section-3">&#182;</a>
</div>
<p>Initialize with a list of valid options, in the form:
</p>
<pre><code>[short-flag, long-flag, description]</code></pre>
<p>Along with an an optional banner for the usage help.
</p>
<p>Initialize with a list of valid options, in the form:</p>
<pre><code>[short-flag, long-flag, description]
</code></pre><p>Along with an an optional banner for the usage help.</p>
</div>
<div class="content"><div class='highlight'><pre> constructor: (rules, <span class="property">@banner</span>) -&gt;
<span class="property">@rules</span> = buildRules rules</pre></div></div>
<div class="content"><div class='highlight'><pre> <span class="hljs-attribute">constructor</span>: <span class="hljs-function"><span class="hljs-params">(rules, <span class="hljs-property">@banner</span>)</span> -&gt;</span>
<span class="hljs-property">@rules</span> = buildRules rules</pre></div></div>
</li>
@@ -171,25 +172,24 @@ specified options, and return it. Options after the first non-option
argument are treated as arguments. <code>options.arguments</code> will be an array
containing the remaining arguments. This is a simpler API than many option
parsers that allow you to attach callback actions for every flag. Instead,
you&#39;re responsible for interpreting the options object.
</p>
youre responsible for interpreting the options object.</p>
</div>
<div class="content"><div class='highlight'><pre> parse: (args) -&gt;
options = arguments: []
skippingArgument = <span class="literal">no</span>
<div class="content"><div class='highlight'><pre> <span class="hljs-attribute">parse</span>: <span class="hljs-function"><span class="hljs-params">(args)</span> -&gt;</span>
options = <span class="hljs-attribute">arguments</span>: []
skippingArgument = <span class="hljs-literal">no</span>
originalArgs = args
args = normalizeArguments args
<span class="keyword">for</span> arg, i <span class="keyword">in</span> args
<span class="keyword">if</span> skippingArgument
skippingArgument = <span class="literal">no</span>
<span class="keyword">continue</span>
<span class="keyword">if</span> arg <span class="keyword">is</span> <span class="string">'--'</span>
pos = originalArgs.indexOf <span class="string">'--'</span>
options.arguments = options.arguments.concat originalArgs[(pos + <span class="number">1</span>)..]
<span class="keyword">break</span>
isOption = !!(arg.match(LONG_FLAG) <span class="keyword">or</span> arg.match(SHORT_FLAG))</pre></div></div>
<span class="hljs-keyword">for</span> arg, i <span class="hljs-keyword">in</span> args
<span class="hljs-keyword">if</span> skippingArgument
skippingArgument = <span class="hljs-literal">no</span>
<span class="hljs-keyword">continue</span>
<span class="hljs-keyword">if</span> arg <span class="hljs-keyword">is</span> <span class="hljs-string">'--'</span>
pos = originalArgs.indexOf <span class="hljs-string">'--'</span>
options.arguments = options.arguments.concat originalArgs[(pos + <span class="hljs-number">1</span>)..]
<span class="hljs-keyword">break</span>
isOption = !!(arg.match(LONG_FLAG) <span class="hljs-keyword">or</span> arg.match(SHORT_FLAG))</pre></div></div>
</li>
@@ -201,25 +201,24 @@ you&#39;re responsible for interpreting the options object.
<a class="pilcrow" href="#section-5">&#182;</a>
</div>
<p>the CS option parser is a little odd; options after the first
non-option argument are treated as non-option arguments themselves
</p>
non-option argument are treated as non-option arguments themselves</p>
</div>
<div class="content"><div class='highlight'><pre> seenNonOptionArg = options.arguments.length &gt; <span class="number">0</span>
<span class="keyword">unless</span> seenNonOptionArg
matchedRule = <span class="literal">no</span>
<span class="keyword">for</span> rule <span class="keyword">in</span> <span class="property">@rules</span>
<span class="keyword">if</span> rule.shortFlag <span class="keyword">is</span> arg <span class="keyword">or</span> rule.longFlag <span class="keyword">is</span> arg
value = <span class="literal">true</span>
<span class="keyword">if</span> rule.hasArgument
skippingArgument = <span class="literal">yes</span>
value = args[i + <span class="number">1</span>]
options[rule.name] = <span class="keyword">if</span> rule.isList <span class="keyword">then</span> (options[rule.name] <span class="keyword">or</span> []).concat value <span class="keyword">else</span> value
matchedRule = <span class="literal">yes</span>
<span class="keyword">break</span>
<span class="keyword">throw</span> <span class="keyword">new</span> Error <span class="string">"unrecognized option: <span class="subst">#{arg}</span>"</span> <span class="keyword">if</span> isOption <span class="keyword">and</span> <span class="keyword">not</span> matchedRule
<span class="keyword">if</span> seenNonOptionArg <span class="keyword">or</span> <span class="keyword">not</span> isOption
<div class="content"><div class='highlight'><pre> seenNonOptionArg = options.arguments.length &gt; <span class="hljs-number">0</span>
<span class="hljs-keyword">unless</span> seenNonOptionArg
matchedRule = <span class="hljs-literal">no</span>
<span class="hljs-keyword">for</span> rule <span class="hljs-keyword">in</span> <span class="hljs-property">@rules</span>
<span class="hljs-keyword">if</span> rule.shortFlag <span class="hljs-keyword">is</span> arg <span class="hljs-keyword">or</span> rule.longFlag <span class="hljs-keyword">is</span> arg
value = <span class="hljs-literal">true</span>
<span class="hljs-keyword">if</span> rule.hasArgument
skippingArgument = <span class="hljs-literal">yes</span>
value = args[i + <span class="hljs-number">1</span>]
options[rule.name] = <span class="hljs-keyword">if</span> rule.isList <span class="hljs-keyword">then</span> (options[rule.name] <span class="hljs-keyword">or</span> []).concat value <span class="hljs-keyword">else</span> value
matchedRule = <span class="hljs-literal">yes</span>
<span class="hljs-keyword">break</span>
<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">if</span> isOption <span class="hljs-keyword">and</span> <span class="hljs-keyword">not</span> matchedRule
<span class="hljs-keyword">if</span> seenNonOptionArg <span class="hljs-keyword">or</span> <span class="hljs-keyword">not</span> isOption
options.arguments.push arg
options</pre></div></div>
@@ -233,20 +232,19 @@ non-option argument are treated as non-option arguments themselves
<a class="pilcrow" href="#section-6">&#182;</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>
of the valid options, for <code>--help</code> and such.</p>
</div>
<div class="content"><div class='highlight'><pre> help: -&gt;
<div class="content"><div class='highlight'><pre> <span class="hljs-attribute">help</span>:<span class="hljs-function"> -&gt;</span>
lines = []
lines.unshift <span class="string">"<span class="subst">#{@banner}</span>\n"</span> <span class="keyword">if</span> <span class="property">@banner</span>
<span class="keyword">for</span> rule <span class="keyword">in</span> <span class="property">@rules</span>
spaces = <span class="number">15</span> - rule.longFlag.length
spaces = <span class="keyword">if</span> spaces &gt; <span class="number">0</span> <span class="keyword">then</span> repeat <span class="string">' '</span>, spaces <span class="keyword">else</span> <span class="string">''</span>
letPart = <span class="keyword">if</span> rule.shortFlag <span class="keyword">then</span> rule.shortFlag + <span class="string">', '</span> <span class="keyword">else</span> <span class="string">' '</span>
lines.push <span class="string">' '</span> + letPart + rule.longFlag + spaces + rule.description
<span class="string">"\n<span class="subst">#{ lines.join('\n') }</span>\n"</span></pre></div></div>
lines.unshift <span class="hljs-string">"<span class="hljs-subst">#{<span class="hljs-property">@banner</span>}</span>\n"</span> <span class="hljs-keyword">if</span> <span class="hljs-property">@banner</span>
<span class="hljs-keyword">for</span> rule <span class="hljs-keyword">in</span> <span class="hljs-property">@rules</span>
spaces = <span class="hljs-number">15</span> - rule.longFlag.length
spaces = <span class="hljs-keyword">if</span> spaces &gt; <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>
@@ -254,10 +252,10 @@ of the valid options, for <code>--help</code> and such.
<li id="section-7">
<div class="annotation">
<div class="pilwrap for-h2">
<div class="pilwrap ">
<a class="pilcrow" href="#section-7">&#182;</a>
</div>
<h2>Helpers</h2>
<h2 id="helpers">Helpers</h2>
</div>
@@ -282,15 +280,14 @@ of the valid options, for <code>--help</code> and such.
<div class="pilwrap ">
<a class="pilcrow" href="#section-9">&#182;</a>
</div>
<p>Regex matchers for option flags.
</p>
<p>Regex matchers for option flags.</p>
</div>
<div class="content"><div class='highlight'><pre>LONG_FLAG = <span class="regexp">/^(--\w[\w\-]*)/</span>
SHORT_FLAG = <span class="regexp">/^(-\w)$/</span>
MULTI_FLAG = <span class="regexp">/^-(\w{2,})/</span>
OPTIONAL = <span class="regexp">/\[(\w+(\*?))\]/</span></pre></div></div>
<div class="content"><div class='highlight'><pre>LONG_FLAG = <span class="hljs-regexp">/^(--\w[\w\-]*)/</span>
SHORT_FLAG = <span class="hljs-regexp">/^(-\w)$/</span>
MULTI_FLAG = <span class="hljs-regexp">/^-(\w{2,})/</span>
OPTIONAL = <span class="hljs-regexp">/\[(\w+(\*?))\]/</span></pre></div></div>
</li>
@@ -302,14 +299,13 @@ OPTIONAL = <span class="regexp">/\[(\w+(\*?))\]/</span></pre></div></div>
<a class="pilcrow" href="#section-10">&#182;</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>
unspecified, leave it out by padding with <code>null</code>.</p>
</div>
<div class="content"><div class='highlight'><pre><span class="function"><span class="title">buildRules</span></span> = (rules) -&gt;
<span class="keyword">for</span> tuple <span class="keyword">in</span> rules
tuple.unshift <span class="literal">null</span> <span class="keyword">if</span> tuple.length &lt; <span class="number">3</span>
<div class="content"><div class='highlight'><pre><span class="hljs-function"><span class="hljs-title">buildRules</span> = <span class="hljs-params">(rules)</span> -&gt;</span>
<span class="hljs-keyword">for</span> tuple <span class="hljs-keyword">in</span> rules
tuple.unshift <span class="hljs-literal">null</span> <span class="hljs-keyword">if</span> tuple.length &lt; <span class="hljs-number">3</span>
buildRule tuple...</pre></div></div>
</li>
@@ -322,21 +318,20 @@ unspecified, leave it out by padding with <code>null</code>.
<a class="pilcrow" href="#section-11">&#182;</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>
description of what the option does.</p>
</div>
<div class="content"><div class='highlight'><pre><span class="function"><span class="title">buildRule</span></span> = (shortFlag, longFlag, description, options = {}) -&gt;
<div class="content"><div class='highlight'><pre><span class="hljs-function"><span class="hljs-title">buildRule</span> = <span class="hljs-params">(shortFlag, longFlag, description, options = {})</span> -&gt;</span>
match = longFlag.match(OPTIONAL)
longFlag = longFlag.match(LONG_FLAG)[<span class="number">1</span>]
longFlag = longFlag.match(LONG_FLAG)[<span class="hljs-number">1</span>]
{
name: longFlag.substr <span class="number">2</span>
shortFlag: shortFlag
longFlag: longFlag
description: description
hasArgument: !!(match <span class="keyword">and</span> match[<span class="number">1</span>])
isList: !!(match <span class="keyword">and</span> match[<span class="number">2</span>])
<span class="hljs-attribute">name</span>: longFlag.substr <span class="hljs-number">2</span>
<span class="hljs-attribute">shortFlag</span>: shortFlag
<span class="hljs-attribute">longFlag</span>: longFlag
<span class="hljs-attribute">description</span>: description
<span class="hljs-attribute">hasArgument</span>: !!(match <span class="hljs-keyword">and</span> match[<span class="hljs-number">1</span>])
<span class="hljs-attribute">isList</span>: !!(match <span class="hljs-keyword">and</span> match[<span class="hljs-number">2</span>])
}</pre></div></div>
</li>
@@ -349,18 +344,17 @@ description of what the option does.
<a class="pilcrow" href="#section-12">&#182;</a>
</div>
<p>Normalize arguments by expanding merged flags into multiple flags. This allows
you to have <code>-wl</code> be the same as <code>--watch --lint</code>.
</p>
you to have <code>-wl</code> be the same as <code>--watch --lint</code>.</p>
</div>
<div class="content"><div class='highlight'><pre><span class="function"><span class="title">normalizeArguments</span></span> = (args) -&gt;
<div class="content"><div class='highlight'><pre><span class="hljs-function"><span class="hljs-title">normalizeArguments</span> = <span class="hljs-params">(args)</span> -&gt;</span>
args = args[..]
result = []
<span class="keyword">for</span> arg <span class="keyword">in</span> args
<span class="keyword">if</span> match = arg.match MULTI_FLAG
result.push <span class="string">'-'</span> + l <span class="keyword">for</span> l <span class="keyword">in</span> match[<span class="number">1</span>].split <span class="string">''</span>
<span class="keyword">else</span>
<span class="hljs-keyword">for</span> arg <span class="hljs-keyword">in</span> args
<span class="hljs-keyword">if</span> match = arg.match MULTI_FLAG
result.push <span class="hljs-string">'-'</span> + l <span class="hljs-keyword">for</span> l <span class="hljs-keyword">in</span> match[<span class="hljs-number">1</span>].split <span class="hljs-string">''</span>
<span class="hljs-keyword">else</span>
result.push arg
result</pre></div></div>

0
documentation/docs/public/fonts/aller-bold.eot Executable file → Normal file
View File

0
documentation/docs/public/fonts/aller-bold.ttf Executable file → Normal file
View File

0
documentation/docs/public/fonts/aller-bold.woff Executable file → Normal file
View File

0
documentation/docs/public/fonts/aller-light.eot Executable file → Normal file
View File

0
documentation/docs/public/fonts/aller-light.ttf Executable file → Normal file
View File

0
documentation/docs/public/fonts/aller-light.woff Executable file → Normal file
View File

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -0,0 +1,251 @@
<!DOCTYPE html>
<html>
<head>
<title>register.coffee</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width, target-densitydpi=160dpi, initial-scale=1.0; maximum-scale=1.0; user-scalable=0;">
<link rel="stylesheet" media="all" href="docco.css" />
</head>
<body>
<div id="container">
<div id="background"></div>
<ul id="jump_to">
<li>
<a class="large" href="javascript:void(0);">Jump To &hellip;</a>
<a class="small" href="javascript:void(0);">+</a>
<div id="jump_wrapper">
<div id="jump_page_wrapper">
<div id="jump_page">
<a class="source" href="browser.html">
browser.coffee
</a>
<a class="source" href="cake.html">
cake.coffee
</a>
<a class="source" href="coffee-script.html">
coffee-script.coffee
</a>
<a class="source" href="command.html">
command.coffee
</a>
<a class="source" href="grammar.html">
grammar.coffee
</a>
<a class="source" href="helpers.html">
helpers.coffee
</a>
<a class="source" href="index.html">
index.coffee
</a>
<a class="source" href="lexer.html">
lexer.coffee
</a>
<a class="source" href="nodes.html">
nodes.coffee
</a>
<a class="source" href="optparse.html">
optparse.coffee
</a>
<a class="source" href="register.html">
register.coffee
</a>
<a class="source" href="repl.html">
repl.coffee
</a>
<a class="source" href="rewriter.html">
rewriter.coffee
</a>
<a class="source" href="scope.html">
scope.litcoffee
</a>
<a class="source" href="sourcemap.html">
sourcemap.litcoffee
</a>
</div>
</div>
</li>
</ul>
<ul class="sections">
<li id="title">
<div class="annotation">
<h1>register.coffee</h1>
</div>
</li>
<li id="section-1">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-1">&#182;</a>
</div>
</div>
<div class="content"><div class='highlight'><pre>CoffeeScript = <span class="hljs-built_in">require</span> <span class="hljs-string">'./coffee-script'</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>
<li id="section-2">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-2">&#182;</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> -&gt;</span>
answer = CoffeeScript._compileFile filename, <span class="hljs-literal">false</span>
<span class="hljs-built_in">module</span>._compile answer, filename</pre></div></div>
</li>
<li id="section-3">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-3">&#182;</a>
</div>
<p>If the installed version of Node supports <code>require.extensions</code>, register
CoffeeScript as an extension.</p>
</div>
<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-built_in">require</span>.extensions[ext] = loadFile</pre></div></div>
</li>
<li id="section-4">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-4">&#182;</a>
</div>
<p>Patch Nodes 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>
<span class="hljs-function"><span class="hljs-title">findExtension</span> = <span class="hljs-params">(filename)</span> -&gt;</span>
extensions = path.basename(filename).split <span class="hljs-string">'.'</span></pre></div></div>
</li>
<li id="section-5">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-5">&#182;</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>
</li>
<li id="section-6">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-6">&#182;</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>
<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-attribute">Module</span>::<span class="hljs-function"><span class="hljs-title">load</span> = <span class="hljs-params">(filename)</span> -&gt;</span>
<span class="hljs-property">@filename</span> = filename
<span class="hljs-property">@paths</span> = Module._nodeModulePaths path.dirname filename
extension = findExtension filename
Module._extensions[extension](<span class="hljs-keyword">this</span>, filename)
<span class="hljs-property">@loaded</span> = <span class="hljs-literal">true</span></pre></div></div>
</li>
<li id="section-7">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-7">&#182;</a>
</div>
<p>If were on Node, patch <code>child_process.fork</code> so that Coffee scripts are able
to fork both CoffeeScript files, and JavaScript files, directly.</p>
</div>
<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>
child_process.<span class="hljs-function"><span class="hljs-title">fork</span> = <span class="hljs-params">(path, args, options)</span> -&gt;</span>
<span class="hljs-keyword">if</span> helpers.isCoffee path
<span class="hljs-keyword">unless</span> Array.isArray args
options = args <span class="hljs-keyword">or</span> {}
args = []
args = [path].concat args
path = binary
fork path, args, options</pre></div></div>
</li>
</ul>
</div>
</body>
</html>

View File

@@ -16,78 +16,85 @@
<a class="large" href="javascript:void(0);">Jump To &hellip;</a>
<a class="small" href="javascript:void(0);">+</a>
<div id="jump_wrapper">
<div id="jump_page">
<div id="jump_page_wrapper">
<div id="jump_page">
<a class="source" href="browser.html">
browser.coffee
</a>
<a class="source" href="browser.html">
browser.coffee
</a>
<a class="source" href="cake.html">
cake.coffee
</a>
<a class="source" href="cake.html">
cake.coffee
</a>
<a class="source" href="coffee-script.html">
coffee-script.coffee
</a>
<a class="source" href="coffee-script.html">
coffee-script.coffee
</a>
<a class="source" href="command.html">
command.coffee
</a>
<a class="source" href="command.html">
command.coffee
</a>
<a class="source" href="grammar.html">
grammar.coffee
</a>
<a class="source" href="grammar.html">
grammar.coffee
</a>
<a class="source" href="helpers.html">
helpers.coffee
</a>
<a class="source" href="helpers.html">
helpers.coffee
</a>
<a class="source" href="index.html">
index.coffee
</a>
<a class="source" href="index.html">
index.coffee
</a>
<a class="source" href="lexer.html">
lexer.coffee
</a>
<a class="source" href="lexer.html">
lexer.coffee
</a>
<a class="source" href="nodes.html">
nodes.coffee
</a>
<a class="source" href="nodes.html">
nodes.coffee
</a>
<a class="source" href="optparse.html">
optparse.coffee
</a>
<a class="source" href="optparse.html">
optparse.coffee
</a>
<a class="source" href="repl.html">
repl.coffee
</a>
<a class="source" href="register.html">
register.coffee
</a>
<a class="source" href="rewriter.html">
rewriter.coffee
</a>
<a class="source" href="repl.html">
repl.coffee
</a>
<a class="source" href="scope.html">
scope.litcoffee
</a>
<a class="source" href="rewriter.html">
rewriter.coffee
</a>
<a class="source" href="sourcemap.html">
sourcemap.litcoffee
</a>
<a class="source" href="scope.html">
scope.litcoffee
</a>
<a class="source" href="sourcemap.html">
sourcemap.litcoffee
</a>
</div>
</div>
</li>
</ul>
@@ -111,18 +118,18 @@
</div>
<div class="content"><div class='highlight'><pre>fs = require <span class="string">'fs'</span>
path = require <span class="string">'path'</span>
vm = require <span class="string">'vm'</span>
nodeREPL = require <span class="string">'repl'</span>
CoffeeScript = require <span class="string">'./coffee-script'</span>
{merge, prettyErrorMessage} = require <span class="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">'./coffee-script'</span>
{merge, updateSyntaxError} = <span class="hljs-built_in">require</span> <span class="hljs-string">'./helpers'</span>
replDefaults =
prompt: <span class="string">'coffee&gt; '</span>,
historyFile: path.join process.env.HOME, <span class="string">'.coffee_history'</span> <span class="keyword">if</span> process.env.HOME
historyMaxInputSize: <span class="number">10240</span>
eval: (input, context, filename, cb) -&gt;</pre></div></div>
<span class="hljs-attribute">prompt</span>: <span class="hljs-string">'coffee&gt; '</span>,
<span class="hljs-attribute">historyFile</span>: path.join process.env.HOME, <span class="hljs-string">'.coffee_history'</span> <span class="hljs-keyword">if</span> process.env.HOME
<span class="hljs-attribute">historyMaxInputSize</span>: <span class="hljs-number">10240</span>
<span class="hljs-attribute">eval</span>: <span class="hljs-function"><span class="hljs-params">(input, context, filename, cb)</span> -&gt;</span></pre></div></div>
</li>
@@ -133,12 +140,11 @@ replDefaults =
<div class="pilwrap ">
<a class="pilcrow" href="#section-2">&#182;</a>
</div>
<p>XXX: multiline hack.
</p>
<p>XXX: multiline hack.</p>
</div>
<div class="content"><div class='highlight'><pre> input = input.replace <span class="regexp">/\uFF00/g</span>, <span class="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>
@@ -149,13 +155,12 @@ replDefaults =
<div class="pilwrap ">
<a class="pilcrow" href="#section-3">&#182;</a>
</div>
<p>Node&#39;s REPL sends the input ending with a newline and then wrapped in
parens. Unwrap all that.
</p>
<p>Nodes 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="regexp">/^\(([\s\S]*)\n\)$/m</span>, <span class="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>
@@ -166,14 +171,13 @@ parens. Unwrap all that.
<div class="pilwrap ">
<a class="pilcrow" href="#section-4">&#182;</a>
</div>
<p>Require AST nodes to do some AST manipulation.
</p>
<p>Require AST nodes to do some AST manipulation.</p>
</div>
<div class="content"><div class='highlight'><pre> {Block, Assign, Value, Literal} = require <span class="string">'./nodes'</span>
<div class="content"><div class='highlight'><pre> {Block, Assign, Value, Literal} = <span class="hljs-built_in">require</span> <span class="hljs-string">'./nodes'</span>
<span class="keyword">try</span></pre></div></div>
<span class="hljs-keyword">try</span></pre></div></div>
</li>
@@ -184,12 +188,11 @@ parens. Unwrap all that.
<div class="pilwrap ">
<a class="pilcrow" href="#section-5">&#182;</a>
</div>
<p>Generate the AST of the clean input.
</p>
<p>Tokenize the clean input.</p>
</div>
<div class="content"><div class='highlight'><pre> ast = CoffeeScript.nodes input</pre></div></div>
<div class="content"><div class='highlight'><pre> tokens = CoffeeScript.tokens input</pre></div></div>
</li>
@@ -200,27 +203,13 @@ parens. Unwrap all that.
<div class="pilwrap ">
<a class="pilcrow" href="#section-6">&#182;</a>
</div>
<p>Add assignment to <code>_</code> variable to force the input to be an expression.
</p>
<p>Collect referenced variable names just like in <code>CoffeeScript.compile</code>.</p>
</div>
<div class="content"><div class='highlight'><pre> ast = <span class="keyword">new</span> Block [
<span class="keyword">new</span> Assign (<span class="keyword">new</span> Value <span class="keyword">new</span> Literal <span class="string">'_'</span>), ast, <span class="string">'='</span>
]
js = ast.compile bare: <span class="literal">yes</span>, locals: Object.keys(context)
cb <span class="literal">null</span>, vm.runInContext(js, context, filename)
<span class="keyword">catch</span> err
cb prettyErrorMessage(err, filename, input, <span class="literal">yes</span>)
<span class="function"><span class="title">addMultilineHandler</span></span> = (repl) -&gt;
{rli, inputStream, outputStream} = repl
multiline =
enabled: <span class="literal">off</span>
initialPrompt: repl.prompt.replace <span class="regexp">/^[^&gt; ]*/, (x) -&gt; x.replace /./g</span>, <span class="string">'-'</span>
prompt: repl.prompt.replace <span class="regexp">/^[^&gt; ]*&gt;?/, (x) -&gt; x.replace /./g</span>, <span class="string">'.'</span>
buffer: <span class="string">''</span></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.variable
)</pre></div></div>
</li>
@@ -231,21 +220,11 @@ parens. Unwrap all that.
<div class="pilwrap ">
<a class="pilcrow" href="#section-7">&#182;</a>
</div>
<p>Proxy node&#39;s line listener
</p>
<p>Generate the AST of the tokens.</p>
</div>
<div class="content"><div class='highlight'><pre> nodeLineListener = rli.listeners(<span class="string">'line'</span>)[<span class="number">0</span>]
rli.removeListener <span class="string">'line'</span>, nodeLineListener
rli.<span class="literal">on</span> <span class="string">'line'</span>, (cmd) -&gt;
<span class="keyword">if</span> multiline.enabled
multiline.buffer += <span class="string">"<span class="subst">#{cmd}</span>\n"</span>
rli.setPrompt multiline.prompt
rli.prompt <span class="literal">true</span>
<span class="keyword">else</span>
nodeLineListener cmd
<span class="keyword">return</span></pre></div></div>
<div class="content"><div class='highlight'><pre> ast = CoffeeScript.nodes tokens</pre></div></div>
</li>
@@ -256,14 +235,16 @@ parens. Unwrap all that.
<div class="pilwrap ">
<a class="pilcrow" href="#section-8">&#182;</a>
</div>
<p>Handle Ctrl-v
</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> inputStream.<span class="literal">on</span> <span class="string">'keypress'</span>, (char, key) -&gt;
<span class="keyword">return</span> <span class="keyword">unless</span> key <span class="keyword">and</span> key.ctrl <span class="keyword">and</span> <span class="keyword">not</span> key.meta <span class="keyword">and</span> <span class="keyword">not</span> key.shift <span class="keyword">and</span> key.name <span class="keyword">is</span> <span class="string">'v'</span>
<span class="keyword">if</span> multiline.enabled</pre></div></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>
]
js = ast.compile {<span class="hljs-attribute">bare</span>: <span class="hljs-literal">yes</span>, <span class="hljs-attribute">locals</span>: Object.keys(context), referencedVars}
cb <span class="hljs-literal">null</span>, runInContext js, context, filename
<span class="hljs-keyword">catch</span> err</pre></div></div>
</li>
@@ -274,16 +255,21 @@ parens. Unwrap all that.
<div class="pilwrap ">
<a class="pilcrow" href="#section-9">&#182;</a>
</div>
<p>allow arbitrarily switching between modes any time before multiple lines are entered
</p>
<p>ASTs <code>compile</code> does not add source code information to syntax errors.</p>
</div>
<div class="content"><div class='highlight'><pre> <span class="keyword">unless</span> multiline.buffer.match <span class="regexp">/\n/</span>
multiline.enabled = <span class="keyword">not</span> multiline.enabled
rli.setPrompt repl.prompt
rli.prompt <span class="literal">true</span>
<span class="keyword">return</span></pre></div></div>
<div class="content"><div class='highlight'><pre> updateSyntaxError err, input
cb err
<span class="hljs-function"><span class="hljs-title">runInContext</span> = <span class="hljs-params">(js, context, filename)</span> -&gt;</span>
<span class="hljs-keyword">if</span> context <span class="hljs-keyword">is</span> <span class="hljs-built_in">global</span>
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> -&gt;</span>
{rli, inputStream, outputStream} = repl</pre></div></div>
</li>
@@ -294,12 +280,17 @@ parens. Unwrap all that.
<div class="pilwrap ">
<a class="pilcrow" href="#section-10">&#182;</a>
</div>
<p>no-op unless the current line is empty
</p>
<p>Node 0.11.12 changed API, prompt is now _prompt.</p>
</div>
<div class="content"><div class='highlight'><pre> <span class="keyword">return</span> <span class="keyword">if</span> rli.line? <span class="keyword">and</span> <span class="keyword">not</span> rli.line.match <span class="regexp">/^\s*$/</span></pre></div></div>
<div class="content"><div class='highlight'><pre> origPrompt = repl._prompt ? repl.prompt
multiline =
<span class="hljs-attribute">enabled</span>: <span class="hljs-literal">off</span>
<span class="hljs-attribute">initialPrompt</span>: origPrompt.replace <span class="hljs-regexp">/^[^&gt; ]*/</span>, <span class="hljs-function"><span class="hljs-params">(x)</span> -&gt;</span> x.replace <span class="hljs-regexp">/./g</span>, <span class="hljs-string">'-'</span>
<span class="hljs-attribute">prompt</span>: origPrompt.replace <span class="hljs-regexp">/^[^&gt; ]*&gt;?/</span>, <span class="hljs-function"><span class="hljs-params">(x)</span> -&gt;</span> x.replace <span class="hljs-regexp">/./g</span>, <span class="hljs-string">'.'</span>
<span class="hljs-attribute">buffer</span>: <span class="hljs-string">''</span></pre></div></div>
</li>
@@ -310,16 +301,21 @@ parens. Unwrap all that.
<div class="pilwrap ">
<a class="pilcrow" href="#section-11">&#182;</a>
</div>
<p>eval, print, loop
</p>
<p>Proxy nodes line listener</p>
</div>
<div class="content"><div class='highlight'><pre> multiline.enabled = <span class="keyword">not</span> multiline.enabled
rli.line = <span class="string">''</span>
rli.cursor = <span class="number">0</span>
rli.output.cursorTo <span class="number">0</span>
rli.output.clearLine <span class="number">1</span></pre></div></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> -&gt;</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>
@@ -330,19 +326,13 @@ parens. Unwrap all that.
<div class="pilwrap ">
<a class="pilcrow" href="#section-12">&#182;</a>
</div>
<p>XXX: multiline hack
</p>
<p>Handle Ctrl-v</p>
</div>
<div class="content"><div class='highlight'><pre> multiline.buffer = multiline.buffer.replace <span class="regexp">/\n/g</span>, <span class="string">'\uFF00'</span>
rli.emit <span class="string">'line'</span>, multiline.buffer
multiline.buffer = <span class="string">''</span>
<span class="keyword">else</span>
multiline.enabled = <span class="keyword">not</span> multiline.enabled
rli.setPrompt multiline.initialPrompt
rli.prompt <span class="literal">true</span>
<span class="keyword">return</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> -&gt;</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>
@@ -353,14 +343,15 @@ parens. Unwrap all that.
<div class="pilwrap ">
<a class="pilcrow" href="#section-13">&#182;</a>
</div>
<p>Store and load command history from a file
</p>
<p>allow arbitrarily switching between modes any time before multiple lines are entered</p>
</div>
<div class="content"><div class='highlight'><pre><span class="function"><span class="title">addHistory</span></span> = (repl, filename, maxSize) -&gt;
lastLine = <span class="literal">null</span>
<span class="keyword">try</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
rli.setPrompt origPrompt
rli.prompt <span class="hljs-literal">true</span>
<span class="hljs-keyword">return</span></pre></div></div>
</li>
@@ -371,13 +362,11 @@ parens. Unwrap all that.
<div class="pilwrap ">
<a class="pilcrow" href="#section-14">&#182;</a>
</div>
<p>Get file info and at most maxSize of command history
</p>
<p>no-op unless the current line is empty</p>
</div>
<div class="content"><div class='highlight'><pre> stat = fs.statSync filename
size = Math.min maxSize, stat.size</pre></div></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>
</li>
@@ -388,14 +377,15 @@ parens. Unwrap all that.
<div class="pilwrap ">
<a class="pilcrow" href="#section-15">&#182;</a>
</div>
<p>Read last <code>size</code> bytes from the file
</p>
<p>eval, print, loop</p>
</div>
<div class="content"><div class='highlight'><pre> readFd = fs.openSync filename, <span class="string">'r'</span>
buffer = <span class="keyword">new</span> Buffer(size)
fs.readSync readFd, buffer, <span class="number">0</span>, size, stat.size - size</pre></div></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>
</li>
@@ -406,12 +396,18 @@ parens. Unwrap all that.
<div class="pilwrap ">
<a class="pilcrow" href="#section-16">&#182;</a>
</div>
<p>Set the history on the interpreter
</p>
<p>XXX: multiline hack</p>
</div>
<div class="content"><div class='highlight'><pre> repl.rli.history = buffer.toString().split(<span class="string">'\n'</span>).reverse()</pre></div></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>
</li>
@@ -422,12 +418,13 @@ parens. Unwrap all that.
<div class="pilwrap ">
<a class="pilcrow" href="#section-17">&#182;</a>
</div>
<p>If the history file was truncated we should pop off a potential partial line
</p>
<p>Store and load command history from a file</p>
</div>
<div class="content"><div class='highlight'><pre> repl.rli.history.pop() <span class="keyword">if</span> stat.size &gt; maxSize</pre></div></div>
<div class="content"><div class='highlight'><pre><span class="hljs-function"><span class="hljs-title">addHistory</span> = <span class="hljs-params">(repl, filename, maxSize)</span> -&gt;</span>
lastLine = <span class="hljs-literal">null</span>
<span class="hljs-keyword">try</span></pre></div></div>
</li>
@@ -438,19 +435,12 @@ parens. Unwrap all that.
<div class="pilwrap ">
<a class="pilcrow" href="#section-18">&#182;</a>
</div>
<p>Shift off the final blank newline
</p>
<p>Get file info and at most maxSize of command history</p>
</div>
<div class="content"><div class='highlight'><pre> repl.rli.history.shift() <span class="keyword">if</span> repl.rli.history[<span class="number">0</span>] <span class="keyword">is</span> <span class="string">''</span>
repl.rli.historyIndex = -<span class="number">1</span>
lastLine = repl.rli.history[<span class="number">0</span>]
fd = fs.openSync filename, <span class="string">'a'</span>
repl.rli.addListener <span class="string">'line'</span>, (code) -&gt;
<span class="keyword">if</span> code <span class="keyword">and</span> code.length <span class="keyword">and</span> code <span class="keyword">isnt</span> <span class="string">'.history'</span> <span class="keyword">and</span> lastLine <span class="keyword">isnt</span> code</pre></div></div>
<div class="content"><div class='highlight'><pre> stat = fs.statSync filename
size = Math.min maxSize, stat.size</pre></div></div>
</li>
@@ -461,15 +451,13 @@ parens. Unwrap all that.
<div class="pilwrap ">
<a class="pilcrow" href="#section-19">&#182;</a>
</div>
<p>Save the latest command in the file
</p>
<p>Read last <code>size</code> bytes from the file</p>
</div>
<div class="content"><div class='highlight'><pre> fs.write fd, <span class="string">"<span class="subst">#{code}</span>\n"</span>
lastLine = code
repl.rli.<span class="literal">on</span> <span class="string">'exit'</span>, -&gt; fs.close fd</pre></div></div>
<div class="content"><div class='highlight'><pre> readFd = fs.openSync filename, <span class="hljs-string">'r'</span>
buffer = <span class="hljs-keyword">new</span> Buffer(size)
fs.readSync readFd, buffer, <span class="hljs-number">0</span>, size, stat.size - size</pre></div></div>
</li>
@@ -480,30 +468,135 @@ parens. Unwrap all that.
<div class="pilwrap ">
<a class="pilcrow" href="#section-20">&#182;</a>
</div>
<p>Add a command to show the history stack
</p>
<p>Set the history on the interpreter</p>
</div>
<div class="content"><div class='highlight'><pre> repl.commands[<span class="string">'.history'</span>] =
help: <span class="string">'Show command history'</span>
action: -&gt;
repl.outputStream.write <span class="string">"<span class="subst">#{repl.rli.history[..].reverse().join '\n'}</span>\n"</span>
<div class="content"><div class='highlight'><pre> repl.rli.history = buffer.toString().split(<span class="hljs-string">'\n'</span>).reverse()</pre></div></div>
</li>
<li id="section-21">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-21">&#182;</a>
</div>
<p>If the history file was truncated we should pop off a potential partial line</p>
</div>
<div class="content"><div class='highlight'><pre> repl.rli.history.pop() <span class="hljs-keyword">if</span> stat.size &gt; maxSize</pre></div></div>
</li>
<li id="section-22">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-22">&#182;</a>
</div>
<p>Shift off the final blank newline</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> -&gt;</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> lastLine <span class="hljs-keyword">isnt</span> code</pre></div></div>
</li>
<li id="section-23">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-23">&#182;</a>
</div>
<p>Save the latest command in the file</p>
</div>
<div class="content"><div class='highlight'><pre> fs.write fd, <span class="hljs-string">"<span class="hljs-subst">#{code}</span>\n"</span>
lastLine = code
repl.rli.<span class="hljs-literal">on</span> <span class="hljs-string">'exit'</span>,<span class="hljs-function"> -&gt;</span> fs.close fd</pre></div></div>
</li>
<li id="section-24">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-24">&#182;</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>)] =
<span class="hljs-attribute">help</span>: <span class="hljs-string">'Show command history'</span>
<span class="hljs-attribute">action</span>:<span class="hljs-function"> -&gt;</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()
module.exports =
start: (opts = {}) -&gt;
[major, minor, build] = process.versions.node.split(<span class="string">'.'</span>).map (n) -&gt; parseInt(n)
<span class="hljs-function"><span class="hljs-title">getCommandId</span> = <span class="hljs-params">(repl, commandName)</span> -&gt;</span></pre></div></div>
</li>
<li id="section-25">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-25">&#182;</a>
</div>
<p>Node 0.11 changed API, a command such as .help is now stored as help</p>
<span class="keyword">if</span> major <span class="keyword">is</span> <span class="number">0</span> <span class="keyword">and</span> minor &lt; <span class="number">8</span>
console.warn <span class="string">"Node 0.8.0+ required for CoffeeScript REPL"</span>
process.exit <span class="number">1</span>
</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>.<span class="hljs-built_in">exports</span> =
<span class="hljs-attribute">start</span>: <span class="hljs-function"><span class="hljs-params">(opts = {})</span> -&gt;</span>
[major, minor, build] = process.versions.node.split<span class="hljs-function"><span class="hljs-params">(<span class="hljs-string">'.'</span>)</span>.<span class="hljs-title">map</span> <span class="hljs-params">(n)</span> -&gt;</span> parseInt(n)
<span class="hljs-keyword">if</span> major <span class="hljs-keyword">is</span> <span class="hljs-number">0</span> <span class="hljs-keyword">and</span> minor &lt; <span class="hljs-number">8</span>
<span class="hljs-built_in">console</span>.warn <span class="hljs-string">"Node 0.8.0+ 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
repl.<span class="literal">on</span> <span class="string">'exit'</span>, -&gt; repl.outputStream.write <span class="string">'\n'</span>
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"> -&gt;</span> repl.outputStream.write <span class="hljs-string">'\n'</span>
addMultilineHandler repl
addHistory repl, opts.historyFile, opts.historyMaxInputSize <span class="keyword">if</span> opts.historyFile
addHistory repl, opts.historyFile, opts.historyMaxInputSize <span class="hljs-keyword">if</span> opts.historyFile</pre></div></div>
</li>
<li id="section-26">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-26">&#182;</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>
repl</pre></div></div>
</li>

File diff suppressed because it is too large Load Diff

View File

@@ -16,78 +16,85 @@
<a class="large" href="javascript:void(0);">Jump To &hellip;</a>
<a class="small" href="javascript:void(0);">+</a>
<div id="jump_wrapper">
<div id="jump_page">
<div id="jump_page_wrapper">
<div id="jump_page">
<a class="source" href="browser.html">
browser.coffee
</a>
<a class="source" href="browser.html">
browser.coffee
</a>
<a class="source" href="cake.html">
cake.coffee
</a>
<a class="source" href="cake.html">
cake.coffee
</a>
<a class="source" href="coffee-script.html">
coffee-script.coffee
</a>
<a class="source" href="coffee-script.html">
coffee-script.coffee
</a>
<a class="source" href="command.html">
command.coffee
</a>
<a class="source" href="command.html">
command.coffee
</a>
<a class="source" href="grammar.html">
grammar.coffee
</a>
<a class="source" href="grammar.html">
grammar.coffee
</a>
<a class="source" href="helpers.html">
helpers.coffee
</a>
<a class="source" href="helpers.html">
helpers.coffee
</a>
<a class="source" href="index.html">
index.coffee
</a>
<a class="source" href="index.html">
index.coffee
</a>
<a class="source" href="lexer.html">
lexer.coffee
</a>
<a class="source" href="lexer.html">
lexer.coffee
</a>
<a class="source" href="nodes.html">
nodes.coffee
</a>
<a class="source" href="nodes.html">
nodes.coffee
</a>
<a class="source" href="optparse.html">
optparse.coffee
</a>
<a class="source" href="optparse.html">
optparse.coffee
</a>
<a class="source" href="repl.html">
repl.coffee
</a>
<a class="source" href="register.html">
register.coffee
</a>
<a class="source" href="rewriter.html">
rewriter.coffee
</a>
<a class="source" href="repl.html">
repl.coffee
</a>
<a class="source" href="scope.html">
scope.litcoffee
</a>
<a class="source" href="rewriter.html">
rewriter.coffee
</a>
<a class="source" href="sourcemap.html">
sourcemap.litcoffee
</a>
<a class="source" href="scope.html">
scope.litcoffee
</a>
<a class="source" href="sourcemap.html">
sourcemap.litcoffee
</a>
</div>
</div>
</li>
</ul>
@@ -113,11 +120,12 @@ generate code, you create a tree of scopes in the same shape as the nested
function bodies. Each scope knows about the variables declared within it,
and has a reference to its parent enclosing scope. In this way, we know which
variables are new and need to be declared with <code>var</code>, and which are shared
with external scopes.
</p>
with external scopes.</p>
</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>
@@ -127,15 +135,18 @@ with external scopes.
<div class="pilwrap ">
<a class="pilcrow" href="#section-2">&#182;</a>
</div>
<p>Import the helpers we plan to use.
</p>
<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>
</div>
<div class="content"><div class='highlight'><pre>
{extend, last} = require <span class="string">'./helpers'</span>
exports.Scope = <span class="class"><span class="keyword">class</span> <span class="title">Scope</span></span></pre></div></div>
<div class="content"><div class='highlight'><pre> <span class="hljs-attribute">constructor</span>: <span class="hljs-function"><span class="hljs-params">(<span class="hljs-property">@parent</span>, <span class="hljs-property">@expressions</span>, <span class="hljs-property">@method</span>, <span class="hljs-property">@referencedVars</span>)</span> -&gt;</span>
<span class="hljs-property">@variables</span> = [{<span class="hljs-attribute">name</span>: <span class="hljs-string">'arguments'</span>, <span class="hljs-attribute">type</span>: <span class="hljs-string">'arguments'</span>}]
<span class="hljs-property">@positions</span> = {}
<span class="hljs-property">@utilities</span> = {} <span class="hljs-keyword">unless</span> <span class="hljs-property">@parent</span></pre></div></div>
</li>
@@ -146,13 +157,11 @@ exports.Scope = <span class="class"><span class="keyword">class</span> <span cla
<div class="pilwrap ">
<a class="pilcrow" href="#section-3">&#182;</a>
</div>
<p>The <code>root</code> is the top-level <strong>Scope</strong> object for a given file.
</p>
<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>
<span class="property">@root</span>: <span class="literal">null</span></pre></div></div>
<div class="content"><div class='highlight'><pre> <span class="hljs-property">@root</span> = <span class="hljs-property">@parent</span>?.root ? <span class="hljs-keyword">this</span></pre></div></div>
</li>
@@ -163,19 +172,16 @@ exports.Scope = <span class="class"><span class="keyword">class</span> <span cla
<div class="pilwrap ">
<a class="pilcrow" href="#section-4">&#182;</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, and a reference to the function that
it belongs to.
</p>
<p>Adds a new variable or overrides an existing one.</p>
</div>
<div class="content"><div class='highlight'><pre>
constructor: (<span class="property">@parent</span>, <span class="property">@expressions</span>, <span class="property">@method</span>) -&gt;
<span class="property">@variables</span> = [{name: <span class="string">'arguments'</span>, type: <span class="string">'arguments'</span>}]
<span class="property">@positions</span> = {}
Scope.root = <span class="keyword">this</span> <span class="keyword">unless</span> <span class="property">@parent</span></pre></div></div>
<div class="content"><div class='highlight'><pre> <span class="hljs-attribute">add</span>: <span class="hljs-function"><span class="hljs-params">(name, type, immediate)</span> -&gt;</span>
<span class="hljs-keyword">return</span> <span class="hljs-property">@parent</span>.add name, type, immediate <span class="hljs-keyword">if</span> <span class="hljs-property">@shared</span> <span class="hljs-keyword">and</span> <span class="hljs-keyword">not</span> immediate
<span class="hljs-keyword">if</span> <span class="hljs-attribute">Object</span>::hasOwnProperty.call <span class="hljs-property">@positions</span>, name
<span class="hljs-property">@variables</span>[<span class="hljs-property">@positions</span>[name]].type = type
<span class="hljs-keyword">else</span>
<span class="hljs-property">@positions</span>[name] = <span class="hljs-property">@variables</span>.push({name, type}) - <span class="hljs-number">1</span></pre></div></div>
</li>
@@ -186,18 +192,17 @@ it belongs to.
<div class="pilwrap ">
<a class="pilcrow" href="#section-5">&#182;</a>
</div>
<p>Adds a new variable or overrides an existing one.
</p>
<p>When <code>super</code> is called, we need to find the name of the current method were
in, so that we know how to invoke the same method of the parent class. This
can get complicated if super is being called from an inner function.
<code>namedMethod</code> will walk up the scope tree until it either finds the first
function object that has a name filled in, or bottoms out.</p>
</div>
<div class="content"><div class='highlight'><pre>
add: (name, type, immediate) -&gt;
<span class="keyword">return</span> <span class="property">@parent</span>.add name, type, immediate <span class="keyword">if</span> <span class="property">@shared</span> <span class="keyword">and</span> <span class="keyword">not</span> immediate
<span class="keyword">if</span> Object::hasOwnProperty.call <span class="property">@positions</span>, name
<span class="property">@variables</span>[<span class="property">@positions</span>[name]].type = type
<span class="keyword">else</span>
<span class="property">@positions</span>[name] = <span class="property">@variables</span>.push({name, type}) - <span class="number">1</span></pre></div></div>
<div class="content"><div class='highlight'><pre> <span class="hljs-attribute">namedMethod</span>:<span class="hljs-function"> -&gt;</span>
<span class="hljs-keyword">return</span> <span class="hljs-property">@method</span> <span class="hljs-keyword">if</span> <span class="hljs-property">@method</span>?.name <span class="hljs-keyword">or</span> !<span class="hljs-property">@parent</span>
<span class="hljs-property">@parent</span>.namedMethod()</pre></div></div>
</li>
@@ -208,19 +213,15 @@ it belongs to.
<div class="pilwrap ">
<a class="pilcrow" href="#section-6">&#182;</a>
</div>
<p>When <code>super</code> is called, we need to find the name of the current method we&#39;re
in, so that we know how to invoke the same method of the parent class. This
can get complicated if super is being called from an inner function.
<code>namedMethod</code> will walk up the scope tree until it either finds the first
function object that has a name filled in, or bottoms out.
</p>
<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>
namedMethod: -&gt;
<span class="keyword">return</span> <span class="property">@method</span> <span class="keyword">if</span> <span class="property">@method</span>?.name <span class="keyword">or</span> !<span class="property">@parent</span>
<span class="property">@parent</span>.namedMethod()</pre></div></div>
<div class="content"><div class='highlight'><pre> <span class="hljs-attribute">find</span>: <span class="hljs-function"><span class="hljs-params">(name)</span> -&gt;</span>
<span class="hljs-keyword">return</span> <span class="hljs-literal">yes</span> <span class="hljs-keyword">if</span> <span class="hljs-property">@check</span> name
<span class="hljs-property">@add</span> name, <span class="hljs-string">'var'</span>
<span class="hljs-literal">no</span></pre></div></div>
</li>
@@ -231,17 +232,14 @@ function object that has a name filled in, or bottoms out.
<div class="pilwrap ">
<a class="pilcrow" href="#section-7">&#182;</a>
</div>
<p>Look up a variable name in lexical scope, and declare it if it does not
already exist.
</p>
<p>Reserve a variable name as originating from a function parameter for this
scope. No <code>var</code> required for internal references.</p>
</div>
<div class="content"><div class='highlight'><pre>
find: (name) -&gt;
<span class="keyword">return</span> <span class="literal">yes</span> <span class="keyword">if</span> <span class="property">@check</span> name
<span class="property">@add</span> name, <span class="string">'var'</span>
<span class="literal">no</span></pre></div></div>
<div class="content"><div class='highlight'><pre> <span class="hljs-attribute">parameter</span>: <span class="hljs-function"><span class="hljs-params">(name)</span> -&gt;</span>
<span class="hljs-keyword">return</span> <span class="hljs-keyword">if</span> <span class="hljs-property">@shared</span> <span class="hljs-keyword">and</span> <span class="hljs-property">@parent</span>.check name, <span class="hljs-literal">yes</span>
<span class="hljs-property">@add</span> name, <span class="hljs-string">'param'</span></pre></div></div>
</li>
@@ -252,16 +250,13 @@ already exist.
<div class="pilwrap ">
<a class="pilcrow" href="#section-8">&#182;</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>
<p>Just check to see if a variable has already been declared, without reserving,
walks up to the root scope.</p>
</div>
<div class="content"><div class='highlight'><pre>
parameter: (name) -&gt;
<span class="keyword">return</span> <span class="keyword">if</span> <span class="property">@shared</span> <span class="keyword">and</span> <span class="property">@parent</span>.check name, <span class="literal">yes</span>
<span class="property">@add</span> name, <span class="string">'param'</span></pre></div></div>
<div class="content"><div class='highlight'><pre> <span class="hljs-attribute">check</span>: <span class="hljs-function"><span class="hljs-params">(name)</span> -&gt;</span>
!!(<span class="hljs-property">@type</span>(name) <span class="hljs-keyword">or</span> <span class="hljs-property">@parent</span>?.check(name))</pre></div></div>
</li>
@@ -272,15 +267,15 @@ scope. No <code>var</code> required for internal references.
<div class="pilwrap ">
<a class="pilcrow" href="#section-9">&#182;</a>
</div>
<p>Just check to see if a variable has already been declared, without reserving,
walks up to the root scope.
</p>
<p>Generate a temporary variable name at the given index.</p>
</div>
<div class="content"><div class='highlight'><pre>
check: (name) -&gt;
!!(<span class="property">@type</span>(name) <span class="keyword">or</span> <span class="property">@parent</span>?.check(name))</pre></div></div>
<div class="content"><div class='highlight'><pre> <span class="hljs-attribute">temporary</span>: <span class="hljs-function"><span class="hljs-params">(name, index, single=<span class="hljs-literal">false</span>)</span> -&gt;</span>
<span class="hljs-keyword">if</span> single
(index + parseInt name, <span class="hljs-number">36</span>).toString(<span class="hljs-number">36</span>).replace <span class="hljs-regexp">/\d/g</span>, <span class="hljs-string">'a'</span>
<span class="hljs-keyword">else</span>
name + (index <span class="hljs-keyword">or</span> <span class="hljs-string">''</span>)</pre></div></div>
</li>
@@ -291,17 +286,13 @@ walks up to the root scope.
<div class="pilwrap ">
<a class="pilcrow" href="#section-10">&#182;</a>
</div>
<p>Generate a temporary variable name at the given index.
</p>
<p>Gets the type of a variable.</p>
</div>
<div class="content"><div class='highlight'><pre>
temporary: (name, index) -&gt;
<span class="keyword">if</span> name.length &gt; <span class="number">1</span>
<span class="string">'_'</span> + name + <span class="keyword">if</span> index &gt; <span class="number">1</span> <span class="keyword">then</span> index - <span class="number">1</span> <span class="keyword">else</span> <span class="string">''</span>
<span class="keyword">else</span>
<span class="string">'_'</span> + (index + parseInt name, <span class="number">36</span>).toString(<span class="number">36</span>).replace <span class="regexp">/\d/g</span>, <span class="string">'a'</span></pre></div></div>
<div class="content"><div class='highlight'><pre> <span class="hljs-attribute">type</span>: <span class="hljs-function"><span class="hljs-params">(name)</span> -&gt;</span>
<span class="hljs-keyword">return</span> v.type <span class="hljs-keyword">for</span> v <span class="hljs-keyword">in</span> <span class="hljs-property">@variables</span> <span class="hljs-keyword">when</span> v.name <span class="hljs-keyword">is</span> name
<span class="hljs-literal">null</span></pre></div></div>
</li>
@@ -312,15 +303,19 @@ walks up to the root scope.
<div class="pilwrap ">
<a class="pilcrow" href="#section-11">&#182;</a>
</div>
<p>Gets the type of a variable.
</p>
<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>
</div>
<div class="content"><div class='highlight'><pre>
type: (name) -&gt;
<span class="keyword">return</span> v.type <span class="keyword">for</span> v <span class="keyword">in</span> <span class="property">@variables</span> <span class="keyword">when</span> v.name <span class="keyword">is</span> name
<span class="literal">null</span></pre></div></div>
<div class="content"><div class='highlight'><pre> <span class="hljs-attribute">freeVariable</span>: <span class="hljs-function"><span class="hljs-params">(name, options={})</span> -&gt;</span>
index = <span class="hljs-number">0</span>
<span class="hljs-keyword">loop</span>
temp = <span class="hljs-property">@temporary</span> name, index, options.single
<span class="hljs-keyword">break</span> <span class="hljs-keyword">unless</span> <span class="hljs-property">@check</span>(temp) <span class="hljs-keyword">or</span> temp <span class="hljs-keyword">in</span> <span class="hljs-property">@root</span>.referencedVars
index++
<span class="hljs-property">@add</span> 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>
@@ -331,18 +326,14 @@ walks up to the root scope.
<div class="pilwrap ">
<a class="pilcrow" href="#section-12">&#182;</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>
<p>Ensure that an assignment is made at the top of this scope
(or at the top-level scope, if requested).</p>
</div>
<div class="content"><div class='highlight'><pre>
freeVariable: (name, reserve=<span class="literal">true</span>) -&gt;
index = <span class="number">0</span>
index++ <span class="keyword">while</span> <span class="property">@check</span>((temp = <span class="property">@temporary</span> name, index))
<span class="property">@add</span> temp, <span class="string">'var'</span>, <span class="literal">yes</span> <span class="keyword">if</span> reserve
temp</pre></div></div>
<div class="content"><div class='highlight'><pre> <span class="hljs-attribute">assign</span>: <span class="hljs-function"><span class="hljs-params">(name, value)</span> -&gt;</span>
<span class="hljs-property">@add</span> name, {value, <span class="hljs-attribute">assigned</span>: <span class="hljs-literal">yes</span>}, <span class="hljs-literal">yes</span>
<span class="hljs-property">@hasAssignments</span> = <span class="hljs-literal">yes</span></pre></div></div>
</li>
@@ -353,16 +344,12 @@ compiler-generated variable. <code>_var</code>, <code>_var2</code>, and so on...
<div class="pilwrap ">
<a class="pilcrow" href="#section-13">&#182;</a>
</div>
<p>Ensure that an assignment is made at the top of this scope
(or at the top-level scope, if requested).
</p>
<p>Does this scope have any declared variables?</p>
</div>
<div class="content"><div class='highlight'><pre>
assign: (name, value) -&gt;
<span class="property">@add</span> name, {value, assigned: <span class="literal">yes</span>}, <span class="literal">yes</span>
<span class="property">@hasAssignments</span> = <span class="literal">yes</span></pre></div></div>
<div class="content"><div class='highlight'><pre> <span class="hljs-attribute">hasDeclarations</span>:<span class="hljs-function"> -&gt;</span>
!!<span class="hljs-property">@declaredVariables</span>().length</pre></div></div>
</li>
@@ -373,14 +360,12 @@ compiler-generated variable. <code>_var</code>, <code>_var2</code>, and so on...
<div class="pilwrap ">
<a class="pilcrow" href="#section-14">&#182;</a>
</div>
<p>Does this scope have any declared variables?
</p>
<p>Return the list of variables first declared in this scope.</p>
</div>
<div class="content"><div class='highlight'><pre>
hasDeclarations: -&gt;
!!<span class="property">@declaredVariables</span>().length</pre></div></div>
<div class="content"><div class='highlight'><pre> <span class="hljs-attribute">declaredVariables</span>:<span class="hljs-function"> -&gt;</span>
(v.name <span class="hljs-keyword">for</span> v <span class="hljs-keyword">in</span> <span class="hljs-property">@variables</span> <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>
@@ -391,37 +376,13 @@ compiler-generated variable. <code>_var</code>, <code>_var2</code>, and so on...
<div class="pilwrap ">
<a class="pilcrow" href="#section-15">&#182;</a>
</div>
<p>Return the list of variables first declared in this scope.
</p>
</div>
<div class="content"><div class='highlight'><pre>
declaredVariables: -&gt;
realVars = []
tempVars = []
<span class="keyword">for</span> v <span class="keyword">in</span> <span class="property">@variables</span> <span class="keyword">when</span> v.type <span class="keyword">is</span> <span class="string">'var'</span>
(<span class="keyword">if</span> v.name.charAt(<span class="number">0</span>) <span class="keyword">is</span> <span class="string">'_'</span> <span class="keyword">then</span> tempVars <span class="keyword">else</span> realVars).push v.name
realVars.sort().concat tempVars.sort()</pre></div></div>
</li>
<li id="section-16">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-16">&#182;</a>
</div>
<p>Return the list of assignments that are supposed to be made at the top
of this scope.
</p>
of this scope.</p>
</div>
<div class="content"><div class='highlight'><pre>
assignedVariables: -&gt;
<span class="string">"<span class="subst">#{v.name}</span> = <span class="subst">#{v.type.value}</span>"</span> <span class="keyword">for</span> v <span class="keyword">in</span> <span class="property">@variables</span> <span class="keyword">when</span> v.type.assigned</pre></div></div>
<div class="content"><div class='highlight'><pre> <span class="hljs-attribute">assignedVariables</span>:<span class="hljs-function"> -&gt;</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> <span class="hljs-property">@variables</span> <span class="hljs-keyword">when</span> v.type.assigned</pre></div></div>
</li>

View File

@@ -16,78 +16,85 @@
<a class="large" href="javascript:void(0);">Jump To &hellip;</a>
<a class="small" href="javascript:void(0);">+</a>
<div id="jump_wrapper">
<div id="jump_page">
<div id="jump_page_wrapper">
<div id="jump_page">
<a class="source" href="browser.html">
browser.coffee
</a>
<a class="source" href="browser.html">
browser.coffee
</a>
<a class="source" href="cake.html">
cake.coffee
</a>
<a class="source" href="cake.html">
cake.coffee
</a>
<a class="source" href="coffee-script.html">
coffee-script.coffee
</a>
<a class="source" href="coffee-script.html">
coffee-script.coffee
</a>
<a class="source" href="command.html">
command.coffee
</a>
<a class="source" href="command.html">
command.coffee
</a>
<a class="source" href="grammar.html">
grammar.coffee
</a>
<a class="source" href="grammar.html">
grammar.coffee
</a>
<a class="source" href="helpers.html">
helpers.coffee
</a>
<a class="source" href="helpers.html">
helpers.coffee
</a>
<a class="source" href="index.html">
index.coffee
</a>
<a class="source" href="index.html">
index.coffee
</a>
<a class="source" href="lexer.html">
lexer.coffee
</a>
<a class="source" href="lexer.html">
lexer.coffee
</a>
<a class="source" href="nodes.html">
nodes.coffee
</a>
<a class="source" href="nodes.html">
nodes.coffee
</a>
<a class="source" href="optparse.html">
optparse.coffee
</a>
<a class="source" href="optparse.html">
optparse.coffee
</a>
<a class="source" href="repl.html">
repl.coffee
</a>
<a class="source" href="register.html">
register.coffee
</a>
<a class="source" href="rewriter.html">
rewriter.coffee
</a>
<a class="source" href="repl.html">
repl.coffee
</a>
<a class="source" href="scope.html">
scope.litcoffee
</a>
<a class="source" href="rewriter.html">
rewriter.coffee
</a>
<a class="source" href="sourcemap.html">
sourcemap.litcoffee
</a>
<a class="source" href="scope.html">
scope.litcoffee
</a>
<a class="source" href="sourcemap.html">
sourcemap.litcoffee
</a>
</div>
</div>
</li>
</ul>
@@ -110,9 +117,14 @@
</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
JavaScript, but in our case, we&#39;re concerned with mapping pretty-printed
JavaScript back to CoffeeScript.
</p>
JavaScript, but in our case, were concerned with mapping pretty-printed
JavaScript back to CoffeeScript.</p>
<p>In order to produce maps, we must keep track of positions (line number, column number)
that originated every node in the syntax tree, and be able to generate a
<a href="https://docs.google.com/document/d/1U1RGAehQwRypUTovF1KRlpiOFze0b-_2gc6fAH0KY0k/edit">map file</a>
— which is a compact, VLQ-encoded representation of the JSON serialization
of this information — to write out alongside the generated JavaScript.</p>
<h2 id="linemap">LineMap</h2>
</div>
@@ -125,25 +137,34 @@ JavaScript back to CoffeeScript.
<div class="pilwrap ">
<a class="pilcrow" href="#section-2">&#182;</a>
</div>
<p>In order to produce maps, we must keep track of positions (line number, column number)
that originated every node in the syntax tree, and be able to generate a
<a href="https://docs.google.com/document/d/1U1RGAehQwRypUTovF1KRlpiOFze0b-_2gc6fAH0KY0k/edit">map file</a>
— which is a compact, VLQ-encoded representation of the JSON serialization
of this information — to write out alongside the generated JavaScript.
</p>
<p>A <strong>LineMap</strong> object keeps track of information about original line and column
positions for a single line of output JavaScript code.
<strong>SourceMaps</strong> are implemented in terms of <strong>LineMaps</strong>.</p>
</div>
<div class="content"><div class='highlight'><pre><span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">LineMap</span></span>
<span class="hljs-attribute">constructor</span>: <span class="hljs-function"><span class="hljs-params">(<span class="hljs-property">@line</span>)</span> -&gt;</span>
<span class="hljs-property">@columns</span> = []
<span class="hljs-attribute">add</span>: <span class="hljs-function"><span class="hljs-params">(column, [sourceLine, sourceColumn], options={})</span> -&gt;</span>
<span class="hljs-keyword">return</span> <span class="hljs-keyword">if</span> <span class="hljs-property">@columns</span>[column] <span class="hljs-keyword">and</span> options.noReplace
<span class="hljs-property">@columns</span>[column] = {<span class="hljs-attribute">line</span>: <span class="hljs-property">@line</span>, column, sourceLine, sourceColumn}
<span class="hljs-attribute">sourceLocation</span>: <span class="hljs-function"><span class="hljs-params">(column)</span> -&gt;</span>
column-- <span class="hljs-keyword">until</span> (mapping = <span class="hljs-property">@columns</span>[column]) <span class="hljs-keyword">or</span> (column &lt;= <span class="hljs-number">0</span>)
mapping <span class="hljs-keyword">and</span> [mapping.sourceLine, mapping.sourceColumn]</pre></div></div>
</li>
<li id="section-3">
<div class="annotation">
<div class="pilwrap for-h2">
<div class="pilwrap ">
<a class="pilcrow" href="#section-3">&#182;</a>
</div>
<h2>LineMap</h2>
<h2 id="sourcemap">SourceMap</h2>
</div>
@@ -156,9 +177,18 @@ of this information — to write out alongside the generated JavaScript.
<div class="pilwrap ">
<a class="pilcrow" href="#section-4">&#182;</a>
</div>
<p>Maps locations in a single generated JavaScript file back to locations in
the original CoffeeScript source file.</p>
<p>This is intentionally agnostic towards how a source map might be represented on
disk. Once the compiler is ready to produce a “v3”-style source map, we can walk
through the arrays of line and column buffer to produce it.</p>
</div>
<div class="content"><div class='highlight'><pre><span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">SourceMap</span></span>
<span class="hljs-attribute">constructor</span>:<span class="hljs-function"> -&gt;</span>
<span class="hljs-property">@lines</span> = []</pre></div></div>
</li>
@@ -168,25 +198,17 @@ of this information — to write out alongside the generated JavaScript.
<div class="pilwrap ">
<a class="pilcrow" href="#section-5">&#182;</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.
<strong>SourceMaps</strong> are implemented in terms of <strong>LineMaps</strong>.
</p>
<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
is already a mapping for the specified <code>line</code> and <code>column</code>, this will have no
effect.</p>
</div>
<div class="content"><div class='highlight'><pre>
<span class="class"><span class="keyword">class</span> <span class="title">LineMap</span></span>
constructor: (<span class="property">@line</span>) -&gt;
<span class="property">@columns</span> = []
add: (column, [sourceLine, sourceColumn], options={}) -&gt;
<span class="keyword">return</span> <span class="keyword">if</span> <span class="property">@columns</span>[column] <span class="keyword">and</span> options.noReplace
<span class="property">@columns</span>[column] = {line: <span class="property">@line</span>, column, sourceLine, sourceColumn}
sourceLocation: (column) -&gt;
column-- <span class="keyword">until</span> (mapping = <span class="property">@columns</span>[column]) <span class="keyword">or</span> (column &lt;= <span class="number">0</span>)
mapping <span class="keyword">and</span> [mapping.sourceLine, mapping.sourceColumn]</pre></div></div>
<div class="content"><div class='highlight'><pre> <span class="hljs-attribute">add</span>: <span class="hljs-function"><span class="hljs-params">(sourceLocation, generatedLocation, options = {})</span> -&gt;</span>
[line, column] = generatedLocation
lineMap = (<span class="hljs-property">@lines</span>[line] <span class="hljs-keyword">or</span>= <span class="hljs-keyword">new</span> LineMap(line))
lineMap.add column, sourceLocation, options</pre></div></div>
</li>
@@ -194,13 +216,18 @@ positions for a single line of output JavaScript code.
<li id="section-6">
<div class="annotation">
<div class="pilwrap for-h2">
<div class="pilwrap ">
<a class="pilcrow" href="#section-6">&#182;</a>
</div>
<h2>SourceMap</h2>
<p>Look up the original position of a given <code>line</code> and <code>column</code> in the generated
code.</p>
</div>
<div class="content"><div class='highlight'><pre> <span class="hljs-attribute">sourceLocation</span>: <span class="hljs-function"><span class="hljs-params">([line, column])</span> -&gt;</span>
line-- <span class="hljs-keyword">until</span> (lineMap = <span class="hljs-property">@lines</span>[line]) <span class="hljs-keyword">or</span> (line &lt;= <span class="hljs-number">0</span>)
lineMap <span class="hljs-keyword">and</span> lineMap.sourceLocation column</pre></div></div>
</li>
@@ -210,7 +237,8 @@ positions for a single line of output JavaScript code.
<div class="pilwrap ">
<a class="pilcrow" href="#section-7">&#182;</a>
</div>
<h2 id="v3-sourcemap-generation">V3 SourceMap Generation</h2>
</div>
</li>
@@ -222,12 +250,29 @@ positions for a single line of output JavaScript code.
<div class="pilwrap ">
<a class="pilcrow" href="#section-8">&#182;</a>
</div>
<p>Maps locations in a single generated JavaScript file back to locations in
the original CoffeeScript source file.
</p>
<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
map. Also, <code>options.sourceFiles</code> and <code>options.generatedFile</code> may be passed to
set “sources” and “file”, respectively.</p>
</div>
<div class="content"><div class='highlight'><pre> <span class="hljs-attribute">generate</span>: <span class="hljs-function"><span class="hljs-params">(options = {}, code = <span class="hljs-literal">null</span>)</span> -&gt;</span>
writingline = <span class="hljs-number">0</span>
lastColumn = <span class="hljs-number">0</span>
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>
<span class="hljs-keyword">for</span> lineMap, lineNumber <span class="hljs-keyword">in</span> <span class="hljs-property">@lines</span> <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 &lt; mapping.line
lastColumn = <span class="hljs-number">0</span>
needComma = <span class="hljs-literal">no</span>
buffer += <span class="hljs-string">";"</span>
writingline++</pre></div></div>
</li>
@@ -237,17 +282,13 @@ the original CoffeeScript source file.
<div class="pilwrap ">
<a class="pilcrow" href="#section-9">&#182;</a>
</div>
<p>This is intentionally agnostic towards how a source map might be represented on
disk. Once the compiler is ready to produce a &quot;v3&quot;-style source map, we can walk
through the arrays of line and column buffer to produce it.
</p>
<p>Write a comma if weve already written a segment on this line.</p>
</div>
<div class="content"><div class='highlight'><pre>
<span class="class"><span class="keyword">class</span> <span class="title">SourceMap</span></span>
constructor: -&gt;
<span class="property">@lines</span> = []</pre></div></div>
<div class="content"><div class='highlight'><pre> <span class="hljs-keyword">if</span> needComma
buffer += <span class="hljs-string">","</span>
needComma = <span class="hljs-literal">no</span></pre></div></div>
</li>
@@ -258,19 +299,15 @@ through the arrays of line and column buffer to produce it.
<div class="pilwrap ">
<a class="pilcrow" href="#section-10">&#182;</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
is already a mapping for the specified <code>line</code> and <code>column</code>, this will have no
effect.
</p>
<p>Write the next segment. Segments can be 1, 4, or 5 values. If just one, then it
is a generated column which doesnt match anything in the source code.</p>
<p>The starting column in the generated source, relative to any previous recorded
column for the current line:</p>
</div>
<div class="content"><div class='highlight'><pre>
add: (sourceLocation, generatedLocation, options = {}) -&gt;
[line, column] = generatedLocation
lineMap = (<span class="property">@lines</span>[line] <span class="keyword">or</span>= <span class="keyword">new</span> LineMap(line))
lineMap.add column, sourceLocation, options</pre></div></div>
<div class="content"><div class='highlight'><pre> buffer += <span class="hljs-property">@encodeVlq</span> mapping.column - lastColumn
lastColumn = mapping.column</pre></div></div>
</li>
@@ -281,16 +318,11 @@ effect.
<div class="pilwrap ">
<a class="pilcrow" href="#section-11">&#182;</a>
</div>
<p>Look up the original position of a given <code>line</code> and <code>column</code> in the generated
code.
</p>
<p>The index into the list of sources:</p>
</div>
<div class="content"><div class='highlight'><pre>
sourceLocation: ([line, column]) -&gt;
line-- <span class="keyword">until</span> (lineMap = <span class="property">@lines</span>[line]) <span class="keyword">or</span> (line &lt;= <span class="number">0</span>)
lineMap <span class="keyword">and</span> lineMap.sourceLocation column</pre></div></div>
<div class="content"><div class='highlight'><pre> buffer += <span class="hljs-property">@encodeVlq</span> <span class="hljs-number">0</span></pre></div></div>
</li>
@@ -298,13 +330,16 @@ code.
<li id="section-12">
<div class="annotation">
<div class="pilwrap for-h2">
<div class="pilwrap ">
<a class="pilcrow" href="#section-12">&#182;</a>
</div>
<h2>V3 SourceMap Generation</h2>
<p>The starting line in the original source, relative to the previous source line.</p>
</div>
<div class="content"><div class='highlight'><pre> buffer += <span class="hljs-property">@encodeVlq</span> mapping.sourceLine - lastSourceLine
lastSourceLine = mapping.sourceLine</pre></div></div>
</li>
@@ -314,9 +349,14 @@ code.
<div class="pilwrap ">
<a class="pilcrow" href="#section-13">&#182;</a>
</div>
<p>The starting column in the original source, relative to the previous column.</p>
</div>
<div class="content"><div class='highlight'><pre> buffer += <span class="hljs-property">@encodeVlq</span> mapping.sourceColumn - lastSourceColumn
lastSourceColumn = mapping.sourceColumn
needComma = <span class="hljs-literal">yes</span></pre></div></div>
</li>
@@ -326,30 +366,21 @@ code.
<div class="pilwrap ">
<a class="pilcrow" href="#section-14">&#182;</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
map. Also, <code>options.sourceFiles</code> and <code>options.generatedFile</code> may be passed to
set &quot;sources&quot; and &quot;file&quot;, respectively.
</p>
<p>Produce the canonical JSON object format for a “v3” source map.</p>
</div>
<div class="content"><div class='highlight'><pre>
generate: (options = {}, code = <span class="literal">null</span>) -&gt;
writingline = <span class="number">0</span>
lastColumn = <span class="number">0</span>
lastSourceLine = <span class="number">0</span>
lastSourceColumn = <span class="number">0</span>
needComma = <span class="literal">no</span>
buffer = <span class="string">""</span>
<div class="content"><div class='highlight'><pre> v3 =
<span class="hljs-attribute">version</span>: <span class="hljs-number">3</span>
<span class="hljs-attribute">file</span>: options.generatedFile <span class="hljs-keyword">or</span> <span class="hljs-string">''</span>
<span class="hljs-attribute">sourceRoot</span>: options.sourceRoot <span class="hljs-keyword">or</span> <span class="hljs-string">''</span>
<span class="hljs-attribute">sources</span>: options.sourceFiles <span class="hljs-keyword">or</span> [<span class="hljs-string">''</span>]
<span class="hljs-attribute">names</span>: []
<span class="hljs-attribute">mappings</span>: buffer
<span class="keyword">for</span> lineMap, lineNumber <span class="keyword">in</span> <span class="property">@lines</span> <span class="keyword">when</span> lineMap
<span class="keyword">for</span> mapping <span class="keyword">in</span> lineMap.columns <span class="keyword">when</span> mapping
<span class="keyword">while</span> writingline &lt; mapping.line
lastColumn = <span class="number">0</span>
needComma = <span class="literal">no</span>
buffer += <span class="string">";"</span>
writingline++</pre></div></div>
v3.sourcesContent = [code] <span class="hljs-keyword">if</span> options.inline
JSON.stringify v3, <span class="hljs-literal">null</span>, <span class="hljs-number">2</span></pre></div></div>
</li>
@@ -360,16 +391,10 @@ set &quot;sources&quot; and &quot;file&quot;, respectively.
<div class="pilwrap ">
<a class="pilcrow" href="#section-15">&#182;</a>
</div>
<p>Write a comma if we&#39;ve already written a segment on this line.
</p>
<h2 id="base64-vlq-encoding">Base64 VLQ Encoding</h2>
</div>
<div class="content"><div class='highlight'><pre>
<span class="keyword">if</span> needComma
buffer += <span class="string">","</span>
needComma = <span class="literal">no</span></pre></div></div>
</li>
@@ -379,12 +404,21 @@ set &quot;sources&quot; and &quot;file&quot;, respectively.
<div class="pilwrap ">
<a class="pilcrow" href="#section-16">&#182;</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&#39;t match anything in the source code.
</p>
<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
encoded value (see <a href="http://en.wikipedia.org/wiki/File:Uintvar_coding.svg">Wikipedia</a>).
SourceMap VLQ does things the other way around, with the least significat four
bits of the original value encoded into the first byte of the VLQ encoded value.</p>
</div>
<div class="content"><div class='highlight'><pre> VLQ_SHIFT = <span class="hljs-number">5</span>
VLQ_CONTINUATION_BIT = <span class="hljs-number">1</span> &lt;&lt; VLQ_SHIFT <span class="hljs-comment"># 0010 0000</span>
VLQ_VALUE_MASK = VLQ_CONTINUATION_BIT - <span class="hljs-number">1</span> <span class="hljs-comment"># 0001 1111</span>
<span class="hljs-attribute">encodeVlq</span>: <span class="hljs-function"><span class="hljs-params">(value)</span> -&gt;</span>
answer = <span class="hljs-string">''</span></pre></div></div>
</li>
@@ -394,15 +428,11 @@ is a generated column which doesn&#39;t match anything in the source code.
<div class="pilwrap ">
<a class="pilcrow" href="#section-17">&#182;</a>
</div>
<p>The starting column in the generated source, relative to any previous recorded
column for the current line:
</p>
<p>Least significant bit represents the sign.</p>
</div>
<div class="content"><div class='highlight'><pre>
buffer += <span class="property">@encodeVlq</span> mapping.column - lastColumn
lastColumn = mapping.column</pre></div></div>
<div class="content"><div class='highlight'><pre> signBit = <span class="hljs-keyword">if</span> value &lt; <span class="hljs-number">0</span> <span class="hljs-keyword">then</span> <span class="hljs-number">1</span> <span class="hljs-keyword">else</span> <span class="hljs-number">0</span></pre></div></div>
</li>
@@ -413,13 +443,11 @@ column for the current line:
<div class="pilwrap ">
<a class="pilcrow" href="#section-18">&#182;</a>
</div>
<p>The index into the list of sources:
</p>
<p>The next bits are the actual value.</p>
</div>
<div class="content"><div class='highlight'><pre>
buffer += <span class="property">@encodeVlq</span> <span class="number">0</span></pre></div></div>
<div class="content"><div class='highlight'><pre> valueToEncode = (Math.abs(value) &lt;&lt; <span class="hljs-number">1</span>) + signBit</pre></div></div>
</li>
@@ -430,14 +458,17 @@ column for the current line:
<div class="pilwrap ">
<a class="pilcrow" href="#section-19">&#182;</a>
</div>
<p>The starting line in the original source, relative to the previous source line.
</p>
<p>Make sure we encode at least one character, even if valueToEncode is 0.</p>
</div>
<div class="content"><div class='highlight'><pre>
buffer += <span class="property">@encodeVlq</span> mapping.sourceLine - lastSourceLine
lastSourceLine = mapping.sourceLine</pre></div></div>
<div class="content"><div class='highlight'><pre> <span class="hljs-keyword">while</span> valueToEncode <span class="hljs-keyword">or</span> <span class="hljs-keyword">not</span> answer
nextChunk = valueToEncode &amp; VLQ_VALUE_MASK
valueToEncode = valueToEncode &gt;&gt; VLQ_SHIFT
nextChunk |= VLQ_CONTINUATION_BIT <span class="hljs-keyword">if</span> valueToEncode
answer += <span class="hljs-property">@encodeBase64</span> nextChunk
answer</pre></div></div>
</li>
@@ -448,16 +479,10 @@ column for the current line:
<div class="pilwrap ">
<a class="pilcrow" href="#section-20">&#182;</a>
</div>
<p>The starting column in the original source, relative to the previous column.
</p>
<h2 id="regular-base64-encoding">Regular Base64 Encoding</h2>
</div>
<div class="content"><div class='highlight'><pre>
buffer += <span class="property">@encodeVlq</span> mapping.sourceColumn - lastSourceColumn
lastSourceColumn = mapping.sourceColumn
needComma = <span class="literal">yes</span></pre></div></div>
</li>
@@ -467,23 +492,13 @@ column for the current line:
<div class="pilwrap ">
<a class="pilcrow" href="#section-21">&#182;</a>
</div>
<p>Produce the canonical JSON object format for a &quot;v3&quot; source map.
</p>
</div>
<div class="content"><div class='highlight'><pre>
v3 =
version: <span class="number">3</span>
file: options.generatedFile <span class="keyword">or</span> <span class="string">''</span>
sourceRoot: options.sourceRoot <span class="keyword">or</span> <span class="string">''</span>
sources: options.sourceFiles <span class="keyword">or</span> [<span class="string">''</span>]
names: []
mappings: buffer
<div class="content"><div class='highlight'><pre> BASE64_CHARS = <span class="hljs-string">'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'</span>
v3.sourcesContent = [code] <span class="keyword">if</span> options.inline
JSON.stringify v3, <span class="literal">null</span>, <span class="number">2</span></pre></div></div>
<span class="hljs-attribute">encodeBase64</span>: <span class="hljs-function"><span class="hljs-params">(value)</span> -&gt;</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>
</li>
@@ -491,152 +506,14 @@ column for the current line:
<li id="section-22">
<div class="annotation">
<div class="pilwrap for-h2">
<div class="pilwrap ">
<a class="pilcrow" href="#section-22">&#182;</a>
</div>
<h2>Base64 VLQ Encoding</h2>
<p>Our API for source maps is just the <code>SourceMap</code> class.</p>
</div>
</li>
<li id="section-23">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-23">&#182;</a>
</div>
</div>
</li>
<li id="section-24">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-24">&#182;</a>
</div>
<p>Note that SourceMap VLQ encoding is &quot;backwards&quot;. MIDI-style VLQ encoding puts
the most-significant-bit (MSB) from the original value into the MSB of the VLQ
encoded value (see <a href="http://en.wikipedia.org/wiki/File:Uintvar_coding.svg">Wikipedia</a>).
SourceMap VLQ does things the other way around, with the least significat four
bits of the original value encoded into the first byte of the VLQ encoded value.
</p>
</div>
<div class="content"><div class='highlight'><pre>
VLQ_SHIFT = <span class="number">5</span>
VLQ_CONTINUATION_BIT = <span class="number">1</span> &lt;&lt; VLQ_SHIFT <span class="comment"># 0010 0000</span>
VLQ_VALUE_MASK = VLQ_CONTINUATION_BIT - <span class="number">1</span> <span class="comment"># 0001 1111</span>
encodeVlq: (value) -&gt;
answer = <span class="string">''</span></pre></div></div>
</li>
<li id="section-25">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-25">&#182;</a>
</div>
<p>Least significant bit represents the sign.
</p>
</div>
<div class="content"><div class='highlight'><pre> signBit = <span class="keyword">if</span> value &lt; <span class="number">0</span> <span class="keyword">then</span> <span class="number">1</span> <span class="keyword">else</span> <span class="number">0</span></pre></div></div>
</li>
<li id="section-26">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-26">&#182;</a>
</div>
<p>The next bits are the actual value.
</p>
</div>
<div class="content"><div class='highlight'><pre> valueToEncode = (Math.abs(value) &lt;&lt; <span class="number">1</span>) + signBit</pre></div></div>
</li>
<li id="section-27">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-27">&#182;</a>
</div>
<p>Make sure we encode at least one character, even if valueToEncode is 0.
</p>
</div>
<div class="content"><div class='highlight'><pre> <span class="keyword">while</span> valueToEncode <span class="keyword">or</span> <span class="keyword">not</span> answer
nextChunk = valueToEncode &amp; VLQ_VALUE_MASK
valueToEncode = valueToEncode &gt;&gt; VLQ_SHIFT
nextChunk |= VLQ_CONTINUATION_BIT <span class="keyword">if</span> valueToEncode
answer += <span class="property">@encodeBase64</span> nextChunk
answer</pre></div></div>
</li>
<li id="section-28">
<div class="annotation">
<div class="pilwrap for-h2">
<a class="pilcrow" href="#section-28">&#182;</a>
</div>
<h2>Regular Base64 Encoding</h2>
</div>
</li>
<li id="section-29">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-29">&#182;</a>
</div>
</div>
<div class="content"><div class='highlight'><pre>
BASE64_CHARS = <span class="string">'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'</span>
encodeBase64: (value) -&gt;
BASE64_CHARS[value] <span class="keyword">or</span> <span class="keyword">throw</span> <span class="keyword">new</span> Error <span class="string">"Cannot Base64 encode value: <span class="subst">#{value}</span>"</span></pre></div></div>
</li>
<li id="section-30">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-30">&#182;</a>
</div>
<p>Our API for source maps is just the <code>SourceMap</code> class.
</p>
</div>
<div class="content"><div class='highlight'><pre>
module.exports = SourceMap</pre></div></div>
<div class="content"><div class='highlight'><pre><span class="hljs-built_in">module</span>.<span class="hljs-built_in">exports</span> = SourceMap</pre></div></div>
</li>

File diff suppressed because one or more lines are too long

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.1 KiB

After

Width:  |  Height:  |  Size: 6.4 KiB

View File

@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Generator: Adobe Illustrator 18.1.0, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
viewBox="-76 212 458 369" enable-background="new -76 212 458 369" xml:space="preserve">
<title>CoffeeScript Logo</title>
<g>
<g>
<path fill="#28334C" d="M106,228.6c0.5,2.3-0.9,4.4-5,6.5c-5.5-3.1-16.9-4.4-26.7-3.5c-10.4,0.9-19.4,4.2-17.9,11.3
c1.5,7.1,11.7,11,29.5,9.5c43.6-3.8,43.4-33.3,107.4-39c49.8-4.4,77.8,11,81.8,29.7c3.1,14.7-9.1,28.6-45.2,31.8
c-32,2.8-50.7-5.6-52.6-14.6c-1-4.5,1.8-11.3,17.2-13.1c1.5,7,10.6,14.4,31.1,12.6c14.8-1.3,27.6-6.6,25.9-14.9
c-1.8-8.6-17.7-13.7-42.6-11.5c-50.7,4.5-63.2,32.5-106.8,36.3c-30.8,2.7-55.9-8.5-59.4-25.1c-1.3-6.1-1.4-21,31.2-23.9
C91,219.2,104.6,222.2,106,228.6L106,228.6z M-56.4,402.5c-14.3,18-20.4,38.8-19.2,59.2c1.2,20.4,11.4,37.1,26.9,50.2
C-32,525-14,528.6,6.4,525c7.8-1.2,16.7-5.3,24.5-7.8c-16.7,0-31-5.3-44.9-16.7c-15.5-11.4-25.7-26.9-28.2-46.1
c-3.7-18,0-34.7,10.2-49c11.4-14.3,25.7-22,44.9-24.5c19.2-1.2,35.9,3.7,52.6,15.5c-3.7-5.3-9-9-14.3-14.3
c-16.7-11.4-34.7-16.7-56.7-11.4C-25.4,374.3-42.2,384.5-56.4,402.5z M167.2,306.2c-53.9,0-101.6-5.3-136.3-13.1
c-37.1-9-56.7-19.2-56.7-32.2c0-5.3,2.4-10.2,10.2-15.5c-23.3,9-35.9,16.7-35.9,28.2c1.2,13.1,22,25.7,64.5,35.9
c40,10.2,91.4,15.5,153,15.5c62.8,0,113-5.3,153-15.5c42.4-10.2,62.8-23.3,62.8-35.9c0-9-9-18-25.7-24.5c3.7,2.4,6.5,6.5,6.5,11.4
c0,13.1-19.2,23.3-57.9,32.2C268.7,300.9,222.6,306.2,167.2,306.2L167.2,306.2z M320.2,342.1c-40,9-91.4,15.5-153,15.5
c-62.8,0-114.2-6.5-154.2-15.5c-35.9-9-55.1-19.2-61.6-29.4c6.5,44.9,22,87.3,42.4,124.8c15.5,23.3,31,43.7,46.1,65.7
c6.5,13.1,11.4,25.7,14.3,38.8c10.2,14.3,24.5,23.3,42.4,28.2c22,7.8,44.9,11.4,68.1,10.2h2.4c23.3,1.2,47.7-2.4,70.6-10.2
c16.7-5.3,31-14.3,41.2-28.2h1.2c2.4-13.1,6.5-25.7,13.1-38.8c15.5-22,31-42.4,46.1-65.7c20.4-37.1,34.7-79.6,42.4-124.8
C374,324.1,354.8,334.3,320.2,342.1L320.2,342.1z"/>
</g>
</g>
</svg>

After

Width:  |  Height:  |  Size: 2.1 KiB

View File

@@ -0,0 +1,59 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Generator: Adobe Illustrator 18.1.0, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
viewBox="-22 347 566 100" enable-background="new -22 347 566 100" xml:space="preserve">
<title>CoffeeScript Logo</title>
<g>
<g>
<path id="Shape" fill="#28334C" d="M21.7,351.1c0.1,0.6-0.2,1.1-1.2,1.6c-1.3-0.7-4.1-1.1-6.4-0.9c-2.5,0.2-4.6,1-4.3,2.7
c0.4,1.7,2.8,2.7,7.1,2.3c10.5-0.9,10.4-8,25.8-9.4c12-1.1,18.7,2.6,19.6,7.1c0.7,3.5-2.2,6.9-10.9,7.6
c-7.7,0.7-12.2-1.4-12.6-3.5c-0.2-1.1,0.4-2.7,4.1-3.1c0.4,1.7,2.5,3.5,7.5,3c3.6-0.3,6.6-1.6,6.2-3.6c-0.4-2.1-4.2-3.3-10.2-2.8
c-12.2,1.1-15.2,7.8-25.6,8.7c-7.4,0.7-13.4-2-14.2-6c-0.3-1.5-0.3-5,7.5-5.7C18.1,348.8,21.3,349.5,21.7,351.1z M-17.3,392.9
c-3.4,4.3-4.9,9.3-4.6,14.2c0.3,4.9,2.7,8.9,6.5,12c4,3.1,8.3,4,13.2,3.1c1.9-0.3,4-1.3,5.9-1.9c-4,0-7.4-1.3-10.8-4
c-3.7-2.7-6.2-6.5-6.8-11.1c-0.9-4.3,0-8.3,2.4-11.8c2.7-3.4,6.2-5.3,10.8-5.9c4.6-0.3,8.6,0.9,12.6,3.7c-0.9-1.3-2.2-2.2-3.4-3.4
c-4-2.7-8.3-4-13.6-2.7C-9.9,386.1-13.9,388.6-17.3,392.9z M36.3,369.8c-12.9,0-24.4-1.3-32.7-3.1c-8.9-2.2-13.6-4.6-13.6-7.7
c0-1.3,0.6-2.4,2.4-3.7c-5.6,2.2-8.6,4-8.6,6.8c0.3,3.1,5.3,6.2,15.5,8.6c9.6,2.4,21.9,3.7,36.7,3.7c15.1,0,27.1-1.3,36.7-3.7
c10.2-2.4,15.1-5.6,15.1-8.6c0-2.2-2.2-4.3-6.2-5.9c0.9,0.6,1.6,1.6,1.6,2.7c0,3.1-4.6,5.6-13.9,7.7
C60.7,368.5,49.7,369.8,36.3,369.8z M73.1,378.4c-9.6,2.2-21.9,3.7-36.7,3.7c-15.1,0-27.4-1.6-37-3.7c-8.6-2.2-13.2-4.6-14.8-7.1
c1.6,10.8,5.3,21,10.2,30c3.7,5.6,7.4,10.5,11.1,15.8c1.6,3.1,2.7,6.2,3.4,9.3c2.4,3.4,5.9,5.6,10.2,6.8
c5.3,1.9,10.8,2.7,16.4,2.4h0.6c5.6,0.3,11.5-0.6,16.9-2.4c4-1.3,7.4-3.4,9.9-6.8h0.3c0.6-3.1,1.6-6.2,3.1-9.3
c3.7-5.3,7.4-10.2,11.1-15.8c4.9-8.9,8.3-19.1,10.2-30C86,374.1,81.4,376.5,73.1,378.4z"/>
<g>
<path fill="#28334C" d="M179.3,408.5c-4.8,12.1-17.6,16.9-25.9,16.9c-13.4,0-19.9-6-19.9-22.3c0-16.5,7.9-47.3,31.7-47.3
c8.5,0,15.2,3.3,15.2,12.1c0,4.8-1.8,8.3-6.4,8.3c-1.5,0-3.4-0.4-5.2-2.4c2.2-1.1,4.2-4.9,4.2-8.3c0-2.9-1.5-5.6-5.6-5.6
c-10,0-18.9,23.9-18.9,42.4c0,8.3,2.2,14.2,10.9,14.2c7.1,0,13.5-3.4,17.7-9.1L179.3,408.5z M212.2,392.2c0.4,0.2,0.7,0.2,1,0.2
c4.2,0,10.1-2.7,14-5.5l0.8,2.4c-3.4,3.7-9.5,6.5-16.1,7.5c-1.5,16.8-10.6,27.3-21.7,27.3c-8.4,0-14.5-4-14.5-14.4
c0-10.5,6.2-32.2,24.9-32.2C208.4,377.8,212.2,382.8,212.2,392.2z M204.5,397.2c-1.9-0.5-2.4-2-2.4-3.8c0-2.5,1.2-4.2,2.8-4.9
c-0.2-3.8-1.1-5.3-3.4-5.3c-6.5,0-12,16.6-12,25.6c0,6,1.2,7.3,4.6,7.3C198.3,416.2,203,408.1,204.5,397.2L204.5,397.2z
M197.9,436.9c0-8.3,7.1-11,15.8-13.6l10.9-51.9c2.7-13,10.6-15.5,16.5-15.5c4.1,0,8,2.2,9.7,5.7c3.6-4.6,8.4-5.7,12.4-5.7
c5.6,0,10.8,3.9,10.8,9.8c0,1.5-0.1,2.6-0.3,3.7h-4.3c0.1-0.9,0.2-1.7,0.2-2.4c0-2.1-1.7-3.1-3.4-3.1c-2,0-4.8,1.1-6.2,7.1
l-1.7,7.4h9.1l-0.8,3.6h-9l-10.3,49.1c-2.7,13-10.6,15.5-16.5,15.5c-5.2,0-8.3-2.3-9.8-5.7c-3.5,4.6-8.3,5.7-12.3,5.7
C203.1,446.7,197.9,442.8,197.9,436.9L197.9,436.9z M207,438.7c1.9,0,4.2-1.8,5.4-7.1l1.1-5.3c-5.7,2-10.1,4.4-10.1,9.4
C203.4,436.9,205.1,438.7,207,438.7z M228.7,438.7c1.9,0,4.2-1.8,5.4-7.1l2.2-10.4l-9.4,1.8l-1.8,8.3c-0.5,2.1-1.1,4-1.8,5.6
C224.2,438.2,226.3,438.7,228.7,438.7L228.7,438.7z M227.3,420.7l9.4-1.7l7.7-36.8h-9L227.3,420.7L227.3,420.7z M243.9,364
c-2,0-4.8,1.1-6.2,7.1l-1.7,7.4h9l2.1-9.5c0.2-0.7,0.2-1.3,0.2-2C247.4,365,245.8,364,243.9,364z M281.8,417
c7.1,0,11.6-4,16.1-9.2h3.1c-5.2,8.3-12.9,16.8-25,16.8c-8.5,0-14.2-4.2-14.2-14.5c0-10.5,5.9-32.3,24.6-32.3
c8.1,0,10,4.2,10,8.7c0,10.5-10,18.5-20.9,19.2c-0.1,1.3-0.2,2.5-0.2,3.6C275.3,415.5,277.5,417,281.8,417z M287.1,382.6
c-4.6,0-9.1,9.7-10.9,18.7c7-0.5,13.2-7.4,13.2-15C289.4,384.1,288.9,382.6,287.1,382.6L287.1,382.6z M315.7,416
c3.4,0,7.8-2.3,10.8-4.8c-2,10.4-8.4,13.4-15.8,13.4c-8.4,0-14.1-4.2-14.1-14.5c0-10.5,5.9-32.3,24.6-32.3c8.1,0,10,4.2,10,8.7
c0,10.6-10,18.5-20.9,19.2c-0.1,0.9-0.2,2-0.2,2.7C310.1,414.1,312.6,416,315.7,416z M321.9,382.6c-4.5,0-9.1,10.1-11,18.7
c7.1-0.4,13.3-7.3,13.3-15C324.2,384.1,323.6,382.6,321.9,382.6z M373.2,375.9c-1.7,0-3-0.6-4.2-1.9c2.4-1.5,4.1-4.8,4.1-7.8
c0-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.8c0,15.3-12.3,22.7-25.6,22.7c-10.4,0-19.3-4.5-19.3-15.7
c0-9.8,7-14.9,13.3-14.9c3.1,0,7.7,1.3,8,6c-4.9,0-10.7,2.3-10.7,8.5c0,4.5,2.9,8.7,8.7,8.7c6.1,0,10.6-4.4,10.6-12
c0-15.6-18.6-21.1-18.6-34.5c0-9.5,9.3-16.3,21-16.3c4.3,0,14.6,0.9,14.6,10.9C380.6,372,377.7,375.9,373.2,375.9L373.2,375.9z
M409.4,386.2c0-2.3-0.8-3.7-2.5-3.7c-5.7,0-11.7,16.6-11.7,26.7c0,6.2,2.2,7.6,6.6,7.6c7.1,0,11.6-4,16.1-9.2h3.1
c-5.2,8.3-12.9,16.8-25,16.8c-8.5,0-14.2-4.2-14.2-14.5c0-10.6,6-32.3,24.5-32.3c8.1,0,10.1,4.2,10.1,8.3c0,4.4-2.2,6.7-4.8,6.7
c-1,0-2.1-0.4-3.1-1.1C409,389.6,409.4,387.9,409.4,386.2z M437.1,378.6l-1.2,5.7c3.1-2.7,6.7-5.7,11-5.7c4.1,0,6.3,3.3,6.3,6.9
c0,3.1-2.1,6.7-6.6,6.7c-5.1,0-2.5-6-5.3-6c-2.7,0-4.4,1.4-6.7,3.4l-7.2,34.6h-13.1l9.6-45.4L437.1,378.6L437.1,378.6z
M471.3,378.6l-6.6,30.9c-0.3,1.2-0.4,2.1-0.4,2.9c0,2.5,1.2,3.3,3.7,3.3c3.5,0,6.9-3.4,8.1-8h3.8c-5.2,14.8-14.2,16.8-19.1,16.8
c-5.5,0-9.7-3.2-9.7-10.9c0-1.8,0.3-3.7,0.7-5.9l6.2-29.2C458,378.5,471.3,378.6,471.3,378.6z M467.2,359.2c4,0,7.2,3.2,7.2,7.2
s-3.2,7.1-7.2,7.1s-7.1-3.1-7.1-7.1C460,362.4,463.3,359.2,467.2,359.2z M496.3,375.2l-1.5,6.9c2.6-2.3,6.1-3.9,10.7-3.9
c6.2,0,11.1,3.5,11.1,14.4c0,12.2-4.7,32.1-22.3,32.1c-4.5,0-6.8-1.6-7.7-3.2l-4.7,22.1l-13.7,3.2l15.2-71.5
C483.4,375.3,496.3,375.2,496.3,375.2z M504.1,392.2c0-7-2.9-7.5-4.5-7.5c-2,0-4.5,1.6-6.3,4.4l-5.4,25.5c0.4,1,1.4,2.1,3.4,2.1
C501,416.7,504.1,400.8,504.1,392.2z M531.9,409.5c-0.3,1.1-0.5,2.2-0.5,3.1c0,1.9,0.7,3.2,3.1,3.2c0.7,0,1.7,0,2.4-0.3
c-2.5,7.8-6.6,8.9-9.6,8.9c-6.4,0-9.1-4.4-9.1-10.3c0-1.6,0.2-3.1,0.6-4.8l5.8-27.2h-3l0.7-3.6h3L528,366l13.4-1.9
c0,0-1.4,6.2-3.1,14.4h5.5l-0.7,3.6h-5.5L531.9,409.5z"/>
</g>
</g>
</g>
</svg>

After

Width:  |  Height:  |  Size: 5.9 KiB

File diff suppressed because it is too large Load Diff

View File

@@ -1,4 +1,4 @@
// Generated by CoffeeScript 1.6.3
// Generated by CoffeeScript 1.9.2
var volume, winner;
if (ignition === true) {

View File

@@ -1,23 +1,23 @@
// Generated by CoffeeScript 1.6.3
var courses, dish, food, foods, i, _i, _j, _k, _len, _len1, _len2, _ref;
// Generated by CoffeeScript 1.9.2
var courses, dish, food, foods, i, j, k, l, len, len1, len2, ref;
_ref = ['toast', 'cheese', 'wine'];
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
food = _ref[_i];
ref = ['toast', 'cheese', 'wine'];
for (j = 0, len = ref.length; j < len; j++) {
food = ref[j];
eat(food);
}
courses = ['greens', 'caviar', 'truffles', 'roast', 'cake'];
for (i = _j = 0, _len1 = courses.length; _j < _len1; i = ++_j) {
for (i = k = 0, len1 = courses.length; k < len1; i = ++k) {
dish = courses[i];
menu(i + 1, dish);
}
foods = ['broccoli', 'spinach', 'chocolate'];
for (_k = 0, _len2 = foods.length; _k < _len2; _k++) {
food = foods[_k];
for (l = 0, len2 = foods.length; l < len2; l++) {
food = foods[l];
if (food !== 'chocolate') {
eat(food);
}

View File

@@ -1,7 +1,7 @@
// Generated by CoffeeScript 1.6.3
// Generated by CoffeeScript 1.9.2
/*
SkinnyMochaHalfCaffScript Compiler v1.0
Released under the MIT License
*/
*/

View File

@@ -1,4 +1,4 @@
// Generated by CoffeeScript 1.6.3
// Generated by CoffeeScript 1.9.2
var fs;
fs = require('fs');
@@ -10,5 +10,5 @@ task('build:parser', 'rebuild the Jison parser', function(options) {
require('jison');
code = require('./lib/grammar').parser.generate();
dir = options.output || 'lib';
return fs.writeFile("" + dir + "/parser.js", code);
return fs.writeFile(dir + "/parser.js", code);
});

View File

@@ -0,0 +1,4 @@
// Generated by CoffeeScript 1.9.2
$('body').click(function(e) {
return $('.box').fadeIn('fast').addClass('.active');
}).css('background', 'white');

View File

@@ -1,7 +1,7 @@
// Generated by CoffeeScript 1.6.3
var Animal, Horse, Snake, sam, tom, _ref, _ref1,
__hasProp = {}.hasOwnProperty,
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
// Generated by CoffeeScript 1.9.2
var Animal, Horse, Snake, sam, tom,
extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
hasProp = {}.hasOwnProperty;
Animal = (function() {
function Animal(name) {
@@ -16,12 +16,11 @@ Animal = (function() {
})();
Snake = (function(_super) {
__extends(Snake, _super);
Snake = (function(superClass) {
extend(Snake, superClass);
function Snake() {
_ref = Snake.__super__.constructor.apply(this, arguments);
return _ref;
return Snake.__super__.constructor.apply(this, arguments);
}
Snake.prototype.move = function() {
@@ -33,12 +32,11 @@ Snake = (function(_super) {
})(Animal);
Horse = (function(_super) {
__extends(Horse, _super);
Horse = (function(superClass) {
extend(Horse, superClass);
function Horse() {
_ref1 = Horse.__super__.constructor.apply(this, arguments);
return _ref1;
return Horse.__super__.constructor.apply(this, arguments);
}
Horse.prototype.move = function() {

View File

@@ -1,4 +1,4 @@
// Generated by CoffeeScript 1.6.3
// Generated by CoffeeScript 1.9.2
var cholesterol, healthy;
cholesterol = 127;

View File

@@ -1,4 +1,4 @@
// Generated by CoffeeScript 1.6.3
// Generated by CoffeeScript 1.9.2
var date, mood;
if (singing) {

View File

@@ -1,5 +1,5 @@
// Generated by CoffeeScript 1.6.3
var Person;
// Generated by CoffeeScript 1.9.2
var Person, tim;
Person = (function() {
function Person(options) {
@@ -9,3 +9,7 @@ Person = (function() {
return Person;
})();
tim = new Person({
age: 4
});

View File

@@ -1,4 +1,4 @@
// Generated by CoffeeScript 1.6.3
// Generated by CoffeeScript 1.9.2
var fill;
fill = function(container, liquid) {

View File

@@ -1,12 +1,12 @@
// Generated by CoffeeScript 1.6.3
var filename, _fn, _i, _len;
// Generated by CoffeeScript 1.9.2
var filename, fn, i, len;
_fn = function(filename) {
fn = function(filename) {
return fs.readFile(filename, function(err, contents) {
return compile(filename, contents.toString());
});
};
for (_i = 0, _len = list.length; _i < _len; _i++) {
filename = list[_i];
_fn(filename);
for (i = 0, len = list.length; i < len; i++) {
filename = list[i];
fn(filename);
}

View File

@@ -1,4 +1,4 @@
// Generated by CoffeeScript 1.6.3
// Generated by CoffeeScript 1.9.2
var hi;
hi = function() {

View File

@@ -1,4 +1,4 @@
// Generated by CoffeeScript 1.6.3
// Generated by CoffeeScript 1.9.2
var footprints, solipsism, speed;
if ((typeof mind !== "undefined" && mind !== null) && (typeof world === "undefined" || world === null)) {

View File

@@ -0,0 +1,6 @@
// Generated by CoffeeScript 1.9.2
var first, last, ref, text;
text = "Every literary critic believes he will outwit history and have the last word";
ref = text.split(" "), first = ref[0], last = ref[ref.length - 1];

View File

@@ -1,4 +1,4 @@
// Generated by CoffeeScript 1.6.3
// Generated by CoffeeScript 1.9.2
var eldest, grade;
grade = function(student) {

View File

@@ -1,4 +1,4 @@
// Generated by CoffeeScript 1.6.3
// Generated by CoffeeScript 1.9.2
var one, six, three, two;
six = (one = 1) + (two = 2) + (three = 3);

View File

@@ -1,11 +1,11 @@
// Generated by CoffeeScript 1.6.3
// Generated by CoffeeScript 1.9.2
var globals, name;
globals = ((function() {
var _results;
_results = [];
var results;
results = [];
for (name in window) {
_results.push(name);
results.push(name);
}
return _results;
return results;
})()).slice(0, 10);

View File

@@ -1,4 +1,4 @@
// Generated by CoffeeScript 1.6.3
// Generated by CoffeeScript 1.9.2
var error;
alert((function() {

View File

@@ -1,11 +1,12 @@
// Generated by CoffeeScript 1.6.3
// Generated by CoffeeScript 1.9.2
var Account;
Account = function(customer, cart) {
var _this = this;
this.customer = customer;
this.cart = cart;
return $('.shopping_cart').bind('click', function(event) {
return _this.customer.purchase(_this.cart);
});
return $('.shopping_cart').on('click', (function(_this) {
return function(event) {
return _this.customer.purchase(_this.cart);
};
})(this));
};

View File

@@ -1,4 +1,4 @@
// Generated by CoffeeScript 1.6.3
// Generated by CoffeeScript 1.9.2
var cube, square;
square = function(x) {

View File

@@ -0,0 +1,13 @@
// Generated by CoffeeScript 1.9.2
var perfectSquares;
perfectSquares = function*() {
var num;
num = 0;
while (true) {
num += 1;
(yield num * num);
}
};
window.ps || (window.ps = perfectSquares());

View File

@@ -1,4 +1,4 @@
// Generated by CoffeeScript 1.6.3
// Generated by CoffeeScript 1.9.2
var html;
html = "<strong>\n cup of coffeescript\n</strong>";

View File

@@ -1,4 +1,4 @@
// Generated by CoffeeScript 1.6.3
// Generated by CoffeeScript 1.9.2
var OPERATOR;
OPERATOR = /^(?:[-=]>|[-+*\/%<>&|^!?=]=|>>>=?|([-+:])\1|([&|<>])\2=?|\?\.|\.{2,3})/;

View File

@@ -1,8 +1,8 @@
// Generated by CoffeeScript 1.6.3
// Generated by CoffeeScript 1.9.2
var author, quote, sentence;
author = "Wittgenstein";
quote = "A picture is a fact. -- " + author;
sentence = "" + (22 / 7) + " is a decent approximation of π";
sentence = (22 / 7) + " is a decent approximation of π";

View File

@@ -1,8 +1,8 @@
// Generated by CoffeeScript 1.6.3
var city, forecast, temp, weatherReport, _ref;
// Generated by CoffeeScript 1.9.2
var city, forecast, ref, temp, weatherReport;
weatherReport = function(location) {
return [location, 72, "Mostly Sunny"];
};
_ref = weatherReport("Berkeley, CA"), city = _ref[0], temp = _ref[1], forecast = _ref[2];
ref = weatherReport("Berkeley, CA"), city = ref[0], temp = ref[1], forecast = ref[2];

View File

@@ -1,4 +1,4 @@
// Generated by CoffeeScript 1.6.3
// Generated by CoffeeScript 1.9.2
var age, ages, child, yearsOld;
yearsOld = {
@@ -8,11 +8,11 @@ yearsOld = {
};
ages = (function() {
var _results;
_results = [];
var results;
results = [];
for (child in yearsOld) {
age = yearsOld[child];
_results.push("" + child + " is " + age);
results.push(child + " is " + age);
}
return _results;
return results;
})();

View File

@@ -1,5 +1,5 @@
// Generated by CoffeeScript 1.6.3
var city, futurists, name, street, _ref, _ref1;
// Generated by CoffeeScript 1.9.2
var city, futurists, name, ref, ref1, street;
futurists = {
sculptor: "Umberto Boccioni",
@@ -10,4 +10,4 @@ futurists = {
}
};
_ref = futurists.poet, name = _ref.name, (_ref1 = _ref.address, street = _ref1[0], city = _ref1[1]);
ref = futurists.poet, name = ref.name, (ref1 = ref.address, street = ref1[0], city = ref1[1]);

View File

@@ -1,4 +1,4 @@
// Generated by CoffeeScript 1.6.3
// Generated by CoffeeScript 1.9.2
var bitlist, kids, singers, song;
song = ["do", "re", "mi", "fa", "so"];

View File

@@ -1,4 +1,4 @@
// Generated by CoffeeScript 1.6.3
// Generated by CoffeeScript 1.9.2
$('.account').attr({
"class": 'active'
});

View File

@@ -1,6 +1,6 @@
// Generated by CoffeeScript 1.6.3
// Generated by CoffeeScript 1.9.2
var cubes, list, math, num, number, opposite, race, square,
__slice = [].slice;
slice = [].slice;
number = 42;
@@ -26,7 +26,7 @@ math = {
race = function() {
var runners, winner;
winner = arguments[0], runners = 2 <= arguments.length ? __slice.call(arguments, 1) : [];
winner = arguments[0], runners = 2 <= arguments.length ? slice.call(arguments, 1) : [];
return print(winner, runners);
};
@@ -35,11 +35,11 @@ if (typeof elvis !== "undefined" && elvis !== null) {
}
cubes = (function() {
var _i, _len, _results;
_results = [];
for (_i = 0, _len = list.length; _i < _len; _i++) {
num = list[_i];
_results.push(math.cube(num));
var i, len, results;
results = [];
for (i = 0, len = list.length; i < len; i++) {
num = list[i];
results.push(math.cube(num));
}
return _results;
return results;
})();

View File

@@ -1,8 +1,8 @@
// Generated by CoffeeScript 1.6.3
var theBait, theSwitch, _ref;
// Generated by CoffeeScript 1.9.2
var ref, theBait, theSwitch;
theBait = 1000;
theSwitch = 0;
_ref = [theSwitch, theBait], theBait = _ref[0], theSwitch = _ref[1];
ref = [theSwitch, theBait], theBait = ref[0], theSwitch = ref[1];

View File

@@ -1,7 +1,7 @@
// Generated by CoffeeScript 1.6.3
var close, contents, open, tag, _i, _ref,
__slice = [].slice;
// Generated by CoffeeScript 1.9.2
var close, contents, i, open, ref, tag,
slice = [].slice;
tag = "<impossible>";
_ref = tag.split(""), open = _ref[0], contents = 3 <= _ref.length ? __slice.call(_ref, 1, _i = _ref.length - 1) : (_i = 1, []), close = _ref[_i++];
ref = tag.split(""), open = ref[0], contents = 3 <= ref.length ? slice.call(ref, 1, i = ref.length - 1) : (i = 1, []), close = ref[i++];

View File

@@ -1,4 +1,4 @@
// Generated by CoffeeScript 1.6.3
// Generated by CoffeeScript 1.9.2
String.prototype.dasherize = function() {
return this.replace(/_/g, "-");
};

View File

@@ -1,11 +1,11 @@
// Generated by CoffeeScript 1.6.3
// Generated by CoffeeScript 1.9.2
var countdown, num;
countdown = (function() {
var _i, _results;
_results = [];
for (num = _i = 10; _i >= 1; num = --_i) {
_results.push(num);
var i, results;
results = [];
for (num = i = 10; i >= 1; num = --i) {
results.push(num);
}
return _results;
return results;
})();

View File

@@ -1,4 +1,4 @@
// Generated by CoffeeScript 1.6.3
// Generated by CoffeeScript 1.9.2
var changeNumbers, inner, outer;
outer = 1;

View File

@@ -1,12 +1,12 @@
// Generated by CoffeeScript 1.6.3
// Generated by CoffeeScript 1.9.2
var copy, end, middle, numbers, start;
numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9];
start = numbers.slice(0, 3);
middle = numbers.slice(3, 6);
middle = numbers.slice(3, -2);
end = numbers.slice(6);
end = numbers.slice(-2);
copy = numbers.slice(0);

View File

@@ -1,4 +1,4 @@
// Generated by CoffeeScript 1.6.3
var zip, _ref;
// Generated by CoffeeScript 1.9.2
var ref, zip;
zip = typeof lottery.drawWinner === "function" ? (_ref = lottery.drawWinner().address) != null ? _ref.zipcode : void 0 : void 0;
zip = typeof lottery.drawWinner === "function" ? (ref = lottery.drawWinner().address) != null ? ref.zipcode : void 0 : void 0;

View File

@@ -1,12 +1,12 @@
// Generated by CoffeeScript 1.6.3
// Generated by CoffeeScript 1.9.2
var awardMedals, contenders, gold, rest, silver,
__slice = [].slice;
slice = [].slice;
gold = silver = rest = "unknown";
awardMedals = function() {
var first, others, second;
first = arguments[0], second = arguments[1], others = 3 <= arguments.length ? __slice.call(arguments, 2) : [];
first = arguments[0], second = arguments[1], others = 3 <= arguments.length ? slice.call(arguments, 2) : [];
gold = first;
silver = second;
return rest = others;

View File

@@ -1,6 +1,6 @@
// Generated by CoffeeScript 1.6.3
var numbers, _ref;
// Generated by CoffeeScript 1.9.2
var numbers, ref;
numbers = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
[].splice.apply(numbers, [3, 4].concat(_ref = [-3, -4, -5, -6])), _ref;
[].splice.apply(numbers, [3, 4].concat(ref = [-3, -4, -5, -6])), ref;

View File

@@ -1,4 +1,4 @@
// Generated by CoffeeScript 1.6.3
// Generated by CoffeeScript 1.9.2
var mobyDick;
mobyDick = "Call me Ishmael. Some years ago -- never mind how long precisely -- having little or no money in my purse, and nothing particular to interest me on shore, I thought I would sail about a little and see the watery part of the world...";

View File

@@ -1,4 +1,4 @@
// Generated by CoffeeScript 1.6.3
// Generated by CoffeeScript 1.9.2
switch (day) {
case "Mon":
go(work);

View File

@@ -1,4 +1,4 @@
// Generated by CoffeeScript 1.6.3
// Generated by CoffeeScript 1.9.2
var grade, score;
score = 76;

View File

@@ -1,4 +1,4 @@
// Generated by CoffeeScript 1.6.3
// Generated by CoffeeScript 1.9.2
var error;
try {

View File

@@ -1,4 +1,4 @@
// Generated by CoffeeScript 1.6.3
// Generated by CoffeeScript 1.9.2
var lyrics, num;
if (this.studyingEconomics) {
@@ -13,10 +13,10 @@ if (this.studyingEconomics) {
num = 6;
lyrics = (function() {
var _results;
_results = [];
var results;
results = [];
while (num -= 1) {
_results.push("" + num + " little monkeys, jumping on the bed. One fell out and bumped his head.");
results.push(num + " little monkeys, jumping on the bed. One fell out and bumped his head.");
}
return _results;
return results;
})();

View File

@@ -31,7 +31,7 @@ File.open = (path, mode, block) ->
# Write.
write = (location, data) ->
path = new Pathname location
throw new Error "Location does not exist" unless fs.existsSync(location)
throw new Error "Location does not exist" unless fs.existsSync location
File.open path, 'w', (file) ->
return false if Digest.MD5.hexdigest(file.read()) is data.hash()

View File

@@ -13,7 +13,7 @@ run_loop = ->
wait()
# Objects:
dense_object_literal = {one: 1, two: 2, three: 3}
dense_object_literal = one: 1, two: 2, three: 3
spaced_out_multiline_object =
pi: 3.14159
@@ -56,7 +56,7 @@ race = ->
run()
walk()
crawl()
if tired then return sleep()
return sleep() if tired
race()
# Conditional assignment:
@@ -64,7 +64,7 @@ good or= evil
wine and= cheese
# Nested property access and calls.
((moon.turn(360))).shapes[3].move({x: 45, y: 30}).position['top'].offset('x')
(moon.turn 360).shapes[3].move(x: 45, y: 30).position['top'].offset('x')
a = b = c = 5
@@ -79,7 +79,7 @@ try
dogs_and_cats_living_together()
throw "up"
catch error
print(error)
print error
finally
clean_up()
@@ -130,8 +130,8 @@ wednesday = -> eat_breakfast(); go_to_work(); eat_dinner()
# Multiline strings with inner quotes.
story = "Lorem ipsum dolor \"sit\" amet, consectetuer adipiscing elit,
sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna
aliquam erat volutpat. Ut wisi enim ad."
sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna
aliquam erat volutpat. Ut wisi enim ad."
# Inheritance and calling super.
class Animal

View File

@@ -19,7 +19,7 @@ binary_search = (items, value) ->
# Test the function.
console.log 2 is binary_search [10, 20, 30, 40, 50], 30
console.log 4 is binary_search [-97, 35, 67, 88, 1200], 1200
console.log 0 is binary_search [0, 45, 70], 0
console.log(-1 is binary_search [0, 45, 70], 10)
console.log 2 is binary_search [10, 20, 30, 40, 50], 30
console.log 4 is binary_search [-97, 35, 67, 88, 1200], 1200
console.log 0 is binary_search [0, 45, 70], 0
console.log -1 is binary_search [0, 45, 70], 10

View File

@@ -1,8 +1,8 @@
# A bubble sort implementation, sorting the given array in-place.
bubble_sort = (list) ->
for i in [0...list.length]
for j in [0...list.length - i]
[list[j], list[j+1]] = [list[j+1], list[j]] if list[j] > list[j+1]
for j in [0...list.length - i] when list[j] > list[j + 1]
[list[j], list[j+1]] = [list[j + 1], list[j]]
list

View File

@@ -1,8 +1,8 @@
# "Classic" linked list implementation that doesn't keep track of its size.
class LinkedList
->
this._head = null # Pointer to the first item in the list.
constructor: ->
@_head = null # Pointer to the first item in the list.
# Appends some data to the end of the list. This method traverses the existing
@@ -12,10 +12,10 @@ class LinkedList
# Create a new node object to wrap the data.
node = data: data, next: null
current = this._head or= node
current = @_head or= node
if this._head isnt node
(current = current.next) while current.next
if @_head isnt node
current = current.next while current.next
current.next = node
this
@@ -27,11 +27,11 @@ class LinkedList
# Check for out-of-bounds values.
return null if index < 0
current = this._head or null
current = @_head or null
i = -1
# Advance through the list.
(current = current.next) while current and index > (i += 1)
current = current.next while current and index > ++i
# Return null if we've reached the end.
current and current.data
@@ -43,16 +43,16 @@ class LinkedList
# Check for out-of-bounds values.
return null if index < 0
current = this._head or null
current = @_head or null
i = -1
# Special case: removing the first item.
if index is 0
this._head = current.next
@_head = current.next
else
# Find the right location.
([previous, current] = [current, current.next]) while index > (i += 1)
[previous, current] = [current, current.next] while index > ++i
# Skip over the item to remove.
previous.next = current.next
@@ -63,7 +63,7 @@ class LinkedList
# Calculate the number of items in the list.
size: ->
current = this._head
current = @_head
count = 0
while current
@@ -76,7 +76,7 @@ class LinkedList
# Convert the list into an array.
toArray: ->
result = []
current = this._head
current = @_head
while current
result.push current.data
@@ -86,7 +86,7 @@ class LinkedList
# The string representation of the linked list.
toString: -> this.toArray().toString()
toString: -> @toArray().toString()
# Tests.

View File

@@ -7,13 +7,13 @@ is_valid_identifier = (identifier) ->
sum = 0
alt = false
for i in [identifier.length - 1..0] by -1
for c in identifier by -1
# Get the next digit.
num = parseInt identifier.charAt(i), 10
num = parseInt c, 10
# If it's not a valid number, abort.
return false if isNaN(num)
return false if isNaN num
# If it's an alternate number...
if alt

Some files were not shown because too many files have changed in this diff Show More