diff --git a/documentation/docs/browser.html b/documentation/docs/browser.html index 8b759611..8877634f 100644 --- a/documentation/docs/browser.html +++ b/documentation/docs/browser.html @@ -120,7 +120,8 @@ We add support for loading remote Coffee scripts via XHR, and -
CoffeeScript = require './coffee-script'
+            
+CoffeeScript = require './coffee-script'
 CoffeeScript.require = require
 compile = CoffeeScript.compile
@@ -168,7 +169,7 @@ compile = CoffeeScript.compile
-

If we're not in a browser environment, we're finished with the public API.

+

If we’re not in a browser environment, we’re finished with the public API.

@@ -183,8 +184,8 @@ compile = CoffeeScript.compile
-

Include source maps where possible. If we've got a base64 encoder, a -JSON serializer, and tools for escaping unicode characters, we're good to go. +

Include source maps where possible. If we’ve got a base64 encoder, a +JSON serializer, and tools for escaping unicode characters, we’re good to go. Ported from https://developer.mozilla.org/en-US/docs/DOM/window.btoa

diff --git a/documentation/docs/cake.html b/documentation/docs/cake.html index d129a301..e92563d9 100644 --- a/documentation/docs/cake.html +++ b/documentation/docs/cake.html @@ -118,8 +118,20 @@ 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.

Running cake with no arguments will print out a list of all the tasks in the -current directory's Cakefile.

-

External dependencies.

+current directory’s Cakefile.

+ + + + + + +
  • +
    + +
    + +
    +

    External dependencies.

    @@ -132,11 +144,26 @@ CoffeeScript = require +
  • - + +
    +

    Register .coffee extension

    + +
    + +
    CoffeeScript.register()
    + +
  • + + +
  • +
    + +
    +

    Keep track of the list of defined tasks, the accepted options, and so on.

    @@ -150,11 +177,11 @@ oparse = null
  • -
  • +
  • - +

    Mixin the top-level Cake functions for Cakefiles to use directly.

    @@ -165,11 +192,11 @@ oparse = null
  • -
  • +
  • - +

    Define a Cake task with a short name, an optional sentence description, and the function to run as the action itself.

    @@ -183,11 +210,11 @@ and the function to run as the action itself.

  • -
  • +
  • - +

    Define an option that the Cakefile accepts. The parsed options hash, containing all of the command-line options passed, will be made available @@ -201,11 +228,11 @@ as the first argument to the action.

  • -
  • +
  • - +

    Invoke another task in the current Cakefile.

    @@ -218,14 +245,14 @@ as the first argument to the action.

  • -
  • +
  • - +
    -

    Run cake. Executes all of the tasks you pass, in order. Note that Node's -asynchrony may cause tasks to execute in a different order than you'd expect. +

    Run cake. Executes all of the tasks you pass, in order. Note that Node’s +asynchrony may cause tasks to execute in a different order than you’d expect. If no tasks are passed, print the help screen. Keep a reference to the original directory name, when running Cake tasks from subdirectories.

    @@ -247,11 +274,11 @@ original directory name, when running Cake tasks from subdirectories.

  • -
  • +
  • - +

    Display the list of Cake tasks in a format similar to rake -T

    @@ -271,11 +298,11 @@ original directory name, when running Cake tasks from subdirectories.

  • -
  • +
  • - +

    Print an error and exit when attempting to use an invalid task/option.

    @@ -291,11 +318,11 @@ original directory name, when running Cake tasks from subdirectories.

  • -
  • +
  • - +

    When cake is invoked, search in the current and all parent directories to find the relevant Cakefile.

    diff --git a/documentation/docs/coffee-script.html b/documentation/docs/coffee-script.html index 3724e9c8..8de4c3e6 100644 --- a/documentation/docs/coffee-script.html +++ b/documentation/docs/coffee-script.html @@ -120,7 +120,8 @@ source CoffeeScript into JavaScript.

    -
    fs            = require 'fs'
    +            
    +fs            = require 'fs'
     vm            = require 'vm'
     path          = require 'path'
     {Lexer}       = require './lexer'
    @@ -466,7 +467,27 @@ The CoffeeScript REPL uses this to run the input.

    else vm.runInContext js, sandbox -exports.register = -> require './register' +exports.register = -> require './register'
    + +
  • + + +
  • +
    + +
    + +
    +

    Throw error with deprecation warning when depending upon implicit require.extensions registration

    + +
    + +
    if require.extensions
    +  for ext in @FILE_EXTENSIONS
    +    require.extensions[ext] ?= ->
    +      throw new Error """
    +      Use CoffeeScript.register() or require the coffee-script/register module to require #{ext} files.
    +      """
     
     exports._compileFile = (filename, sourceMap = no) ->
       raw = fs.readFileSync filename, 'utf8'
    @@ -479,11 +500,11 @@ The CoffeeScript REPL uses this to run the input.

  • -
  • +
  • - +

    As the filename and code of a dynamically loaded file will be different from the original file compiled with CoffeeScript.run, add that @@ -498,11 +519,11 @@ information to error so it can be pretty-printed later.

  • -
  • +
  • - +

    Instantiate a Lexer for our use here.

    @@ -513,15 +534,15 @@ information to error so it can be pretty-printed later.

  • -
  • +
  • - +

    The real Lexer produces a generic stream of tokens. This object provides a thin wrapper around it, compatible with the Jison API. We can then pass it -directly as a "Jison lexer".

    +directly as a “Jison lexer”.

    @@ -544,11 +565,11 @@ directly as a "Jison lexer".

  • -
  • +
  • - +

    Make all the AST nodes visible to the parser.

    @@ -559,13 +580,13 @@ directly as a "Jison lexer".

  • -
  • +
  • - +
    -

    Override Jison's default error handling function.

    +

    Override Jison’s default error handling function.

    @@ -574,13 +595,13 @@ directly as a "Jison lexer".

  • -
  • +
  • - +
    -

    Disregard Jison's message, it contains redundant line numer information. +

    Disregard Jison’s message, it contains redundant line numer information. Disregard the token, we take its value directly from the lexer in case the error is caused by a generated token which might refer to its origin.

    @@ -599,11 +620,11 @@ the error is caused by a generated token which might refer to its origin.

  • -
  • +
  • - +

    The second argument has a loc property, which should have the location data for this token. Unfortunately, Jison seems to send an outdated loc @@ -617,11 +638,11 @@ from the lexer.

  • -
  • +
  • - +

    Based on http://v8.googlecode.com/svn/branches/bleeding_edge/src/messages.js Modified to handle sourceMap

    @@ -649,11 +670,11 @@ Modified to handle sourceMap

  • -
  • +
  • - +

    Check for a sourceMap position

    @@ -694,11 +715,11 @@ Modified to handle sourceMap

  • -
  • +
  • - +

    Map of filenames -> sourceMap object.

    @@ -709,11 +730,11 @@ Modified to handle sourceMap

  • -
  • +
  • - +

    Generates the source map for a coffee file and stores it in the local cache variable.

    @@ -728,11 +749,11 @@ Modified to handle sourceMap

  • -
  • +
  • - +

    Based on michaelficarra/CoffeeScriptRedux NodeJS / V8 have no support for transforming positions in stack traces using @@ -751,7 +772,7 @@ positions.

    break if frame.getFunction() is exports.run " at #{formatSourcePosition frame, getSourceMapping}" - "#{err.name}: #{err.message ? ''}\n#{frames.join '\n'}\n"
    + "#{err.toString()}\n#{frames.join '\n'}\n"
  • diff --git a/documentation/docs/command.html b/documentation/docs/command.html index fd2016d7..c45e74a8 100644 --- a/documentation/docs/command.html +++ b/documentation/docs/command.html @@ -118,7 +118,19 @@ into various forms: saved into .js files or printed to stdout or recompiled every time the source is saved, printed as a token stream or as the syntax tree, or launch an interactive REPL.

    -

    External dependencies.

    + + + + + + +
  • +
    + +
    + +
    +

    External dependencies.

    @@ -136,11 +148,11 @@ useWinPathSep = path.sep is +
  • - +

    Allow CoffeeScript to emit Node.js events.

    @@ -156,11 +168,11 @@ useWinPathSep = path.sep is +
  • - +

    The help banner that is printed in conjunction with -h/--help.

    @@ -175,11 +187,11 @@ useWinPathSep = path.sep is +
  • - +

    The list of all the valid option flags that coffee knows how to handle.

    @@ -208,11 +220,11 @@ useWinPathSep = path.sep is +
  • - +

    Top-level objects shared by all the functions.

    @@ -228,11 +240,11 @@ optionParser = null
  • -
  • +
  • - +

    Run coffee by parsing passed options and determining what action to take. Many flags cause us to divert before compiling anything. Flags passed after @@ -246,15 +258,15 @@ Many flags cause us to divert before compiling anything. Flags passed after

  • -
  • +
  • - +
    -

    Make the REPL CLI use the global context so as to (a) be consistent with the +

    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.

    +(such as ‘colors’ and ‘sugar’) work as expected.

    @@ -271,7 +283,22 @@ Many flags cause us to divert before compiling anything. Flags passed after process.argv[0] = 'coffee' opts.output = path.resolve opts.output if opts.output - opts.join = path.resolve opts.join if opts.join + if opts.join + opts.join = path.resolve opts.join + console.error ''' + + The --join option is deprecated and will be removed in a future version. + + If for some reason it's necessary to share local variables between files, + replace... + + $ coffee --compile --join bundle.js -- a.coffee b.coffee c.coffee + + with... + + $ cat a.coffee b.coffee c.coffee | coffee --compile --stdio > bundle.js + + ''' for source in opts.arguments source = path.resolve source compilePath source, yes, source @@ -279,14 +306,14 @@ Many flags cause us to divert before compiling anything. Flags passed after
  • -
  • +
  • - +

    Compile a path, which could be a script or a directory. If a directory -is passed, recursively compile all '.coffee', '.litcoffee', and '.coffee.md' +is passed, recursively compile all ‘.coffee’, ‘.litcoffee’, and ‘.coffee.md’ extension source files in it and all subdirectories.

    @@ -342,15 +369,15 @@ extension source files in it and all subdirectories.

  • -
  • +
  • - +

    Compile a single source script, containing the given code, according to the requested options. If evaluating the script directly sets __filename, -__dirname and module.filename to be correct relative to the script's path.

    +__dirname and module.filename to be correct relative to the script’s path.

    @@ -396,11 +423,11 @@ requested options. If evaluating the script directly sets __filename -
  • +
  • - +

    Attach the appropriate listeners to compile scripts incoming over stdin, and write them back to stdout.

    @@ -418,11 +445,11 @@ and write them back to stdout.

  • -
  • +
  • - +

    If all of the source files are done being read, concatenate and compile them together.

    @@ -440,11 +467,11 @@ them together.

  • -
  • +
  • - +

    Watch a source CoffeeScript file using fs.watch, recompiling it every time the file is updated. May be used in combination with other options, @@ -500,11 +527,11 @@ such as --print.

  • -
  • +
  • - +

    Watch a directory of files for new additions.

    @@ -551,11 +578,11 @@ such as --print.

  • -
  • +
  • - +

    Remove a file from our source list, and source code cache. Optionally remove the compiled JS version as well.

    @@ -580,11 +607,11 @@ the compiled JS version as well.

  • -
  • +
  • - +

    Get the corresponding output JavaScript path for a source file.

    @@ -604,11 +631,11 @@ the compiled JS version as well.

  • -
  • +
  • - +

    Write out a JavaScript source file with the compiled code. By default, files are written out in cwd as .js files with the same name, but the output @@ -628,45 +655,31 @@ same directory as the .js file.

    fs.writeFile jsPath, js, (err) -> if err printLine err.message + process.exit 1 else if opts.compile and opts.watch timeLog "compiled #{sourcePath}" if generatedSourceMap fs.writeFile sourceMapPath, generatedSourceMap, (err) -> if err printLine "Could not write source map: #{err.message}" + process.exit 1 fs.exists jsDir, (itExists) -> if itExists then compile() else mkdirp jsDir, compile
  • -
  • -
    - -
    - -
    -

    Convenience for cleaner setTimeouts.

    - -
    - -
    wait = (milliseconds, func) -> setTimeout func, milliseconds
    - -
  • - -
  • -

    When watching scripts, it's useful to log changes with the timestamp.

    +

    Convenience for cleaner setTimeouts.

    -
    timeLog = (message) ->
    -  console.log "#{(new Date).toLocaleTimeString()} - #{message}"
    +
    wait = (milliseconds, func) -> setTimeout func, milliseconds
  • @@ -677,6 +690,22 @@ same directory as the .js file.

    +

    When watching scripts, it’s useful to log changes with the timestamp.

    + + + +
    timeLog = (message) ->
    +  console.log "#{(new Date).toLocaleTimeString()} - #{message}"
    + + + + +
  • +
    + +
    + +

    Pretty-print a stream of tokens, sans location data.

    @@ -691,11 +720,11 @@ same directory as the .js file.

  • -
  • +
  • - +

    Use the OptionParser module to extract all options from process.argv that are specified in SWITCHES.

    @@ -712,11 +741,11 @@ same directory as the .js file.

  • -
  • +
  • - +

    The compile-time options to pass to the CoffeeScript compiler.

    @@ -751,11 +780,11 @@ same directory as the .js file.

  • -
  • +
  • - +

    Start up a new Node.js instance with the arguments in --nodejs passed to the node binary, preserving the other options.

    @@ -775,11 +804,11 @@ the node binary, preserving the other options.

  • -
  • +
  • - +

    Print the --help usage message and exit. Deprecated switches are not shown.

    @@ -792,11 +821,11 @@ shown.

  • -
  • +
  • - +

    Print the --version message and exit.

    diff --git a/documentation/docs/docco.css b/documentation/docs/docco.css index f690a079..a2899ac8 100644 --- a/documentation/docs/docco.css +++ b/documentation/docs/docco.css @@ -51,9 +51,17 @@ b, strong { font-family: "aller-bold"; } -p, ul, ol { +p { margin: 15px 0 0px; } + .annotation ul, .annotation ol { + margin: 25px 0; + } + .annotation ul li, .annotation ol li { + font-size: 14px; + line-height: 18px; + margin: 10px 0; + } h1, h2, h3, h4, h5, h6 { color: #112233; @@ -70,7 +78,7 @@ h1 { hr { border: 0; - background: 1px solid #ddd; + background: 1px #ddd; height: 1px; margin: 20px 0; } @@ -205,7 +213,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; @@ -306,7 +313,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; @@ -376,125 +382,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 .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; } diff --git a/documentation/docs/grammar.html b/documentation/docs/grammar.html index 37b2a3e9..efe5a495 100644 --- a/documentation/docs/grammar.html +++ b/documentation/docs/grammar.html @@ -127,12 +127,9 @@ reduces into the
    {Parser} = require 'jison'
    -
  • @@ -142,10 +139,12 @@ from our rules and saves it into lib/parser.js.

    -

    Jison DSL

    +

    The only dependency is on the Jison.Parser.

    +
    {Parser} = require 'jison'
    + @@ -155,7 +154,32 @@ from our rules and saves it into lib/parser.js.

    -

    Since we're going to be wrapped in a function by Jison in any case, if our +

    Jison DSL

    + + + + + + +
  • +
    + +
    + +
    + +
    + +
  • + + +
  • +
    + +
    + +
    +

    Since we’re going to be wrapped in a function by Jison in any case, if our action immediately returns a value, we can optimize by removing the function wrapper and just returning the value directly.

    @@ -166,11 +190,11 @@ wrapper and just returning the value directly.

  • -
  • +
  • - +

    Our handy DSL for Jison grammar generation, thanks to Tim Caswell. For every rule in the grammar, @@ -189,13 +213,13 @@ previous nonterminal.

  • -
  • +
  • - +
    -

    All runtime functions we need are defined on "yy"

    +

    All runtime functions we need are defined on “yy”

    @@ -205,11 +229,11 @@ previous nonterminal.

  • -
  • +
  • - +

    Returns a function which adds location data to the first parameter passed in, and returns the parameter. If the parameter is not a node, it will @@ -231,11 +255,11 @@ just be passed through unaffected.

  • -
  • +
  • - +

    Grammatical Rules

    @@ -244,17 +268,29 @@ just be passed through unaffected.

  • -
  • +
  • - +
    -

    In all of the rules that follow, you'll see the name of the nonterminal as -the key to a list of alternative matches. With each match's action, the + +

    + +
  • + + +
  • +
    + +
    + +
    +

    In all of the rules that follow, you’ll see the name of the nonterminal as +the key to a list of alternative matches. With each match’s action, the dollar-sign variables are provided by Jison as references to the value of their numeric position, so in this rule:

    -
    "Expression UNLESS Expression"
    +
    "Expression UNLESS Expression"
     

    $1 would be the value of the first Expression, $2 would be the token for the UNLESS terminal, and $3 would be the value of the second Expression.

    @@ -266,11 +302,11 @@ for the UNLESS terminal, and $3 would be the value of
  • -
  • +
  • - +

    The Root is the top-level node in the syntax tree. Since we parse bottom-up, all parsing must end here.

    @@ -285,11 +321,11 @@ all parsing must end here.

  • -
  • +
  • - +

    Any list of statements and expressions, separated by line breaks or semicolons.

    @@ -304,11 +340,11 @@ all parsing must end here.

  • -
  • +
  • - +

    Block and statements, which make up a line in a body.

    @@ -322,11 +358,11 @@ all parsing must end here.

  • -
  • +
  • - +

    Pure statements which cannot be expressions.

    @@ -341,14 +377,14 @@ all parsing must end here.

  • -
  • +
  • - +

    All the different types of expressions in our language. The basic unit of -CoffeeScript is the Expression -- everything that can be an expression +CoffeeScript is the Expression — everything that can be an expression is one. Blocks serve as the building blocks of many other rules, making them somewhat circular.

    @@ -372,11 +408,11 @@ them somewhat circular.

  • -
  • +
  • - +

    An indented block of expressions. Note that the Rewriter will convert some postfix forms into blocks for us, by adjusting the @@ -392,11 +428,11 @@ token stream.

  • -
  • +
  • - +

    A literal identifier, a variable name or property.

    @@ -409,11 +445,11 @@ token stream.

  • -
  • +
  • - +

    Alphanumerics are separated from the other Literal matchers because they can also serve as keys in object literals.

    @@ -428,11 +464,11 @@ they can also serve as keys in object literals.

  • -
  • +
  • - +

    All of our immediate values. Generally these can be passed straight through and printed to JavaScript.

    @@ -452,11 +488,11 @@ through and printed to JavaScript.

  • -
  • +
  • - +

    Assignment of a variable, property, or index to a value.

    @@ -471,11 +507,11 @@ through and printed to JavaScript.

  • -
  • +
  • - +

    Assignment when it happens within an object literal. The difference from the ordinary Assign is that these allow numbers and strings as keys.

    @@ -499,11 +535,11 @@ the ordinary Assign is that these allow numbers and strings as
  • -
  • +
  • - +

    A return statement from a function body.

    @@ -517,11 +553,11 @@ the ordinary Assign is that these allow numbers and strings as
  • -
  • +
  • - +

    A block comment.

    @@ -534,13 +570,13 @@ the ordinary Assign is that these allow numbers and strings as
  • -
  • +
  • - +
    -

    The Code node is the function literal. It's defined by an indented block +

    The Code node is the function literal. It’s defined by an indented block of Block preceded by a function arrow, with an optional parameter list.

    @@ -554,11 +590,11 @@ list.

  • -
  • +
  • - +

    CoffeeScript has two different symbols for functions. -> is for ordinary functions, and => is for functions bound to the current value of this.

    @@ -573,11 +609,11 @@ functions, and => is for functions bound to the current value of
  • -
  • +
  • - +

    An optional, trailing comma.

    @@ -591,11 +627,11 @@ functions, and => is for functions bound to the current value of
  • -
  • +
  • - +

    The list of parameters that a function accepts can be of any length.

    @@ -612,11 +648,11 @@ functions, and => is for functions bound to the current value of
  • -
  • +
  • - +

    A single parameter in a function definition can be ordinary, or a splat that hoovers up the remaining arguments.

    @@ -633,11 +669,11 @@ that hoovers up the remaining arguments.

  • -
  • +
  • - +

    Function Parameters

    @@ -653,11 +689,11 @@ that hoovers up the remaining arguments.

  • -
  • +
  • - +

    A splat that occurs outside of a parameter list.

    @@ -670,11 +706,11 @@ that hoovers up the remaining arguments.

  • -
  • +
  • - +

    Variables and properties that can be assigned to.

    @@ -690,11 +726,11 @@ that hoovers up the remaining arguments.

  • -
  • +
  • - +

    Everything that can be assigned to.

    @@ -709,13 +745,13 @@ that hoovers up the remaining arguments.

  • -
  • +
  • - +
    -

    The types of things that can be treated as values -- assigned to, invoked +

    The types of things that can be treated as values — assigned to, invoked as functions, indexed into, named as a class, etc.

    @@ -731,11 +767,11 @@ as functions, indexed into, named as a class, etc.

  • -
  • +
  • - +

    The general group of accessors into an object, by property, by prototype or by array index or slice.

    @@ -754,11 +790,11 @@ or by array index or slice.

  • -
  • +
  • - +

    Indexing into an object or array using bracket notation.

    @@ -777,11 +813,11 @@ or by array index or slice.

  • -
  • +
  • - +

    In CoffeeScript, an object literal is simply a list of assignments.

    @@ -794,11 +830,11 @@ or by array index or slice.

  • -
  • +
  • - +

    Assignment of properties within an object literal can be separated by comma, as in JavaScript, or simply by newline.

    @@ -816,11 +852,11 @@ comma, as in JavaScript, or simply by newline.

  • -
  • +
  • - +

    Class definitions have optional bodies of prototype property assignments, and optional references to the superclass.

    @@ -841,11 +877,11 @@ and optional references to the superclass.

  • -
  • +
  • - +

    Ordinary function invocation, or a chained series of calls.

    @@ -861,11 +897,11 @@ and optional references to the superclass.

  • -
  • +
  • - +

    An optional existence check on a function.

    @@ -879,11 +915,11 @@ and optional references to the superclass.

  • -
  • +
  • - +

    The list of arguments to a function call.

    @@ -897,11 +933,11 @@ and optional references to the superclass.

  • -
  • +
  • - +

    A reference to the this current object.

    @@ -915,11 +951,11 @@ and optional references to the superclass.

  • -
  • +
  • - +

    A reference to a property on this.

    @@ -932,11 +968,11 @@ and optional references to the superclass.

  • -
  • +
  • - +

    The array literal.

    @@ -950,11 +986,11 @@ and optional references to the superclass.

  • -
  • +
  • - +

    Inclusive and exclusive range dots.

    @@ -968,11 +1004,11 @@ and optional references to the superclass.

  • -
  • +
  • - +

    The CoffeeScript range literal.

    @@ -985,11 +1021,11 @@ and optional references to the superclass.

  • -
  • +
  • - +

    Array slice literals.

    @@ -1005,11 +1041,11 @@ and optional references to the superclass.

  • -
  • +
  • - +

    The ArgList is both the list of objects passed into a function call, as well as the contents of an array literal @@ -1028,11 +1064,11 @@ as well as the contents of an array literal

  • -
  • +
  • - +

    Valid arguments are Blocks or Splats.

    @@ -1047,15 +1083,15 @@ as well as the contents of an array literal
  • -
  • +
  • - +

    Just simple, comma-separated, required arguments (no fancy syntax). We need this to be separate from the ArgList for use in Switch blocks, where -having the newlines wouldn't make sense.

    +having the newlines wouldn’t make sense.

    @@ -1067,11 +1103,11 @@ having the newlines wouldn't make sense.

  • -
  • +
  • - +

    The variants of try/catch/finally exception handling blocks.

    @@ -1087,11 +1123,11 @@ having the newlines wouldn't make sense.

  • -
  • +
  • - +

    A catch clause names its error and runs a block of code.

    @@ -1106,11 +1142,11 @@ having the newlines wouldn't make sense.

  • -
  • +
  • - +

    Throw an exception object.

    @@ -1123,11 +1159,11 @@ having the newlines wouldn't make sense.

  • -
  • +
  • - +

    Parenthetical expressions. Note that the Parenthetical is a Value, not an Expression, so if you need to use an expression in a place @@ -1144,11 +1180,11 @@ the trick.

  • -
  • +
  • - +

    The condition portion of a while loop.

    @@ -1164,11 +1200,11 @@ the trick.

  • -
  • +
  • - +

    The while loop can either be normal, with a block of expressions to execute, or postfix, with a single expression. There is no do..while.

    @@ -1190,11 +1226,11 @@ or postfix, with a single expression. There is no do..while.

  • -
  • +
  • - +

    Array, object, and range comprehensions, at the most generic level. Comprehensions can either be normal, with a block of expressions to execute, @@ -1221,11 +1257,11 @@ or postfix, with a single expression.

  • -
  • +
  • - +

    An array of all accepted values for a variable inside the loop. This enables support for pattern matching.

    @@ -1242,11 +1278,11 @@ This enables support for pattern matching.

  • -
  • +
  • - +

    An array or range comprehension has variables for the current element and (optional) reference to the current index. Or, key, value, in the case @@ -1262,14 +1298,14 @@ of object comprehensions.

  • -
  • +
  • - +

    The source of a comprehension is an array or object with an optional guard -clause. If it's an array comprehension, you can also choose to step through +clause. If it’s an array comprehension, you can also choose to step through in fixed-size increments.

    @@ -1299,11 +1335,11 @@ in fixed-size increments.

  • -
  • +
  • - +

    An individual When clause, with action.

    @@ -1317,11 +1353,11 @@ in fixed-size increments.

  • -
  • +
  • - +

    The most basic form of if is a condition and an action. The following if-related rules are broken up along these lines in order to avoid @@ -1337,11 +1373,11 @@ ambiguity.

  • -
  • +
  • - +

    The full complement of if expressions, including postfix one-liner if and unless.

    @@ -1358,11 +1394,11 @@ ambiguity.

  • -
  • +
  • - +

    Arithmetic and logical operators, working on one or more operands. Here they are grouped by order of precedence. The actual precedence rules @@ -1387,11 +1423,11 @@ rules are necessary.

  • -
  • +
  • - +

    The existential operator.

    @@ -1425,11 +1461,11 @@ rules are necessary.

  • -
  • +
  • - +

    Precedence

    @@ -1438,17 +1474,29 @@ rules are necessary.

  • -
  • +
  • - + +
    + +
    + +
  • + + +
  • +
    + +
    +

    Operators at the top of this list have higher precedence than the ones lower down. Following these rules is what makes 2 + 3 * 4 parse as:

    -
    2 + (3 * 4)
    +
    2 + (3 * 4)
     

    And not:

    -
    (2 + 3) * 4
    +
    (2 + 3) * 4
     
    @@ -1476,11 +1524,11 @@ down. Following these rules is what makes 2 + 3 * 4 parse as:

  • -
  • +
  • - +

    Wrapping Up

    @@ -1489,16 +1537,28 @@ down. Following these rules is what makes 2 + 3 * 4 parse as:

  • -
  • +
  • - + +
    + +
    + +
  • + + +
  • +
    + +
    +

    Finally, now that we have our grammar and our operators, we can create our Jison.Parser. We do this by processing all of our rules, recording all terminals (every symbol which does not appear as the name of a rule above) -as "tokens".

    +as “tokens”.

    @@ -1513,11 +1573,11 @@ as "tokens".

  • -
  • +
  • - +

    Initialize the Parser with our list of terminal tokens, our grammar rules, and the name of the root. Reverse the operators because Jison orders diff --git a/documentation/docs/helpers.html b/documentation/docs/helpers.html index bdfa4767..35807f29 100644 --- a/documentation/docs/helpers.html +++ b/documentation/docs/helpers.html @@ -113,16 +113,12 @@

    -

    This file contains the common helper functions that we'd like to share among +

    This file contains the common helper functions that we’d like to share among the Lexer, Rewriter, and the Nodes. Merge objects, flatten arrays, count characters, that sort of thing.

    -

    Peek at the beginning of a given string to see if it matches a sequence.

    -
    exports.starts = (string, literal, start) ->
    -  literal is string.substr start, literal.length
    -
  • @@ -132,6 +128,22 @@ arrays, count characters, that sort of thing.

    +

    Peek at the beginning of a given string to see if it matches a sequence.

    + + + +
    exports.starts = (string, literal, start) ->
    +  literal is string.substr start, literal.length
    + + + + +
  • +
    + +
    + +

    Peek at the end of a given string to see if it matches a sequence.

    @@ -143,11 +155,11 @@ arrays, count characters, that sort of thing.

  • -
  • +
  • - +

    Repeat a string n times.

    @@ -158,11 +170,11 @@ arrays, count characters, that sort of thing.

  • -
  • +
  • - +

    Use clever algorithm to have O(log(n)) string concatenation operations.

    @@ -178,11 +190,11 @@ arrays, count characters, that sort of thing.

  • -
  • +
  • - +

    Trim out all falsy values from an array.

    @@ -194,11 +206,11 @@ arrays, count characters, that sort of thing.

  • -
  • +
  • - +

    Count the number of occurrences of a string in a string.

    @@ -213,11 +225,11 @@ arrays, count characters, that sort of thing.

  • -
  • +
  • - +

    Merge objects, returning a fresh copy with attributes from both sides. Used every time Base#compile is called, to allow properties in the @@ -231,11 +243,11 @@ options hash to propagate down the tree without polluting other branches.

  • -
  • +
  • - +

    Extend a source object with the properties of another object (shallow copy).

    @@ -249,11 +261,11 @@ options hash to propagate down the tree without polluting other branches.

  • -
  • +
  • - +

    Return a flattened version of an array. Handy for getting a list of children from the nodes.

    @@ -272,11 +284,11 @@ Handy for getting a list of children from the nodes.

  • -
  • +
  • - +

    Delete a key from an object, returning the value. Useful when a node is looking for a particular method in an options hash.

    @@ -291,11 +303,11 @@ looking for a particular method in an options hash.

  • -
  • +
  • - +

    Gets the last item of an array(-like) object.

    @@ -306,11 +318,11 @@ looking for a particular method in an options hash.

  • -
  • +
  • - +

    Typical Array::some

    @@ -323,15 +335,15 @@ looking for a particular method in an options hash.

  • -
  • +
  • - +

    Simple function for inverting Literate CoffeeScript code by putting the documentation in comments, producing a string of CoffeeScript code that -can be compiled "normally".

    +can be compiled “normally”.

    @@ -349,11 +361,11 @@ can be compiled "normally".

  • -
  • +
  • - +

    Merge two jison-style location data objects together. If last is not provided, this will simply return first.

    @@ -372,14 +384,14 @@ If last is not provided, this will simply return first
  • -
  • +
  • - +

    This returns a function which takes an object as a parameter, and if that -object is an AST node, updates that object's locationData. +object is an AST node, updates that object’s locationData. The object is returned either way.

    @@ -394,11 +406,11 @@ The object is returned either way.

  • -
  • +
  • - +

    Convert jison location data to a string. obj can be a token, or a locationData.

    @@ -418,11 +430,11 @@ The object is returned either way.

  • -
  • +
  • - +

    A .coffee.md compatible version of basename, that returns the file sans-extension.

    @@ -441,11 +453,11 @@ The object is returned either way.

  • -
  • +
  • - +

    Determine if a filename represents a CoffeeScript file.

    @@ -456,11 +468,11 @@ The object is returned either way.

  • -
  • +
  • - +

    Determine if a filename represents a Literate CoffeeScript file.

    @@ -471,14 +483,14 @@ The object is returned either way.

  • -
  • +
  • - +

    Throws a SyntaxError from a given location. -The error's toString will return an error message following the "standard" +The error’s toString will return an error message following the “standard” format ::: plus the line with the error and a marker showing where the error is.

    @@ -492,13 +504,13 @@ marker showing where the error is.

  • -
  • +
  • - +
    -

    Instead of showing the compiler's stacktrace, show our custom error message +

    Instead of showing the compiler’s stacktrace, show our custom error message (this is useful when the error bubbles up in Node.js applications that compile CoffeeScript for example).

    @@ -511,13 +523,13 @@ compile CoffeeScript for example).

  • -
  • +
  • - +
    -

    Update a compiler SyntaxError with source code information if it didn't have +

    Update a compiler SyntaxError with source code information if it didn’t have it already.

    @@ -527,11 +539,11 @@ it already.

  • -
  • +
  • - +

    Avoid screwing up the stack property of other errors (i.e. possible bugs).

    @@ -557,29 +569,29 @@ it already.

  • -
  • -
    - -
    - -
    -

    Show only the first line on multi-line errors.

    - -
    - -
      end      = if first_line is last_line then last_column + 1 else codeLine.length
    -  marker   = repeat(' ', start) + repeat('^', end - start)
    - -
  • - -
  • -

    Check to see if we're running on a color-enabled TTY.

    +

    Show only the first line on multi-line errors.

    + +
    + +
      end      = if first_line is last_line then last_column + 1 else codeLine.length
    +  marker   = codeLine[...start].replace(/[^\s]/g, ' ') + repeat('^', end - start)
    + +
  • + + +
  • +
    + +
    + +
    +

    Check to see if we’re running on a color-enabled TTY.

    diff --git a/documentation/docs/lexer.html b/documentation/docs/lexer.html index 3a375b8d..46abbbaf 100644 --- a/documentation/docs/lexer.html +++ b/documentation/docs/lexer.html @@ -124,7 +124,8 @@ are read by jison in the parser.lexer function defined in coffee-sc -
    {Rewriter, INVERSES} = require './rewriter'
    +
    +{Rewriter, INVERSES} = require './rewriter'
  • @@ -164,6 +165,18 @@ locationDataToString, throwSyntaxError} = require + + + + + + +
  • +
    + +
    + +

    The Lexer class reads a stream of CoffeeScript and divvies it up into tagged tokens. Some potential ambiguity in the grammar has been avoided by pushing some extra smarts into the Lexer.

    @@ -175,13 +188,13 @@ pushing some extra smarts into the Lexer.

  • -
  • +
  • - +
    -

    tokenize is the Lexer's main method. Scan by attempting to match tokens +

    tokenize is the Lexer’s main method. Scan by attempting to match tokens one at a time, using a regular expression anchored at the start of the remaining code, or a custom recursive token-matching method (for interpolations). When the next token has been recorded, we move forward @@ -212,11 +225,11 @@ unless explicitly asked not to.

  • -
  • +
  • - +

    At every position, run through this list of attempted matches, short-circuiting if any of them succeed. Their order determines precedence: @@ -241,11 +254,11 @@ short-circuiting if any of them succeed. Their order determines precedence:

  • -
  • +
  • - +

    Update position

    @@ -263,15 +276,15 @@ short-circuiting if any of them succeed. Their order determines precedence:
  • -
  • +
  • - +

    Preprocess the code to remove leading and trailing whitespace, carriage -returns, etc. If we're lexing literate CoffeeScript, strip external Markdown -by removing all lines that aren't indented by at least four spaces or a tab.

    +returns, etc. If we’re lexing literate CoffeeScript, strip external Markdown +by removing all lines that aren’t indented by at least four spaces or a tab.

    @@ -287,11 +300,11 @@ by removing all lines that aren't indented by at least four spaces or a tab.
  • -
  • +
  • - +

    Tokenizers

    @@ -300,16 +313,28 @@ by removing all lines that aren't indented by at least four spaces or a tab.
  • -
  • +
  • - + +
    + +
    + +
  • + + +
  • +
    + +
    +

    Matches identifying literals: variables, keywords, method names, etc. -Check to ensure that JavaScript reserved words aren't being used as +Check to ensure that JavaScript reserved words aren’t being used as identifiers. Because CoffeeScript reserves a handful of keywords that are -allowed in JavaScript, we're careful not to tag them as keywords when +allowed in JavaScript, we’re careful not to tag them as keywords when referenced as property names here, so you can still do jQuery.is() even though is means === otherwise.

    @@ -322,11 +347,11 @@ though is means === otherwise.

  • -
  • +
  • - +

    Preserve length of id for location data

    @@ -394,11 +419,11 @@ though is means === otherwise.

  • -
  • +
  • - +

    Matches numbers, including decimals, hex, and exponential notation. Be careful not to interfere with ranges-in-progress.

    @@ -427,25 +452,29 @@ Be careful not to interfere with ranges-in-progress.

  • -
  • +
  • - +

    Matches strings, including multi-line strings. Ensures that quotation marks -are balanced within the string's contents, and within nested interpolations.

    +are balanced within the string’s contents, and within nested interpolations.

      stringToken: ->
         switch quote = @chunk.charAt 0
    -      when "'" then [string] = SIMPLESTR.exec @chunk
    +      when "'" then [string] = SIMPLESTR.exec(@chunk) || []
           when '"' then string = @balancedString @chunk, '"'
         return 0 unless string
    -    trimmed = @removeNewlines string[1...-1]
    +    inner = string[1...-1]
    +    trimmed = @removeNewlines inner
         if quote is '"' and 0 < string.indexOf '#{', 1
    -      @interpolateString trimmed, strOffset: 1, lexedLength: string.length
    +      numBreak = pos = 0
    +      innerLen = inner.length
    +      numBreak++ while inner.charAt(pos++) is '\n' and pos < innerLen
    +      @interpolateString trimmed, strOffset: 1 + numBreak, lexedLength: string.length
         else
           @token 'STRING', quote + @escapeLines(trimmed) + quote, 0, string.length
         if octalEsc = /^(?:\\.|[^\\])*\\(?:0[0-7]|[1-7])/.test string
    @@ -455,11 +484,11 @@ are balanced within the string's contents, and within nested interpolations.
             
  • -
  • +
  • - +

    Matches heredocs, adjusting indentation to the correct level, as heredocs preserve whitespace, but ignore indentation to the left.

    @@ -472,7 +501,8 @@ preserve whitespace, but ignore indentation to the left.

    quote = heredoc.charAt 0 doc = @sanitizeHeredoc match[2], quote: quote, indent: null if quote is '"' and 0 <= doc.indexOf '#{' - @interpolateString doc, heredoc: yes, strOffset: 3, lexedLength: heredoc.length + strOffset = if match[2].charAt(0) is '\n' then 4 else 3 + @interpolateString doc, heredoc: yes, strOffset: strOffset, lexedLength: heredoc.length else @token 'STRING', @makeString(doc, quote, yes), 0, heredoc.length heredoc.length
    @@ -480,11 +510,11 @@ preserve whitespace, but ignore indentation to the left.

  • -
  • +
  • - +

    Matches and consumes comments.

    @@ -503,11 +533,11 @@ preserve whitespace, but ignore indentation to the left.

  • -
  • +
  • - +

    Matches JavaScript interpolated directly into the source via backticks.

    @@ -521,11 +551,11 @@ preserve whitespace, but ignore indentation to the left.

  • -
  • +
  • - +

    Matches regular expression literals. Lexing regular expressions is difficult to distinguish from division, so we borrow some basic heuristics from @@ -545,11 +575,11 @@ JavaScript and Ruby.

  • -
  • +
  • - +

    Avoid conflicts with floor division operator.

    @@ -563,11 +593,11 @@ JavaScript and Ruby.

  • -
  • +
  • - +

    Matches multiline extended regular expressions.

    @@ -584,7 +614,7 @@ JavaScript and Ruby.

    @token 'IDENTIFIER', 'RegExp', 0, 0 @token 'CALL_START', '(', 0, 0 tokens = [] - for token in @interpolateString(body, regex: yes) + for token in @interpolateString(body, regex: yes, strOffset: 3) [tag, value] = token if tag is 'TOKENS' tokens.push value... @@ -595,11 +625,11 @@ JavaScript and Ruby.

  • -
  • +
  • - +

    Convert NEOSTRING into STRING

    @@ -620,13 +650,13 @@ JavaScript and Ruby.

  • -
  • +
  • - +
    -

    Remove the extra "+"

    +

    Remove the extra “+”

    @@ -642,11 +672,11 @@ JavaScript and Ruby.

  • -
  • +
  • - +

    Find the flags in the heregex

    @@ -662,11 +692,11 @@ JavaScript and Ruby.

  • -
  • +
  • - +

    Matches newlines, indents, and outdents, and determines which is which. If we can detect that the current line is continued onto the the next line, @@ -713,11 +743,11 @@ can close multiple indents, so we need to know how far in we happen to be.

  • -
  • +
  • - +

    Record an outdent token or multiple tokens, if we happen to be moving back inwards past several recorded indents. Sets new @indent value.

    @@ -746,11 +776,11 @@ inwards past several recorded indents. Sets new @indent value.

  • -
  • +
  • - +

    pair might call outdentToken, so preserve decreasedIndent

    @@ -769,14 +799,14 @@ inwards past several recorded indents. Sets new @indent value.

  • -
  • +
  • - +

    Matches and consumes non-meaningful whitespace. Tag the previous token -as being "spaced", because there are some cases where it makes a difference.

    +as being “spaced”, because there are some cases where it makes a difference.

    @@ -790,11 +820,11 @@ as being "spaced", because there are some cases where it makes a diffe
  • -
  • +
  • - +

    Generate a newline token. Consecutive newlines get merged together.

    @@ -808,11 +838,11 @@ as being "spaced", because there are some cases where it makes a diffe
  • -
  • +
  • - +

    Use a \ at a line-ending to suppress the newline. The slash is removed here once its job is done.

    @@ -826,11 +856,11 @@ The slash is removed here once its job is done.

  • -
  • +
  • - +

    We treat all other single characters as a token. E.g.: ( ) , . ! Multi-character operators are also literal tokens, so that Jison can assign @@ -882,11 +912,11 @@ parentheses that indicate a method call from regular parentheses, and so on.

  • -
  • +
  • - +

    Token Manipulators

    @@ -895,11 +925,23 @@ parentheses that indicate a method call from regular parentheses, and so on.

  • -
  • +
  • - + +
    + +
    + +
  • + + +
  • +
    + +
    +

    Sanitize a heredoc or herecomment by erasing all external indentation on the left-hand side.

    @@ -923,11 +965,11 @@ erasing all external indentation on the left-hand side.

  • -
  • +
  • - +

    A source of ambiguity in our grammar used to be parameter lists in function definitions versus argument lists in function calls. Walk backwards, tagging @@ -956,11 +998,11 @@ parameters specially in order to make things easier for the parser.

  • -
  • +
  • - +

    Close up all remaining open blocks at the end of the file.

    @@ -972,11 +1014,11 @@ parameters specially in order to make things easier for the parser.

  • -
  • +
  • - +

    Matches a balanced group such as a single or double-quoted string. Pass in a series of delimiters, all of which must be nested correctly within the @@ -1016,23 +1058,23 @@ interpolations within strings, ad infinitum.

  • -
  • +
  • - +

    Expand variables and expressions inside double-quoted strings using Ruby-like notation for substitution of arbitrary expressions.

    -
    "Hello #{name.capitalize()}."
    +
    "Hello #{name.capitalize()}."
     

    If it encounters an interpolation, this method will recursively create a new Lexer, tokenize the interpolated contents, and merge them into the token stream.

      -
    • str is the start of the string contents (IE with the " or """ stripped +
    • str is the start of the string contents (IE with the “ or “”” stripped off.)
    • options.offsetInChunk is the start of the interpolated string in the -current chunk, including the " or """, etc... If not provided, this is +current chunk, including the “ or “””, etc… If not provided, this is assumed to be 0. options.lexedLength is the length of the interpolated string, including both the start and end quotes. Both of these values are ignored if options.regex is true.
    • @@ -1051,11 +1093,11 @@ current chunk. -
    • +
    • - +

      Parse the string.

      @@ -1075,11 +1117,11 @@ current chunk.
    • -
    • +
    • - +

      NEOSTRING is a fake token. This will be converted to a string below.

      @@ -1090,7 +1132,7 @@ current chunk.
    • errorToken = @makeToken '', 'string interpolation', offsetInChunk + i + 1, 2 inner = expr[1...-1] if inner.length - [line, column] = @getLineAndColumnFromChunk(strOffset + i + 1) + [line, column] = @getLineAndColumnFromChunk(strOffset + i + 2) nested = new Lexer().tokenize inner, line: line, column: column, rewrite: off popped = nested.pop() popped = nested.shift() if nested[0]?[0] is 'TERMINATOR' @@ -1102,13 +1144,13 @@ current chunk. -
    • +
    • - +
      -

      Push a fake 'TOKENS' token, which will get turned into real tokens below.

      +

      Push a fake ‘TOKENS’ token, which will get turned into real tokens below.

      @@ -1120,11 +1162,11 @@ current chunk.
    • -
    • +
    • - +

      If regex, then return now and let the regex code deal with all these fake tokens

      @@ -1135,13 +1177,13 @@ current chunk.
    • -
    • +
    • - +
      -

      If we didn't find any tokens, then just return an empty string.

      +

      If we didn’t find any tokens, then just return an empty string.

      @@ -1150,11 +1192,11 @@ current chunk.
    • -
    • +
    • - +

      If the first token is not a string, add a fake empty string to the beginning.

      @@ -1168,11 +1210,11 @@ current chunk.
    • -
    • +
    • - +

      Push all the tokens

      @@ -1185,13 +1227,13 @@ current chunk.
    • -
    • +
    • - +
      -

      Create a 0-length "+" token.

      +

      Create a 0-length “+” token.

      @@ -1207,13 +1249,13 @@ current chunk.
    • -
    • +
    • - +
      -

      Push all the tokens in the fake 'TOKENS' token. These already have +

      Push all the tokens in the fake ‘TOKENS’ token. These already have sane location data.

      @@ -1224,11 +1266,11 @@ sane location data.

    • -
    • +
    • - +

      Convert NEOSTRING into STRING

      @@ -1248,11 +1290,11 @@ sane location data.

    • -
    • +
    • - +

      Pairs up a closing token, ensuring that all listed pairs of tokens are correctly balanced throughout the course of the token stream.

      @@ -1266,15 +1308,15 @@ correctly balanced throughout the course of the token stream.

    • -
    • +
    • - +

      Auto-close INDENT to support syntax like this:

      -
      el.click((event) ->
      -  el.hide())
      +
      el.click((event) ->
      +  el.hide())
       
      @@ -1285,11 +1327,11 @@ correctly balanced throughout the course of the token stream.

    • -
    • +
    • - +

      Helpers

      @@ -1298,11 +1340,23 @@ correctly balanced throughout the course of the token stream.

    • -
    • +
    • - + +
      + +
      + +
    • + + +
    • +
      + +
      +

      Returns the line and column number from an offset into the current chunk.

      offset is a number of characters into @chunk.

      @@ -1332,13 +1386,13 @@ correctly balanced throughout the course of the token stream.

    • -
    • +
    • - +
      -

      Same as "token", exception this just returns the token without adding it +

      Same as “token”, exception this just returns the token without adding it to the results.

      @@ -1351,14 +1405,14 @@ to the results.

    • -
    • +
    • - +
      -

      Use length - 1 for the final offset - we're supplying the last_line and the last_column, -so if last_column == first_column, then we're looking at a character of length 1.

      +

      Use length - 1 for the final offset - we’re supplying the last_line and the last_column, +so if last_column == first_column, then we’re looking at a character of length 1.

      @@ -1373,11 +1427,11 @@ so if last_column == first_column, then we're looking at a character of leng
    • -
    • +
    • - +

      Add a token to the results. offset is the offset into the current @chunk where the token starts. @@ -1396,11 +1450,11 @@ not specified, the length of value will be used.

    • -
    • +
    • - +

      Peek at a tag in the current token stream.

      @@ -1412,11 +1466,11 @@ not specified, the length of value will be used.

    • -
    • +
    • - +

      Peek at a value in the current token stream.

      @@ -1428,11 +1482,11 @@ not specified, the length of value will be used.

    • -
    • +
    • - +

      Are we in the midst of an unfinished expression?

      @@ -1446,11 +1500,11 @@ not specified, the length of value will be used.

    • -
    • +
    • - +

      Remove newlines from beginning and (non escaped) from end of string literals.

      @@ -1463,11 +1517,11 @@ not specified, the length of value will be used.

    • -
    • +
    • - +

      Converts newlines for string literals.

      @@ -1478,11 +1532,11 @@ not specified, the length of value will be used.

    • -
    • +
    • - +

      Ignore escaped backslashes and remove escaped newlines

      @@ -1498,11 +1552,11 @@ not specified, the length of value will be used.

    • -
    • +
    • - +

      Constructs a string token by escaping quotes and newlines.

      @@ -1514,11 +1568,11 @@ not specified, the length of value will be used.

    • -
    • +
    • - +

      Ignore escaped backslashes and unescape quotes

      @@ -1532,11 +1586,11 @@ not specified, the length of value will be used.

    • -
    • +
    • - +

      Throws a compiler error on the current position.

      @@ -1547,11 +1601,11 @@ not specified, the length of value will be used.

    • -
    • +
    • - +

      TODO: Are there some cases we could improve the error line number by passing the offset in the chunk where the error happened?

      @@ -1564,11 +1618,11 @@ passing the offset in the chunk where the error happened?

    • -
    • +
    • - +

      Constants

      @@ -1577,11 +1631,23 @@ passing the offset in the chunk where the error happened?

    • -
    • +
    • - + +
      + +
      + +
    • + + +
    • +
      + +
      +

      Keywords that CoffeeScript shares in common with JavaScript.

      @@ -1598,11 +1664,11 @@ passing the offset in the chunk where the error happened?

    • -
    • +
    • - +

      CoffeeScript-only keywords.

      @@ -1627,11 +1693,11 @@ COFFEE_KEYWORDS = COFFEE_KEYWORDS.concat COFFEE_ALIASES
  • -
  • +
  • - +

    The list of keywords that are reserved by JavaScript, but not used, or are used by CoffeeScript internally. We throw an error when these are encountered, @@ -1651,11 +1717,11 @@ STRICT_PROSCRIBED = ['arguments', +

  • - +

    The superset of both JavaScript keywords and reserved words, none of which may be used as identifiers or properties.

    @@ -1670,11 +1736,11 @@ be used as identifiers or properties.

  • -
  • +
  • - +

    The character code of the nasty Microsoft madness otherwise known as the BOM.

    @@ -1685,11 +1751,11 @@ be used as identifiers or properties.

  • -
  • +
  • - +

    Token matching regexes.

    @@ -1734,11 +1800,11 @@ JSTOKEN = /^`[^\\`]*(?:\\.[^\\`]*)*`/<
  • -
  • +
  • - +

    Regex-matching-regexes.

    @@ -1769,11 +1835,11 @@ HEREGEX_OMIT = ///
  • -
  • +
  • - +

    Token cleaning regexes.

    @@ -1792,11 +1858,11 @@ TRAILING_SPACES = /\s+$/
  • -
  • +
  • - +

    Compound assignment tokens.

    @@ -1810,11 +1876,11 @@ TRAILING_SPACES = /\s+$/
  • -
  • +
  • - +

    Unary tokens.

    @@ -1827,11 +1893,11 @@ UNARY_MATH = ['!', '~
  • -
  • +
  • - +

    Logical tokens.

    @@ -1842,11 +1908,11 @@ UNARY_MATH = ['!', '~
  • -
  • +
  • - +

    Bit-shifting tokens.

    @@ -1857,11 +1923,11 @@ UNARY_MATH = ['!', '~
  • -
  • +
  • - +

    Comparison tokens.

    @@ -1872,11 +1938,11 @@ UNARY_MATH = ['!', '~
  • -
  • +
  • - +

    Mathematical tokens.

    @@ -1887,11 +1953,11 @@ UNARY_MATH = ['!', '~
  • -
  • +
  • - +

    Relational tokens that are negatable with not prefix.

    @@ -1902,11 +1968,11 @@ UNARY_MATH = ['!', '~
  • -
  • +
  • - +

    Boolean tokens.

    @@ -1917,11 +1983,11 @@ UNARY_MATH = ['!', '~
  • -
  • +
  • - +

    Tokens which a regular expression will never immediately follow, but which a division operator might.

    @@ -1935,11 +2001,11 @@ a division operator might.

  • -
  • +
  • - +

    If the previous token is not spaced, there are more preceding tokens that force a division parse:

    @@ -1951,11 +2017,11 @@ force a division parse:

  • -
  • +
  • - +

    Tokens which could legitimately be invoked or indexed. An opening parentheses or bracket following these tokens will be recorded as the start @@ -1969,11 +2035,11 @@ INDEXABLE = CALLABLE.concat 'NUMBER', -

  • +
  • - +

    Tokens that, when immediately preceding a WHEN, indicate that the WHEN occurs at the start of a line. We disambiguate these from trailing whens to @@ -1986,11 +2052,11 @@ avoid an ambiguity in the grammar.

  • -
  • +
  • - +

    Additional indent in front of these is ignored.

    diff --git a/documentation/docs/nodes.html b/documentation/docs/nodes.html index 029f34cd..bb7b8690 100644 --- a/documentation/docs/nodes.html +++ b/documentation/docs/nodes.html @@ -120,7 +120,8 @@ the syntax tree into a string of JavaScript code, call compile() on
    -
    Error.stackTraceLimit = Infinity
    +            
    +Error.stackTraceLimit = Infinity
     
     {Scope} = require './scope'
     {RESERVED, STRICT_PROSCRIBED} = require './lexer'
    @@ -166,7 +167,7 @@ addLocationDataFn, locationDataToString, throwSyntaxError} =
    -

    Constant functions for nodes that don't need customization.

    +

    Constant functions for nodes that don’t need customization.

    @@ -185,10 +186,22 @@ addLocationDataFn, locationDataToString, throwSyntaxError} =

    CodeFragment

    -

    The various nodes defined below all compile to a collection of CodeFragment objects. + + + +

  • + + +
  • +
    + +
    + +
    +

    The various nodes defined below all compile to a collection of CodeFragment objects. A CodeFragments is a block of generated code, and the location in the source file where the code came from. CodeFragments can be assembled together into working code just by catting together -all the CodeFragments' code snippets, in order.

    +all the CodeFragments’ code snippets, in order.

    @@ -204,11 +217,11 @@ all the CodeFragments' code snippets, in order.

  • -
  • +
  • - +

    Convert an array of CodeFragments into a string.

    @@ -220,14 +233,26 @@ all the CodeFragments' code snippets, in order.

  • -
  • +
  • - +

    Base

    -

    The Base is the abstract base class for all nodes in the syntax tree. + +

    + +
  • + + +
  • +
    + +
    + +
    +

    The Base is the abstract base class for all nodes in the syntax tree. Each subclass implements the compileNode method, which performs the code generation for that node. To compile a node to JavaScript, call compile on it, which wraps compileNode in some generic extra smarts, @@ -247,16 +272,16 @@ scope, and indentation level.

  • -
  • +
  • - +

    Common logic for determining whether to wrap this node in a closure before compiling it, or to compile directly. We need to wrap if this node is a -statement, and it's not a pureStatement, and we're not at -the top level of a block (which would be unnecessary), and we haven't +statement, and it’s not a pureStatement, and we’re not at +the top level of a block (which would be unnecessary), and we haven’t already been asked to return the result (because statements know how to return results).

    @@ -275,11 +300,11 @@ return results).

  • -
  • +
  • - +

    Statements converted into expressions via closure-wrapping share a scope object with their parent closure, to preserve the expected lexical scope.

    @@ -305,11 +330,11 @@ object with their parent closure, to preserve the expected lexical scope.

  • -
  • +
  • - +

    If the code generation wishes to use the result of a complex expression in multiple places, ensure that the expression is only ever evaluated once, @@ -335,15 +360,15 @@ the two values are raw nodes which have not been compiled.

  • -
  • +
  • - +
    -

    Construct a node that returns the current node's result. +

    Construct a node that returns the current node’s result. Note that this is overridden for smarter behavior for -many statement nodes (e.g. If, For)...

    +many statement nodes (e.g. If, For)…

    @@ -357,11 +382,11 @@ many statement nodes (e.g. If, For)...

  • -
  • +
  • - +

    Does this node, or any of its children, contain a node of a certain kind? Recursively traverses down the children nodes and returns the first one @@ -381,11 +406,11 @@ scope boundaries.

  • -
  • +
  • - +

    Pull out the last non-comment node of a node list.

    @@ -399,11 +424,11 @@ scope boundaries.

  • -
  • +
  • - +

    toString representation of the node, for inspecting the parse tree. This is what coffee --nodes prints out.

    @@ -419,11 +444,11 @@ This is what coffee --nodes prints out.

  • -
  • +
  • - +

    Passes each child to a function, breaking when the function returns false.

    @@ -452,11 +477,11 @@ This is what coffee --nodes prints out.

  • -
  • +
  • - +

    Default implementations of the common node properties and methods. Nodes will override these with custom logic, if needed.

    @@ -477,11 +502,11 @@ will override these with custom logic, if needed.

  • -
  • +
  • - +

    Is this node used to assign a certain variable?

    @@ -492,11 +517,11 @@ will override these with custom logic, if needed.

  • -
  • +
  • - +

    For this node and all descendents, set the location data to locationData if the location data is not already set.

    @@ -513,13 +538,13 @@ if the location data is not already set.

  • -
  • +
  • - +
    -

    Throw a SyntaxError associated with this node's location.

    +

    Throw a SyntaxError associated with this node’s location.

    @@ -535,11 +560,11 @@ if the location data is not already set.

  • -
  • +
  • - +

    fragmentsList is an array of arrays of fragments. Each array in fragmentsList will be concatonated together, with joinStr added in between each, to produce a final flat array @@ -557,16 +582,28 @@ of fragments.

  • -
  • +
  • - +

    Block

    -

    The block is the list of expressions that forms the body of an -indented block of code -- the implementation of a function, a clause in an -if, switch, or try, and so on...

    + +
    + +
  • + + +
  • +
    + +
    + +
    +

    The block is the list of expressions that forms the body of an +indented block of code — the implementation of a function, a clause in an +if, switch, or try, and so on…

    @@ -579,11 +616,11 @@ indented block of code -- the implementation of a function, a clause in an
  • -
  • +
  • - +

    Tack an expression on to the end of this expression list.

    @@ -596,11 +633,11 @@ indented block of code -- the implementation of a function, a clause in an
  • -
  • +
  • - +

    Remove and return the last expression of this expression list.

    @@ -612,11 +649,11 @@ indented block of code -- the implementation of a function, a clause in an
  • -
  • +
  • - +

    Add an expression at the beginning of this expression list.

    @@ -629,11 +666,11 @@ indented block of code -- the implementation of a function, a clause in an
  • -
  • +
  • - +

    If this Block consists of just a single node, unwrap it by pulling it back out.

    @@ -646,11 +683,11 @@ it back out.

  • -
  • +
  • - +

    Is this an empty block of code?

    @@ -671,11 +708,11 @@ it back out.

  • -
  • +
  • - +

    A Block node does not return its entire body, rather it ensures that the final expression is returned.

    @@ -695,11 +732,11 @@ ensures that the final expression is returned.

  • -
  • +
  • - +

    A Block is the only node that can serve as the root.

    @@ -711,14 +748,14 @@ ensures that the final expression is returned.

  • -
  • +
  • - +

    Compile all expressions within the Block body. If we need to -return the result, and it's an expression, simply return it. If it's a +return the result, and it’s an expression, simply return it. If it’s a statement, ask the statement to do so.

    @@ -737,13 +774,13 @@ statement, ask the statement to do so.

  • -
  • +
  • - +
    -

    This is a nested block. We don't do anything special here like enclose +

    This is a nested block. We don’t do anything special here like enclose it in a new scope; we just compile the statements in this block along with our own

    @@ -773,11 +810,11 @@ our own

  • -
  • +
  • - +

    If we happen to be the top-level Block, wrap everything in a safety closure, unless requested not to. @@ -795,13 +832,13 @@ clean up obvious double-parentheses.

  • -
  • +
  • - +
    -

    Mark given local variables in the root scope as parameters so they don't +

    Mark given local variables in the root scope as parameters so they don’t end up being declared on this block.

    @@ -825,11 +862,11 @@ end up being declared on this block.

  • -
  • +
  • - +

    Compile the expressions body for the contents of a function, with declarations of all inner variables pushed up to the top.

    @@ -869,11 +906,11 @@ declarations of all inner variables pushed up to the top.

  • -
  • +
  • - +

    Wrap up the given nodes as a Block, unless it already happens to be one.

    @@ -887,16 +924,28 @@ to be one.

  • -
  • +
  • - +

    Literal

    -

    Literals are static values that can be passed through directly into + +

    + +
  • + + +
  • +
    + +
    + +
    +

    Literals are static values that can be passed through directly into JavaScript without translation, such as: strings, numbers, -true, false, null...

    +true, false, null

    @@ -954,21 +1003,32 @@ JavaScript without translation, such as: strings, numbers,
  • -
  • +
  • - +

    Return

    -

    A return is a pureStatement -- wrapping it in a closure wouldn't + +

    + +
  • + + +
  • +
    + +
    + +
    +

    A return is a pureStatement — wrapping it in a closure wouldn’t make sense.

    exports.Return = class Return extends Base
    -  constructor: (expr) ->
    -    @expression = expr if expr and not expr.unwrap().isUndefined
    +  constructor: (@expression) ->
     
       children: ['expression']
     
    @@ -986,13 +1046,13 @@ make sense.

  • -
  • +
  • - +
    -

    TODO: If we call expression.compile() here twice, we'll sometimes get back different results!

    +

    TODO: If we call expression.compile() here twice, we’ll sometimes get back different results!

    @@ -1005,14 +1065,26 @@ make sense.

  • -
  • +
  • - +

    Value

    -

    A value, variable or literal or parenthesized, indexed or dotted into, + +

    + +
  • + + +
  • +
    + +
    + +
    +

    A value, variable or literal or parenthesized, indexed or dotted into, or vanilla.

    @@ -1030,11 +1102,11 @@ or vanilla.

  • -
  • +
  • - +

    Add a property (or properties ) Access to the list.

    @@ -1053,11 +1125,11 @@ or vanilla.

  • -
  • +
  • - +

    Some boolean checks for the benefit of other nodes.

    @@ -1096,11 +1168,11 @@ or vanilla.

  • -
  • +
  • - +

    The value can be unwrapped as its inner node, if there are no attached properties.

    @@ -1113,11 +1185,11 @@ properties.

  • -
  • +
  • - +

    A reference has base part (this value) and name part. We cache them separately for compiling complex expressions. @@ -1143,11 +1215,11 @@ We cache them separately for compiling complex expressions.

  • -
  • +
  • - +

    We compile a value to JavaScript by compiling and joining each property. Things get much more interesting if the chain of properties has soak @@ -1169,11 +1241,11 @@ evaluate anything twice when building the soak chain.

  • -
  • +
  • - +

    Unfold a soak into an If: a?.b -> a.b if a?

    @@ -1198,14 +1270,26 @@ evaluate anything twice when building the soak chain.

  • -
  • +
  • - +

    Comment

    -

    CoffeeScript passes through block comments as JavaScript block comments + +

    + +
  • + + +
  • +
    + +
    + +
    +

    CoffeeScript passes through block comments as JavaScript block comments at the same position.

    @@ -1225,15 +1309,27 @@ at the same position.

  • -
  • +
  • - +

    Call

    -

    Node for a function invocation. Takes care of converting super() calls into -calls against the prototype's function of the same name.

    + +
    + +
  • + + +
  • +
    + +
    + +
    +

    Node for a function invocation. Takes care of converting super() calls into +calls against the prototype’s function of the same name.

    @@ -1250,11 +1346,11 @@ calls against the prototype's function of the same name.

  • -
  • +
  • - +

    Tag this invocation as creating a new instance.

    @@ -1271,13 +1367,13 @@ calls against the prototype's function of the same name.

  • -
  • +
  • - +
    -

    Grab the reference to the superclass's implementation of the current +

    Grab the reference to the superclass’s implementation of the current method.

    @@ -1297,11 +1393,11 @@ method.

  • -
  • +
  • - +

    The appropriate this value for a super call.

    @@ -1314,11 +1410,11 @@ method.

  • -
  • +
  • - +

    Soaked chained invocations unfold into if/else ternary structures.

    @@ -1358,11 +1454,11 @@ method.

  • -
  • +
  • - +

    Compile a vanilla function call.

    @@ -1394,17 +1490,17 @@ method.

  • -
  • +
  • - +
    -

    If you call a function with a splat, it's converted into a JavaScript +

    If you call a function with a splat, it’s converted into a JavaScript .apply() call to allow an array of arguments to be passed. -If it's a constructor, then things get real tricky. We have to inject an +If it’s a constructor, then things get real tricky. We have to inject an inner constructor in order to be able to pass the varargs.

    -

    splatArgs is an array of CodeFragments to put into the 'apply'.

    +

    splatArgs is an array of CodeFragments to put into the ‘apply’.

    @@ -1446,14 +1542,26 @@ inner constructor in order to be able to pass the varargs.

  • -
  • +
  • - +

    Extends

    -

    Node to extend an object's prototype with an ancestor object. + +

    + +
  • + + +
  • +
    + +
    + +
    +

    Node to extend an object’s prototype with an ancestor object. After goog.inherits from the Closure Library.

    @@ -1467,13 +1575,13 @@ After goog.inherits from the
  • -
  • +
  • - +
    -

    Hooks one constructor into another's prototype chain.

    +

    Hooks one constructor into another’s prototype chain.

    @@ -1483,15 +1591,27 @@ After goog.inherits from the
  • -
  • +
  • - +

    Access

    -

    A . access into a property of a value, or the :: shorthand for -an access into the object's prototype.

    + +
    + +
  • + + +
  • +
    + +
    + +
    +

    A . access into a property of a value, or the :: shorthand for +an access into the object’s prototype.

    @@ -1516,14 +1636,26 @@ an access into the object's prototype.

  • -
  • +
  • - +

    Index

    -

    A [ ... ] indexed access into an array or object.

    + +
    + +
  • + + +
  • +
    + +
    + +
    +

    A [ ... ] indexed access into an array or object.

    @@ -1541,14 +1673,26 @@ an access into the object's prototype.

  • -
  • +
  • - +

    Range

    -

    A range literal. Ranges can be used to extract portions (slices) of arrays, + +

    + +
  • + + +
  • +
    + +
    + +
    +

    A range literal. Ranges can be used to extract portions (slices) of arrays, to specify a range for comprehensions, or as a value, to be expanded into the corresponding array of integers at runtime.

    @@ -1565,13 +1709,13 @@ corresponding array of integers at runtime.

  • -
  • +
  • - +
    -

    Compiles the range's source variables -- where it starts and where it ends. +

    Compiles the range’s source variables — where it starts and where it ends. But only if they need to be cached to avoid double evaluation.

    @@ -1587,11 +1731,11 @@ But only if they need to be cached to avoid double evaluation.

  • -
  • +
  • - +

    When compiled normally, the range returns the contents of the for loop needed to iterate over the values in the range. Used by comprehensions.

    @@ -1605,11 +1749,11 @@ needed to iterate over the values in the range. Used by comprehensions.

  • -
  • +
  • - +

    Set up endpoints.

    @@ -1627,11 +1771,11 @@ needed to iterate over the values in the range. Used by comprehensions.

  • -
  • +
  • - +

    Generate the condition.

    @@ -1649,11 +1793,11 @@ needed to iterate over the values in the range. Used by comprehensions.

  • -
  • +
  • - +

    Generate the step.

    @@ -1678,11 +1822,11 @@ needed to iterate over the values in the range. Used by comprehensions.

  • -
  • +
  • - +

    The final loop body.

    @@ -1693,11 +1837,11 @@ needed to iterate over the values in the range. Used by comprehensions.

  • -
  • +
  • - +

    When used as a value, expand the range into the equivalent array.

    @@ -1727,14 +1871,26 @@ needed to iterate over the values in the range. Used by comprehensions.

  • -
  • +
  • - +

    Slice

    -

    An array slice literal. Unlike JavaScript's Array#slice, the second parameter + +

    + +
  • + + +
  • +
    + +
    + +
    +

    An array slice literal. Unlike JavaScript’s Array#slice, the second parameter specifies the index of the end of the slice, just as the first parameter is the index of the beginning.

    @@ -1750,11 +1906,11 @@ is the index of the beginning.

  • -
  • +
  • - +

    We have to be careful when trying to slice through the end of the array, 9e9 is used because not all implementations respect undefined or 1/0. @@ -1769,13 +1925,13 @@ is the index of the beginning.

  • -
  • +
  • - +
    -

    TODO: jwalton - move this into the 'if'?

    +

    TODO: jwalton - move this into the ‘if’?

    @@ -1795,14 +1951,26 @@ is the index of the beginning.

  • -
  • +
  • - +

    Obj

    -

    An object literal, nothing fancy.

    + +
    + +
  • + + +
  • +
    + +
    + +
    +

    An object literal, nothing fancy.

    @@ -1851,14 +2019,26 @@ is the index of the beginning.

  • -
  • +
  • - +

    Arr

    -

    An array literal.

    + +
    + +
  • + + +
  • +
    + +
    + +
    +

    An array literal.

    @@ -1895,14 +2075,26 @@ is the index of the beginning.

  • -
  • +
  • - +

    Class

    -

    The CoffeeScript class definition. + +

    + +
  • + + +
  • +
    + +
    + +
    +

    The CoffeeScript class definition. Initialize a Class with its name, an optional superclass, and a list of prototype property assignments.

    @@ -1918,11 +2110,11 @@ list of prototype property assignments.

  • -
  • +
  • - +

    Figure out the appropriate name for the constructor function of this class.

    @@ -1941,11 +2133,11 @@ list of prototype property assignments.

  • -
  • +
  • - +

    For all this-references and bound functions in the class definition, this is the Class being constructed.

    @@ -1964,11 +2156,11 @@ list of prototype property assignments.

  • -
  • +
  • - +

    Ensure that all functions bound to the instance are proxied in the constructor.

    @@ -1984,11 +2176,11 @@ constructor.

  • -
  • +
  • - +

    Merge the properties from a top-level object as prototypal properties on the class.

    @@ -2026,11 +2218,11 @@ on the class.

  • -
  • +
  • - +

    Walk the body of the class, looking for prototype properties to be converted and tagging static assignments.

    @@ -2054,11 +2246,11 @@ and tagging static assignments.

  • -
  • +
  • - +

    use strict (and other directives) must be the first expression statement(s) of a function body. This method ensures the prologue is correctly positioned @@ -2076,11 +2268,11 @@ above the constructor.

  • -
  • +
  • - +

    Make sure that a constructor is defined for the class, and properly configured.

    @@ -2103,11 +2295,11 @@ configured.

  • -
  • +
  • - +

    Instead of generating the JavaScript string directly, we build up the equivalent syntax tree and compile that, in pieces. You can see the @@ -2151,15 +2343,27 @@ constructor, property assignments, and inheritance getting built out below.

  • -
  • +
  • - +

    Assign

    -

    The Assign is used to assign a local variable to value, or to set the -property of an object -- including within object literals.

    + +
    + +
  • + + +
  • +
    + +
    + +
    +

    The Assign is used to assign a local variable to value, or to set the +property of an object — including within object literals.

    @@ -2185,15 +2389,15 @@ property of an object -- including within object literals.

  • -
  • +
  • - +

    Compile an assignment, delegating to compilePatternMatch or compileSplice if appropriate. Keep track of the name of the base object -we've been assigned to, for correct internal references. If the variable +we’ve been assigned to, for correct internal references. If the variable has not been seen yet within the current scope, declare it.

    @@ -2226,11 +2430,11 @@ has not been seen yet within the current scope, declare it.

  • -
  • +
  • - +

    Brief implementation of recursive pattern matching, when assigning array or object literals to a value. Peeks at their properties to assign inner names. @@ -2252,11 +2456,11 @@ for details.

  • -
  • +
  • - +

    Unroll simplest cases: {v} = x -> v = x.v

    @@ -2283,13 +2487,13 @@ for details.

  • -
  • +
  • - +
    -

    Make vvar into a simple variable if it isn't already.

    +

    Make vvar into a simple variable if it isn’t already.

    @@ -2302,11 +2506,11 @@ for details.

  • -
  • +
  • - +

    A regular array pattern-match.

    @@ -2319,11 +2523,11 @@ for details.

  • -
  • +
  • - +

    A regular object pattern-match.

    @@ -2335,11 +2539,11 @@ for details.

  • -
  • +
  • - +

    A shorthand {a, b, @c} = val pattern-match.

    @@ -2390,11 +2594,11 @@ for details.

  • -
  • +
  • - +

    When compiling a conditional assignment, take care to ensure that the operands are only evaluated once, even though we have to reference them @@ -2408,11 +2612,11 @@ more than once.

  • -
  • +
  • - +

    Disallow conditional assignment of undefined variables.

    @@ -2431,11 +2635,11 @@ more than once.

  • -
  • +
  • - +

    Convert special math assignment operators like a **= b to the equivalent extended form a = a ** b and then compiles that.

    @@ -2449,13 +2653,13 @@ extended form a = a ** b and then compiles that.

  • -
  • +
  • - +
    -

    Compile the assignment from an array splice literal, using JavaScript's +

    Compile the assignment from an array splice literal, using JavaScript’s Array#splice method.

    @@ -2484,16 +2688,28 @@ extended form a = a ** b and then compiles that.

  • -
  • +
  • - +

    Code

    -

    A function definition. This is the only node that creates a new Scope. + +

    + +
  • + + +
  • +
    + +
    + +
    +

    A function definition. This is the only node that creates a new Scope. When for the purposes of walking the contents of a function body, the Code -has no children -- they're within the inner scope.

    +has no children — they’re within the inner scope.

    @@ -2514,11 +2730,11 @@ has no children -- they're within the inner scope.

  • -
  • +
  • - +

    Compilation creates a new scope unless explicitly asked to share with the outer scope. Handles splat parameters in the parameter list by peeking at @@ -2536,11 +2752,11 @@ a closure.

  • -
  • +
  • - +

    Handle bound functions early.

    @@ -2612,11 +2828,11 @@ a closure.

  • -
  • +
  • - +

    Short-circuit traverseChildren method to prevent it from crossing scope boundaries unless crossScope is true.

    @@ -2629,14 +2845,26 @@ unless crossScope is true.

  • -
  • +
  • - +

    Param

    -

    A parameter in a function definition. Beyond a typical Javascript parameter, + +

    + +
  • + + +
  • +
    + +
    + +
    +

    A parameter in a function definition. Beyond a typical Javascript parameter, these parameters can also attach themselves to the context of the function, as well as be a splat, gathering up a group of parameters into an array.

    @@ -2672,11 +2900,11 @@ as well as be a splat, gathering up a group of parameters into an array.

  • -
  • +
  • - +

    Iterates the name or names of a Param. In a sense, a destructured parameter represents multiple JS parameters. This @@ -2695,11 +2923,11 @@ to that name.

  • -
  • +
  • - +
    • simple literals foo
    • @@ -2712,11 +2940,11 @@ to that name.

      -
    • +
    • - +
      • at-params @foo
      • @@ -2730,11 +2958,11 @@ to that name.

        -
      • +
      • - +
        • assignments within destructured parameters {foo:bar}
        • @@ -2748,11 +2976,11 @@ to that name.

          -
        • +
        • - +
          • splats within destructured parameters [xs...]
          • @@ -2768,11 +2996,11 @@ to that name.

            -
          • +
          • - +
            • destructured parameters within destructured parameters [{a}]
            • @@ -2786,11 +3014,11 @@ to that name.

              -
            • +
            • - +
              • at-params within destructured parameters {@foo}
              • @@ -2804,11 +3032,11 @@ to that name.

                -
              • +
              • - +
                • simple destructured parameters {foo}
                • @@ -2824,14 +3052,26 @@ to that name.

                  -
                • +
                • - +

                  Splat

                  -

                  A splat, either as a parameter to a function, an argument to a call, + +

                  + +
                • + + +
                • +
                  + +
                  + +
                  +

                  A splat, either as a parameter to a function, an argument to a call, or as part of a destructuring assignment.

                  @@ -2856,11 +3096,11 @@ or as part of a destructuring assignment.

                • -
                • +
                • - +

                  Utility function that converts an arbitrary number of elements, mixed with splats, to a proper array.

                  @@ -2894,14 +3134,26 @@ splats, to a proper array.

                • -
                • +
                • - +

                  Expansion

                  -

                  Used to skip values inside an array destructuring (pattern matching) or + +

                  + +
                • + + +
                • +
                  + +
                  + +
                  +

                  Used to skip values inside an array destructuring (pattern matching) or parameter list.

                  @@ -2921,14 +3173,26 @@ parameter list.

                • -
                • +
                • - +

                  While

                  -

                  A while loop, the only sort of low-level loop exposed by CoffeeScript. From + +

                  + +
                • + + +
                • +
                  + +
                  + +
                  +

                  A while loop, the only sort of low-level loop exposed by CoffeeScript. From it, all other loops can be manufactured. Useful in cases where you need more flexibility or more speed than a comprehension can provide.

                  @@ -2963,14 +3227,14 @@ flexibility or more speed than a comprehension can provide.

                • -
                • +
                • - +

                  The main difference from a JavaScript while is that the CoffeeScript -while can be used as a part of a larger expression -- while loops may +while can be used as a part of a larger expression — while loops may return an array containing the computed result of each iteration.

                  @@ -3000,14 +3264,26 @@ return an array containing the computed result of each iteration.

                • -
                • +
                • - +

                  Op

                  -

                  Simple Arithmetic and logical operations. Performs some conversion from + +

                  + +
                • + + +
                • +
                  + +
                  + +
                  +

                  Simple Arithmetic and logical operations. Performs some conversion from CoffeeScript operations into their JavaScript equivalents.

                  @@ -3029,11 +3305,11 @@ CoffeeScript operations into their JavaScript equivalents.

                • -
                • +
                • - +

                  The map of conversions from CoffeeScript to JavaScript symbols.

                  @@ -3047,11 +3323,11 @@ CoffeeScript operations into their JavaScript equivalents.

                • -
                • +
                • - +

                  The map of invertible operators.

                  @@ -3074,11 +3350,11 @@ CoffeeScript operations into their JavaScript equivalents.

                • -
                • +
                • - +

                  Am I capable of Python-style comparison chaining?

                  @@ -3140,13 +3416,13 @@ CoffeeScript operations into their JavaScript equivalents.

                • -
                • +
                • - +
                  -

                  In chains, there's no need to wrap bare obj literals in parens, +

                  In chains, there’s no need to wrap bare obj literals in parens, as the chained expression is wrapped.

                  @@ -3172,16 +3448,16 @@ as the chained expression is wrapped.

                • -
                • +
                • - +
                  -

                  Mimic Python's chained comparisons when multiple comparison operators are +

                  Mimic Python’s chained comparisons when multiple comparison operators are used sequentially. For example:

                  -
                  bin/coffee -e 'console.log 50 < 65 > 10'
                  -true
                  +
                  bin/coffee -e 'console.log 50 < 65 > 10'
                  +true
                   
                  @@ -3195,11 +3471,11 @@ true
                • -
                • +
                • - +

                  Keep reference to the left expression, unless this an existential assignment

                  @@ -3217,11 +3493,11 @@ true
                • -
                • +
                • - +

                  Compile a unary Op.

                  @@ -3250,11 +3526,11 @@ true
                • -
                • +
                • - +

                  Make a Math.pow call

                  @@ -3278,11 +3554,11 @@ true
                • -
                • +
                • - +

                  In

                  @@ -3304,11 +3580,11 @@ true
                • -
                • +
                • - +

                  compileOrTest only if we have an array literal with no splats

                  @@ -3340,14 +3616,26 @@ true
                • -
                • +
                • - +

                  Try

                  -

                  A classic try/catch/finally block.

                  + +
                  + +
                • + + +
                • +
                  + +
                  + +
                  +

                  A classic try/catch/finally block.

                  @@ -3368,13 +3656,13 @@ true
                • -
                • +
                • - +
                  -

                  Compilation is more or less as you would expect -- the finally clause +

                  Compilation is more or less as you would expect — the finally clause is optional, the catch is not.

                  @@ -3403,14 +3691,26 @@ is optional, the catch is not.

                • -
                • +
                • - +

                  Throw

                  -

                  Simple node to throw an exception.

                  + +
                  + +
                • + + +
                • +
                  + +
                  + +
                  +

                  Simple node to throw an exception.

                  @@ -3425,13 +3725,13 @@ is optional, the catch is not.

                • -
                • +
                • - +
                  -

                  A Throw is already a return, of sorts...

                  +

                  A Throw is already a return, of sorts…

                  @@ -3443,14 +3743,26 @@ is optional, the catch is not.

                • -
                • +
                • - +

                  Existence

                  -

                  Checks a variable for existence -- not null and not undefined. This is + +

                  + +
                • + + +
                • +
                  + +
                  + +
                  +

                  Checks a variable for existence — not null and not undefined. This is similar to .nil? in Ruby, and avoids having to consult a JavaScript truth table.

                  @@ -3474,11 +3786,11 @@ table.

                • -
                • +
                • - +

                  do not use strict equality here; it will break existing code

                  @@ -3490,16 +3802,28 @@ table.

                • -
                • +
                • - +

                  Parens

                  -

                  An extra set of parentheses, specified explicitly in the source. At one time + +

                  + +
                • + + +
                • +
                  + +
                  + +
                  +

                  An extra set of parentheses, specified explicitly in the source. At one time we tried to clean up the results by detecting and removing redundant -parentheses, but no longer -- you can put in as many as you please.

                  +parentheses, but no longer — you can put in as many as you please.

                  Parentheses are a good way to force any statement to become an expression.

                  @@ -3525,14 +3849,26 @@ parentheses, but no longer -- you can put in as many as you please.

                • -
                • +
                • - +

                  For

                  -

                  CoffeeScript's replacement for the for loop is our array and object + +

                  + +
                • + + +
                • +
                  + +
                  + +
                  +

                  CoffeeScript’s replacement for the for loop is our array and object comprehensions, that compile into for loops here. They also act as an expression, able to return the result of each filtered iteration.

                  Unlike Python array comprehensions, they can be multi-line, and you can pass @@ -3561,11 +3897,11 @@ you can map and filter in a single pass.

                • -
                • +
                • - +

                  Welcome to the hairiest method in all of CoffeeScript. Handles the inner loop, filtering, stepping, and result saving for array, object, and range @@ -3670,14 +4006,26 @@ some cannot.

                • -
                • +
                • - +

                  Switch

                  -

                  A JavaScript switch statement. Converts into a returnable expression on-demand.

                  + +
                  + +
                • + + +
                • +
                  + +
                  + +
                  +

                  A JavaScript switch statement. Converts into a returnable expression on-demand.

                  @@ -3722,17 +4070,29 @@ some cannot.

                • -
                • +
                • - +

                  If

                  -

                  If/else statements. Acts as an expression by pushing down requested returns + +

                  + +
                • + + +
                • +
                  + +
                  + +
                  +

                  If/else statements. Acts as an expression by pushing down requested returns to the last line of each clause.

                  Single-expression Ifs are compiled into conditional operators if possible, -because ternaries are already proper expressions, and don't need conversion.

                  +because ternaries are already proper expressions, and don’t need conversion.

                  @@ -3751,11 +4111,11 @@ because ternaries are already proper expressions, and don't need conversion.
                • -
                • +
                • - +

                  Rewrite a chain of Ifs to add a default case as the final else.

                  @@ -3773,11 +4133,11 @@ because ternaries are already proper expressions, and don't need conversion.
                • -
                • +
                • - +

                  The If only compiles into a statement if either of its bodies needs to be a statement. Otherwise a conditional operator is safe.

                  @@ -3805,11 +4165,11 @@ to be a statement. Otherwise a conditional operator is safe.

                • -
                • +
                • - +

                  Compile the If as a regular if-else statement. Flattened chains force inner else bodies into statement form.

                  @@ -3840,11 +4200,11 @@ force inner else bodies into statement form.

                • -
                • +
                • - +

                  Compile the If as a conditional operator.

                  @@ -3863,11 +4223,11 @@ force inner else bodies into statement form.

                • -
                • +
                • - +

                  Constants

                  @@ -3876,25 +4236,26 @@ force inner else bodies into statement form.

                • -
                • +
                • - +
                  -
                  UTILITIES =
                  +
                  +UTILITIES =
                • -
                • +
                • - +

                  Correctly set up a prototype chain for inheritance, including a reference to the superclass for super() calls, and copies of any static properties.

                  @@ -3919,13 +4280,13 @@ to the superclass for super() calls, and copies of any static prope
                • -
                • +
                • - +
                  -

                  Create a function bound to the current value of "this".

                  +

                  Create a function bound to the current value of “this”.

                  @@ -3940,11 +4301,11 @@ to the superclass for super() calls, and copies of any static prope
                • -
                • +
                • - +

                  Discover if an item is in an array.

                  @@ -3960,17 +4321,17 @@ to the superclass for super() calls, and copies of any static prope " modulo: -> """ - function(a, b) { return (a % b + +b) % b; } + function(a, b) { return (+a % (b = +b) + b) % b; } """
              • -
              • +
              • - +

                Shortcuts to speed up the lookup time for native functions.

                @@ -3982,13 +4343,13 @@ to the superclass for super() calls, and copies of any static prope
              • -
              • +
              • - +
                -

                Levels indicate a node's position in the AST. Useful for knowing if +

                Levels indicate a node’s position in the AST. Useful for knowing if parens are necessary or superfluous.

                @@ -4003,11 +4364,11 @@ LEVEL_ACCESS = 6 #
              • -
              • +
              • - +

                Tabs are two spaces for pretty printing.

                @@ -4036,11 +4397,11 @@ $ ///
            • -
            • +
            • - +

              Is a literal value a string/regex?

              @@ -4052,11 +4413,11 @@ IS_REGEX = /^\//
          • -
          • +
          • - +

            Helper Functions

            @@ -4065,11 +4426,23 @@ IS_REGEX = /^\//
        • -
        • +
        • - + +
          + +
          + +
        • + + +
        • +
          + +
          +

          Helper for ensuring that utility functions are assigned at the top level.

          @@ -4087,11 +4460,11 @@ IS_REGEX = /^\//
      • -
      • +
      • - +

        Parse a number (+- decimal/hexadecimal) Examples: 0, -1, 1, 2e3, 2e-3, -0xfe, 0xfe

        @@ -4117,13 +4490,13 @@ Examples: 0, -1, 1, 2e3, 2e-3, -0xfe, 0xfe

      • -
      • +
      • - +
        -

        Unfold a node's child if soak, then tuck the node under created If

        +

        Unfold a node’s child if soak, then tuck the node under created If

        diff --git a/documentation/docs/optparse.html b/documentation/docs/optparse.html index d8ce31b8..420c9ace 100644 --- a/documentation/docs/optparse.html +++ b/documentation/docs/optparse.html @@ -129,7 +129,7 @@

      A simple OptionParser class to parse option flags from the command-line. Use it like so:

      -
      parser  = new OptionParser switches, helpBanner
      +
      parser  = new OptionParser switches, helpBanner
       options = parser.parse process.argv
       

      The first non-option is considered to be the start of the file (and file option) list, and all subsequent arguments are left unparsed.

      @@ -170,7 +170,7 @@ specified options, and return it. Options after the first non-option argument are treated as arguments. options.arguments 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're responsible for interpreting the options object.

      +you’re responsible for interpreting the options object.

    @@ -266,6 +266,18 @@ of the valid options, for --help and such.

    + + + +
  • + + +
  • +
    + +
    + +

    Regex matchers for option flags.

    @@ -278,11 +290,11 @@ OPTIONAL = /\[(\w+(\*?))\]/
  • -
  • +
  • - +

    Build and return the list of option rules. If the optional short-flag is unspecified, leave it out by padding with null.

    @@ -297,11 +309,11 @@ unspecified, leave it out by padding with null.

  • -
  • +
  • - +

    Build a rule from a -o short flag, a --output [DIR] long flag, and the description of what the option does.

    @@ -323,11 +335,11 @@ description of what the option does.

  • -
  • +
  • - +

    Normalize arguments by expanding merged flags into multiple flags. This allows you to have -wl be the same as --watch --lint.

    diff --git a/documentation/docs/register.html b/documentation/docs/register.html index 117c11f5..863062e2 100644 --- a/documentation/docs/register.html +++ b/documentation/docs/register.html @@ -165,10 +165,8 @@ CoffeeScript as an extension.

    -

    Patch Node's module loader to be able to handle mult-dot extensions. -This is a horrible thing that should not be required. Perhaps, one day, -when a truly benevolent dictator comes to rule over the Republik of Node, -it won't be.

    +

    Patch Node’s module loader to be able to handle multi-dot extensions. +This is a horrible thing that should not be required.

    @@ -226,7 +224,7 @@ it won't be.

    -

    If we're on Node, patch child_process.fork so that Coffee scripts are able +

    If we’re on Node, patch child_process.fork so that Coffee scripts are able to fork both CoffeeScript files, and JavaScript files, directly.

    diff --git a/documentation/docs/repl.html b/documentation/docs/repl.html index 38506bbf..16795ef0 100644 --- a/documentation/docs/repl.html +++ b/documentation/docs/repl.html @@ -153,7 +153,7 @@ replDefaults =
    -

    Node's REPL sends the input ending with a newline and then wrapped in +

    Node’s REPL sends the input ending with a newline and then wrapped in parens. Unwrap all that.

    @@ -210,7 +210,7 @@ parens. Unwrap all that.

    ] js = ast.compile bare: yes, locals: Object.keys(context) result = if context is global - vm.runInThisContext js, filename + vm.runInThisContext js, filename else vm.runInContext js, context, filename cb null, result @@ -225,7 +225,7 @@ parens. Unwrap all that.

    -

    AST's compile does not add source code information to syntax errors.

    +

    AST’s compile does not add source code information to syntax errors.

    @@ -233,13 +233,7 @@ parens. Unwrap all that.

    cb err addMultilineHandler = (repl) -> - {rli, inputStream, outputStream} = repl - - multiline = - enabled: off - initialPrompt: repl.prompt.replace /^[^> ]*/, (x) -> x.replace /./g, '-' - prompt: repl.prompt.replace /^[^> ]*>?/, (x) -> x.replace /./g, '.' - buffer: '' + {rli, inputStream, outputStream} = repl
  • @@ -250,7 +244,28 @@ parens. Unwrap all that.

    -

    Proxy node's line listener

    +

    Node 0.11.12 changed API, prompt is now _prompt.

    + + + +
      origPrompt = repl._prompt ? repl.prompt
    +
    +  multiline =
    +    enabled: off
    +    initialPrompt: origPrompt.replace /^[^> ]*/, (x) -> x.replace /./g, '-'
    +    prompt: origPrompt.replace /^[^> ]*>?/, (x) -> x.replace /./g, '.'
    +    buffer: ''
    + + + + +
  • +
    + +
    + +
    +

    Proxy node’s line listener

    @@ -262,17 +277,18 @@ parens. Unwrap all that.

    rli.setPrompt multiline.prompt rli.prompt true else + rli.setPrompt origPrompt nodeLineListener cmd return
  • -
  • +
  • - +

    Handle Ctrl-v

    @@ -285,11 +301,11 @@ parens. Unwrap all that.

  • -
  • +
  • - +

    allow arbitrarily switching between modes any time before multiple lines are entered

    @@ -297,18 +313,18 @@ parens. Unwrap all that.

          unless multiline.buffer.match /\n/
             multiline.enabled = not multiline.enabled
    -        rli.setPrompt repl.prompt
    +        rli.setPrompt origPrompt
             rli.prompt true
             return
  • -
  • +
  • - +

    no-op unless the current line is empty

    @@ -319,11 +335,11 @@ parens. Unwrap all that.

  • -
  • +
  • - +

    eval, print, loop

    @@ -338,11 +354,11 @@ parens. Unwrap all that.

  • -
  • +
  • - +

    XXX: multiline hack

    @@ -360,11 +376,11 @@ parens. Unwrap all that.

  • -
  • +
  • - +

    Store and load command history from a file

    @@ -377,11 +393,11 @@ parens. Unwrap all that.

  • -
  • +
  • - +

    Get file info and at most maxSize of command history

    @@ -393,11 +409,11 @@ parens. Unwrap all that.

  • -
  • +
  • - +

    Read last size bytes from the file

    @@ -410,11 +426,11 @@ parens. Unwrap all that.

  • -
  • +
  • - +

    Set the history on the interpreter

    @@ -425,11 +441,11 @@ parens. Unwrap all that.

  • -
  • +
  • - +

    If the history file was truncated we should pop off a potential partial line

    @@ -440,11 +456,11 @@ parens. Unwrap all that.

  • -
  • +
  • - +

    Shift off the final blank newline

    @@ -462,11 +478,11 @@ parens. Unwrap all that.

  • -
  • +
  • - +

    Save the latest command in the file

    @@ -480,22 +496,40 @@ parens. Unwrap all that.

  • -
  • +
  • - +

    Add a command to show the history stack

    -
      repl.commands['.history'] =
    +            
      repl.commands[getCommandId(repl, 'history')] =
         help: 'Show command history'
         action: ->
           repl.outputStream.write "#{repl.rli.history[..].reverse().join '\n'}\n"
           repl.displayPrompt()
     
    +getCommandId = (repl, commandName) ->
    + +
  • + + +
  • +
    + +
    + +
    +

    Node 0.11 changed API, a command such as ‘.help’ is now stored as ‘help’

    + +
    + +
      commandsHaveLeadingDot = repl.commands['.help']?
    +  if commandsHaveLeadingDot then ".#{commandName}" else commandName
    +
     module.exports =
       start: (opts = {}) ->
         [major, minor, build] = process.versions.node.split('.').map (n) -> parseInt(n)
    @@ -510,7 +544,22 @@ parens. Unwrap all that.

    repl = nodeREPL.start opts repl.on 'exit', -> repl.outputStream.write '\n' addMultilineHandler repl - addHistory repl, opts.historyFile, opts.historyMaxInputSize if opts.historyFile + addHistory repl, opts.historyFile, opts.historyMaxInputSize if opts.historyFile
    + +
  • + + +
  • +
    + +
    + +
    +

    Adapt help inherited from the node REPL

    + +
    + +
        repl.commands[getCommandId(repl, 'load')].help = 'Load code from a file into this REPL session'
         repl
  • diff --git a/documentation/docs/rewriter.html b/documentation/docs/rewriter.html index 014c8b45..94d21566 100644 --- a/documentation/docs/rewriter.html +++ b/documentation/docs/rewriter.html @@ -119,7 +119,19 @@ the resulting parse table. Instead of making the parser handle it all, we take a series of passes over the token stream, using this Rewriter to convert shorthand into the unambiguous long form, add implicit indentation and parentheses, and generally clean things up.

    -

    Create a generated token: one that exists due to a use of implicit syntax.

    + + + + + + +
  • +
    + +
    + +
    +

    Create a generated token: one that exists due to a use of implicit syntax.

    @@ -132,11 +144,11 @@ parentheses, and generally clean things up.

  • -
  • +
  • - +

    The Rewriter class is used by the Lexer, directly against its internal array of tokens.

    @@ -148,18 +160,30 @@ its internal array of tokens.

  • -
  • +
  • - +

    Helpful snippet for debugging:

    -
    console.log (t[0] + '/' + t[1] for t in @tokens).join ' '
    -

    Rewrite the token stream in multiple passes, one logical filter at +

    console.log (t[0] + '/' + t[1] for t in @tokens).join ' '
    +
    +
    + +
  • + + +
  • +
    + +
    + +
    +

    Rewrite the token stream in multiple passes, one logical filter at a time. This could certainly be changed into a single pass through the -stream, with a big ol' efficient switch, but it's much nicer to work with -like this. The order of these passes matters -- indentation must be +stream, with a big ol’ efficient switch, but it’s much nicer to work with +like this. The order of these passes matters — indentation must be corrected before implicit parentheses can be wrapped around blocks of code.

    @@ -177,15 +201,15 @@ corrected before implicit parentheses can be wrapped around blocks of code.

  • -
  • +
  • - +

    Rewrite the token stream, looking one token ahead and behind. Allow the return value of the block to tell us how many tokens to move -forwards (or backwards) in the stream, to make sure we don't miss anything +forwards (or backwards) in the stream, to make sure we don’t miss anything as tokens are inserted and removed, and the stream changes length under our feet.

    @@ -213,11 +237,11 @@ our feet.

  • -
  • +
  • - +

    Leading newlines would introduce an ambiguity in the grammar, so we dispatch them here.

    @@ -231,11 +255,11 @@ dispatch them here.

  • -
  • +
  • - +

    The lexer has tagged the opening parenthesis of a method call. Match it with its paired close. We have the mis-nested outdent case included here for @@ -258,11 +282,11 @@ calls that close on the same line, just before their outdent.

  • -
  • +
  • - +

    The lexer has tagged the opening parenthesis of an indexing operation call. Match it with its paired close.

    @@ -283,11 +307,11 @@ Match it with its paired close.

  • -
  • +
  • - +

    Match tags in token stream starting at i with pattern, skipping HERECOMMENTs Pattern may consist of strings (equality), an array of strings (one of) @@ -307,14 +331,14 @@ or null (wildcard)

  • -
  • +
  • - +

    yes iff standing in front of something looking like -@: or :, skipping over 'HERECOMMENT's

    +@: or :, skipping over ‘HERECOMMENT’s

    @@ -324,11 +348,11 @@ or null (wildcard)

  • -
  • +
  • - +

    yes iff current line of tokens contain an element of tags on same expression level. Stop searching at LINEBREAKS or explicit start of @@ -350,11 +374,11 @@ containing balanced expression.

  • -
  • +
  • - +

    Look for signs of implicit calls and objects in the token stream and add them.

    @@ -366,11 +390,11 @@ add them.

  • -
  • +
  • - +

    Track current balancing depth (both implicit and explicit) on stack.

    @@ -388,11 +412,11 @@ add them.

  • -
  • +
  • - +

    Helper function, used for keeping track of the number of tokens consumed and spliced, when returning for getting a new token.

    @@ -404,11 +428,11 @@ and spliced, when returning for getting a new token.

  • -
  • +
  • - +

    Helper functions

    @@ -421,11 +445,11 @@ and spliced, when returning for getting a new token.

  • -
  • +
  • - +

    Unclosed control statement inside implicit parens (like class declaration or if-conditionals)

    @@ -460,13 +484,13 @@ class declaration or if-conditionals)

  • -
  • +
  • - +
    -

    Don't end an implicit call on next indent if any of these are in an argument

    +

    Don’t end an implicit call on next indent if any of these are in an argument

    @@ -480,11 +504,11 @@ class declaration or if-conditionals)

  • -
  • +
  • - +

    An INDENT closes an implicit call unless

      @@ -503,11 +527,11 @@ class declaration or if-conditionals)

      -
    1. +
    2. - +

      Straightforward start of explicit expression

      @@ -520,11 +544,11 @@ class declaration or if-conditionals)

    3. -
    4. +
    5. - +

      Close all implicit expressions inside of explicitly closed expressions.

      @@ -543,11 +567,11 @@ class declaration or if-conditionals)

    6. -
    7. +
    8. - +

      Recognize standard implicit calls like f a, f() b, f? c, h[0] d etc.

      @@ -566,29 +590,29 @@ f a, f() b, f? c, h[0] d etc.

    9. -
    10. +
    11. - +

      Implicit call taking an implicit indented object as first argument.

      f
      -  a: b
      -  c: d
      +  a: b
      +  c: d
       

      and

      f
      -  1
      -  a: b
      -  b: c
      -

      Don't accept implicit calls of this type, when on the same line + 1 + a: b + b: c +

      Don’t accept implicit calls of this type, when on the same line as the control strucutures below as that may misinterpret constructs like:

      -
      if f
      -   a: 1
      +
      if f
      +   a: 1
       

      as

      -
      if f(a: 1)
      +
      if f(a: 1)
       

      which is probably always unintended. -Furthermore don't allow this in literal arrays, as +Furthermore don’t allow this in literal arrays, as that creates grammatical ambiguities.

      @@ -603,11 +627,11 @@ that creates grammatical ambiguities.

    12. -
    13. +
    14. - +

      Implicit objects start here

      @@ -618,11 +642,11 @@ that creates grammatical ambiguities.

    15. -
    16. +
    17. - +

      Go back to the (implicit) start of the object

      @@ -634,11 +658,11 @@ that creates grammatical ambiguities.

    18. -
    19. +
    20. - +

      Mark if the value is a for loop

      @@ -651,11 +675,11 @@ that creates grammatical ambiguities.

    21. -
    22. +
    23. - +

      Are we just continuing an already declared object?

      @@ -673,17 +697,17 @@ that creates grammatical ambiguities.

    24. -
    25. +
    26. - +

      End implicit calls when chaining method calls like e.g.:

      -
      f ->
      +
      f ->
         a
      -.g b, ->
      +.g b, ->
         c
       .h a
       

      and also

      @@ -693,7 +717,8 @@ like e.g.:

      -
            stackTop()[2].sameLine = no if inImplicitObject() and tag in LINEBREAKS
      +            
      +      stackTop()[2].sameLine = no if inImplicitObject() and tag in LINEBREAKS
       
             newLine = prevTag is 'OUTDENT' or prevToken.newLine
             if tag in IMPLICIT_END or tag in CALL_CLOSERS and newLine
      @@ -703,11 +728,11 @@ like e.g.:

    27. -
    28. +
    29. - +

      Close implicit calls when reached end of argument list

      @@ -719,11 +744,11 @@ like e.g.:

    30. -
    31. +
    32. - +

      Close implicit objects such as: return a: 1, b: 2 unless true

      @@ -737,14 +762,14 @@ return a: 1, b: 2 unless true

    33. -
    34. +
    35. - +
      -

      Close implicit objects when at end of line, line didn't end with a comma -and the implicit object didn't start the line or the next line doesn't look like +

      Close implicit objects when at end of line, line didn’t end with a comma +and the implicit object didn’t start the line or the next line doesn’t look like the continuation of an object.

      @@ -758,21 +783,21 @@ the continuation of an object.

    36. -
    37. +
    38. - +

      Close implicit object if comma is the last character -and what comes after doesn't look like it belongs. +and what comes after doesn’t look like it belongs. This is used for trailing commas and calls, like:

      x =
      -    a: b,
      -    c: d,
      -e = 2
      +    a: b,
      +    c: d,
      +e = 2
       

      and

      -
      f a, b: c, d: e, f, g: h: i, j
      +
      f a, b: c, d: e, f, g: h: i, j
       
      @@ -783,20 +808,21 @@ e = 2
    39. -
    40. +
    41. - +

      When nextTag is OUTDENT the comma is insignificant and should just be ignored so embed it in the implicit object.

      -

      When it isn't the comma go on to play a role in a call or +

      When it isn’t the comma go on to play a role in a call or array further up the stack, so give it a chance.

      -
              offset = if nextTag is 'OUTDENT' then 1 else 0
      +            
      +        offset = if nextTag is 'OUTDENT' then 1 else 0
               while inImplicitObject()
                 endImplicitObject i + offset
             return forward(1)
      @@ -804,11 +830,11 @@ array further up the stack, so give it a chance.

    42. -
    43. +
    44. - +

      Add location data to all tokens generated by the rewriter.

      @@ -834,15 +860,15 @@ array further up the stack, so give it a chance.

    45. -
    46. +
    47. - +
      -

      Because our grammar is LALR(1), it can't handle some single-line +

      Because our grammar is LALR(1), it can’t handle some single-line expressions that lack ending delimiters. The Rewriter adds the implicit -blocks, so it doesn't need to. To keep the grammar clean and tidy, trailing +blocks, so it doesn’t need to. To keep the grammar clean and tidy, trailing newlines within expressions are removed and the indentation tokens of empty blocks are added.

      @@ -888,11 +914,11 @@ blocks are added.

    48. -
    49. +
    50. - +

      Tag postfix conditionals as such, so that we can parse them with a different precedence.

      @@ -921,11 +947,11 @@ different precedence.

    51. -
    52. +
    53. - +

      Generate the indentation tokens, based on another token on the same line.

      @@ -946,11 +972,11 @@ different precedence.

    54. -
    55. +
    56. - +

      Look up a tag by token index.

      @@ -961,11 +987,11 @@ different precedence.

    57. -
    58. +
    59. - +

      Constants

      @@ -974,11 +1000,23 @@ different precedence.

    60. -
    61. +
    62. - + +
      + +
      + +
    63. + + +
    64. +
      + +
      +

      List of the token pairs that must be balanced.

      @@ -997,13 +1035,13 @@ different precedence.

    65. -
    66. +
    67. - +
      -

      The inverse mappings of BALANCED_PAIRS we're trying to fix up, so we can +

      The inverse mappings of BALANCED_PAIRS we’re trying to fix up, so we can look things up from either end.

      @@ -1013,11 +1051,11 @@ look things up from either end.

    68. -
    69. +
    70. - +

      The tokens that signal the start/end of a balanced pair.

      @@ -1033,11 +1071,11 @@ EXPRESSION_END = []
    71. -
    72. +
    73. - +

      Tokens that indicate the close of a clause of an expression.

      @@ -1048,11 +1086,11 @@ EXPRESSION_END = []
    74. -
    75. +
    76. - +

      Tokens that, if followed by an IMPLICIT_CALL, indicate a function invocation.

      @@ -1063,11 +1101,11 @@ EXPRESSION_END = []
    77. -
    78. +
    79. - +

      If preceded by an IMPLICIT_FUNC, indicates a function invocation.

      @@ -1084,11 +1122,11 @@ IMPLICIT_UNSPACED_CALL = ['+', +
    80. - +

      Tokens that always mark the end of an implicit call for single-liners.

      @@ -1100,14 +1138,14 @@ IMPLICIT_UNSPACED_CALL = ['+', +
    81. - +

      Single-line flavors of block expressions that have unclosed endings. -The grammar can't disambiguate them, so we insert the implicit indentation.

      +The grammar can’t disambiguate them, so we insert the implicit indentation.

      @@ -1117,11 +1155,11 @@ SINGLE_CLOSERS = ['TERMINATOR', +
    82. - +

      Tokens that end a line.

      @@ -1132,11 +1170,11 @@ SINGLE_CLOSERS = ['TERMINATOR', +
    83. - +

      Tokens that close open calls when they follow a newline.

      diff --git a/documentation/docs/scope.html b/documentation/docs/scope.html index 944bbe93..14bb0365 100644 --- a/documentation/docs/scope.html +++ b/documentation/docs/scope.html @@ -192,7 +192,7 @@ it belongs to.

      -

      When super is called, we need to find the name of the current method we're +

      When super is called, we need to find the name of the current method we’re in, so that we know how to invoke the same method of the parent class. This can get complicated if super is being called from an inner function. namedMethod will walk up the scope tree until it either finds the first @@ -304,7 +304,7 @@ walks up to the root scope.

      If we need to store an intermediate result, find an available name for a -compiler-generated variable. _var, _var2, and so on...

      +compiler-generated variable. _var, _var2, and so on…

    diff --git a/documentation/docs/sourcemap.html b/documentation/docs/sourcemap.html index 4f3b31d0..9bab8b46 100644 --- a/documentation/docs/sourcemap.html +++ b/documentation/docs/sourcemap.html @@ -115,7 +115,7 @@

    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're concerned with mapping pretty-printed +JavaScript, but in our case, we’re concerned with mapping pretty-printed JavaScript back to CoffeeScript.

    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 @@ -178,7 +178,7 @@ positions for a single line of output JavaScript code.

    Maps locations in a single generated JavaScript file back to locations in the original CoffeeScript source file.

    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 +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.

    @@ -251,7 +251,7 @@ code.

    Builds up a V3 source map, returning the generated JSON as a string. options.sourceRoot may be used to specify the sourceRoot written to the source map. Also, options.sourceFiles and options.generatedFile may be passed to -set "sources" and "file", respectively.

    +set “sources” and “file”, respectively.

    @@ -280,7 +280,7 @@ set "sources" and "file", respectively.

    -

    Write a comma if we've already written a segment on this line.

    +

    Write a comma if we’ve already written a segment on this line.

    @@ -298,7 +298,7 @@ set "sources" and "file", respectively.

    Write the next segment. Segments can be 1, 4, or 5 values. If just one, then it -is a generated column which doesn't match anything in the source code.

    +is a generated column which doesn’t match anything in the source code.

    The starting column in the generated source, relative to any previous recorded column for the current line:

    @@ -364,7 +364,7 @@ column for the current line:

    -

    Produce the canonical JSON object format for a "v3" source map.

    +

    Produce the canonical JSON object format for a “v3” source map.

    @@ -402,7 +402,7 @@ column for the current line:

    -

    Note that SourceMap VLQ encoding is "backwards". MIDI-style VLQ encoding puts +

    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 Wikipedia). SourceMap VLQ does things the other way around, with the least significat four diff --git a/documentation/docs/underscore.html b/documentation/docs/underscore.html index e8d86f5c..1d5307bb 100644 --- a/documentation/docs/underscore.html +++ b/documentation/docs/underscore.html @@ -32,12 +32,11 @@ Underscore is freely distributable under the terms of the MIT license. Portions of Underscore are inspired by or borrowed from -Prototype.js, Oliver Steele's -Functional, and John Resig's +Prototype.js, Oliver Steele’s +Functional, and John Resig’s Micro-Templating. For all details and documentation: http://documentcloud.github.com/underscore/

    -

    Baseline setup

    @@ -50,12 +49,10 @@ For all details and documentation:
    -

    Establish the root object, window in the browser, or global on the server.

    +

    Baseline setup

    -
    root = this
    -
  • @@ -65,12 +62,9 @@ For all details and documentation:
    -

    Save the previous value of the _ variable.

    - + -
    previousUnderscore = root._
    - @@ -80,12 +74,11 @@ For all details and documentation:
    -

    Establish the object that gets thrown to break out of a loop iteration. -StopIteration is SOP on Mozilla.

    +

    Establish the root object, window in the browser, or global on the server.

    -
    breaker = if typeof(StopIteration) is 'undefined' then '__break__' else StopIteration
    +
    root = this
    @@ -96,11 +89,11 @@ For all details and documentation:
    -

    Helper function to escape RegExp contents, because JS doesn't have one.

    +

    Save the previous value of the _ variable.

    -
    escapeRegExp = (string) -> string.replace(/([.*+?^${}()|[\]\/\\])/g, '\\$1')
    +
    previousUnderscore = root._
    @@ -111,6 +104,37 @@ For all details and documentation:
    +

    Establish the object that gets thrown to break out of a loop iteration. +StopIteration is SOP on Mozilla.

    + + + +
    breaker = if typeof(StopIteration) is 'undefined' then '__break__' else StopIteration
    + + + + +
  • +
    + +
    + +
    +

    Helper function to escape RegExp contents, because JS doesn’t have one.

    + +
    + +
    escapeRegExp = (string) -> string.replace(/([.*+?^${}()|[\]\/\\])/g, '\\$1')
    + +
  • + + +
  • +
    + +
    + +

    Save bytes in the minified (but not gzipped) version:

    @@ -121,11 +145,11 @@ ObjProto = Object.prototype
  • -
  • +
  • - +

    Create quick reference variables for speed access to core prototypes.

    @@ -140,11 +164,11 @@ propertyIsEnumerable = ObjProto.propertyIsEnumerable
  • -
  • +
  • - +

    All ECMA5 native implementations we hope to use are declared here.

    @@ -165,47 +189,17 @@ nativeKeys = Object.keys
  • -
  • -
    - -
    - -
    -

    Create a safe reference to the Underscore object for use below.

    - -
    - -
    _ = (obj) -> new wrapper(obj)
    - -
  • - - -
  • -
    - -
    - -
    -

    Export the Underscore object for CommonJS.

    - -
    - -
    if typeof(exports) != 'undefined' then exports._ = _
    - -
  • - -
  • -

    Export Underscore to global scope.

    +

    Create a safe reference to the Underscore object for use below.

    -
    root._ = _
    +
    _ = (obj) -> new wrapper(obj)
  • @@ -216,11 +210,11 @@ nativeKeys = Object.keys
    -

    Current version.

    +

    Export the Underscore object for CommonJS.

    -
    _.VERSION = '1.1.0'
    +
    if typeof(exports) != 'undefined' then exports._ = _
    @@ -228,13 +222,15 @@ nativeKeys = Object.keys
  • -
    +
    -

    Collection Functions

    +

    Export Underscore to global scope.

    +
    root._ = _
    +
  • @@ -244,22 +240,11 @@ nativeKeys = Object.keys
    -

    The cornerstone, an each implementation. -Handles objects implementing forEach, arrays, and raw objects.

    +

    Current version.

    -
    _.each = (obj, iterator, context) ->
    -  try
    -    if nativeForEach and obj.forEach is nativeForEach
    -      obj.forEach iterator, context
    -    else if _.isNumber obj.length
    -      iterator.call context, obj[i], i, obj for i in [0...obj.length]
    -    else
    -      iterator.call context, val, key, obj  for own key, val of obj
    -  catch e
    -    throw e if e isnt breaker
    -  obj
    +
    _.VERSION = '1.1.0'
    @@ -270,18 +255,10 @@ Handles objects implementing forEach, arrays, and raw objects.<
    -

    Return the results of applying the iterator to each element. Use JavaScript -1.6's version of map, if possible.

    +

    Collection Functions

    -
    _.map = (obj, iterator, context) ->
    -  return obj.map(iterator, context) if nativeMap and obj.map is nativeMap
    -  results = []
    -  _.each obj, (value, index, list) ->
    -    results.push iterator.call context, value, index, list
    -  results
    - @@ -291,19 +268,9 @@ Handles objects implementing forEach, arrays, and raw objects.<
    -

    Reduce builds up a single result from a list of values. Also known as -inject, or foldl. Uses JavaScript 1.8's version of reduce, if possible.

    - + -
    _.reduce = (obj, iterator, memo, context) ->
    -  if nativeReduce and obj.reduce is nativeReduce
    -    iterator = _.bind iterator, context if context
    -    return obj.reduce iterator, memo
    -  _.each obj, (value, index, list) ->
    -    memo = iterator.call context, memo, value, index, list
    -  memo
    - @@ -313,17 +280,22 @@ Handles objects implementing forEach, arrays, and raw objects.<
    -

    The right-associative version of reduce, also known as foldr. Uses -JavaScript 1.8's version of reduceRight, if available.

    +

    The cornerstone, an each implementation. +Handles objects implementing forEach, arrays, and raw objects.

    -
    _.reduceRight = (obj, iterator, memo, context) ->
    -  if nativeReduceRight and obj.reduceRight is nativeReduceRight
    -    iterator = _.bind iterator, context if context
    -    return obj.reduceRight iterator, memo
    -  reversed = _.clone(_.toArray(obj)).reverse()
    -  _.reduce reversed, iterator, memo, context
    +
    _.each = (obj, iterator, context) ->
    +  try
    +    if nativeForEach and obj.forEach is nativeForEach
    +      obj.forEach iterator, context
    +    else if _.isNumber obj.length
    +      iterator.call context, obj[i], i, obj for i in [0...obj.length]
    +    else
    +      iterator.call context, val, key, obj  for own key, val of obj
    +  catch e
    +    throw e if e isnt breaker
    +  obj
    @@ -334,17 +306,17 @@ JavaScript 1.8's version of reduceRight, if available.

    -

    Return the first value which passes a truth test.

    +

    Return the results of applying the iterator to each element. Use JavaScript +1.6’s version of map, if possible.

    -
    _.detect = (obj, iterator, context) ->
    -  result = null
    -  _.each obj, (value, index, list) ->
    -    if iterator.call context, value, index, list
    -      result = value
    -      _.breakLoop()
    -  result
    +
    _.map = (obj, iterator, context) ->
    +  return obj.map(iterator, context) if nativeMap and obj.map is nativeMap
    +  results = []
    +  _.each obj, (value, index, list) ->
    +    results.push iterator.call context, value, index, list
    +  results
    @@ -355,17 +327,18 @@ JavaScript 1.8's version of reduceRight, if available.

    -

    Return all the elements that pass a truth test. Use JavaScript 1.6's -filter, if it exists.

    +

    Reduce builds up a single result from a list of values. Also known as +inject, or foldl. Uses JavaScript 1.8’s version of reduce, if possible.

    -
    _.filter = (obj, iterator, context) ->
    -  return obj.filter iterator, context if nativeFilter and obj.filter is nativeFilter
    -  results = []
    -  _.each obj, (value, index, list) ->
    -    results.push value if iterator.call context, value, index, list
    -  results
    +
    _.reduce = (obj, iterator, memo, context) ->
    +  if nativeReduce and obj.reduce is nativeReduce
    +    iterator = _.bind iterator, context if context
    +    return obj.reduce iterator, memo
    +  _.each obj, (value, index, list) ->
    +    memo = iterator.call context, memo, value, index, list
    +  memo
    @@ -376,15 +349,17 @@ JavaScript 1.8's version of reduceRight, if available.

    -

    Return all the elements for which a truth test fails.

    +

    The right-associative version of reduce, also known as foldr. Uses +JavaScript 1.8’s version of reduceRight, if available.

    -
    _.reject = (obj, iterator, context) ->
    -  results = []
    -  _.each obj, (value, index, list) ->
    -    results.push value if not iterator.call context, value, index, list
    -  results
    +
    _.reduceRight = (obj, iterator, memo, context) ->
    +  if nativeReduceRight and obj.reduceRight is nativeReduceRight
    +    iterator = _.bind iterator, context if context
    +    return obj.reduceRight iterator, memo
    +  reversed = _.clone(_.toArray(obj)).reverse()
    +  _.reduce reversed, iterator, memo, context
    @@ -395,17 +370,16 @@ JavaScript 1.8's version of reduceRight, if available.

    -

    Determine whether all of the elements match a truth test. Delegate to -JavaScript 1.6's every, if it is present.

    +

    Return the first value which passes a truth test.

    -
    _.every = (obj, iterator, context) ->
    -  iterator ||= _.identity
    -  return obj.every iterator, context if nativeEvery and obj.every is nativeEvery
    -  result = true
    -  _.each obj, (value, index, list) ->
    -    _.breakLoop() unless (result = result and iterator.call(context, value, index, list))
    +            
    _.detect = (obj, iterator, context) ->
    +  result = null
    +  _.each obj, (value, index, list) ->
    +    if iterator.call context, value, index, list
    +      result = value
    +      _.breakLoop()
       result
    @@ -417,18 +391,17 @@ JavaScript 1.6's every, if it is present.

    -

    Determine if at least one element in the object matches a truth test. Use -JavaScript 1.6's some, if it exists.

    +

    Return all the elements that pass a truth test. Use JavaScript 1.6’s +filter, if it exists.

    -
    _.some = (obj, iterator, context) ->
    -  iterator ||= _.identity
    -  return obj.some iterator, context if nativeSome and obj.some is nativeSome
    -  result = false
    -  _.each obj, (value, index, list) ->
    -    _.breakLoop() if (result = iterator.call(context, value, index, list))
    -  result
    +
    _.filter = (obj, iterator, context) ->
    +  return obj.filter iterator, context if nativeFilter and obj.filter is nativeFilter
    +  results = []
    +  _.each obj, (value, index, list) ->
    +    results.push value if iterator.call context, value, index, list
    +  results
    @@ -439,15 +412,15 @@ JavaScript 1.6's some, if it exists.

    -

    Determine if a given value is included in the array or object, -based on ===.

    +

    Return all the elements for which a truth test fails.

    -
    _.include = (obj, target) ->
    -  return _.indexOf(obj, target) isnt -1 if nativeIndexOf and obj.indexOf is nativeIndexOf
    -  return true for own key, val of obj when val is target
    -  false
    +
    _.reject = (obj, iterator, context) ->
    +  results = []
    +  _.each obj, (value, index, list) ->
    +    results.push value if not iterator.call context, value, index, list
    +  results
    @@ -458,13 +431,18 @@ based on ===.

    -

    Invoke a method with arguments on every item in a collection.

    +

    Determine whether all of the elements match a truth test. Delegate to +JavaScript 1.6’s every, if it is present.

    -
    _.invoke = (obj, method) ->
    -  args = _.rest arguments, 2
    -  (if method then val[method] else val).apply(val, args) for val in obj
    +
    _.every = (obj, iterator, context) ->
    +  iterator ||= _.identity
    +  return obj.every iterator, context if nativeEvery and obj.every is nativeEvery
    +  result = true
    +  _.each obj, (value, index, list) ->
    +    _.breakLoop() unless (result = result and iterator.call(context, value, index, list))
    +  result
    @@ -475,12 +453,18 @@ based on ===.

    -

    Convenience version of a common use case of map: fetching a property.

    +

    Determine if at least one element in the object matches a truth test. Use +JavaScript 1.6’s some, if it exists.

    -
    _.pluck = (obj, key) ->
    -  _.map(obj, (val) -> val[key])
    +
    _.some = (obj, iterator, context) ->
    +  iterator ||= _.identity
    +  return obj.some iterator, context if nativeSome and obj.some is nativeSome
    +  result = false
    +  _.each obj, (value, index, list) ->
    +    _.breakLoop() if (result = iterator.call(context, value, index, list))
    +  result
    @@ -491,17 +475,15 @@ based on ===.

    -

    Return the maximum item or (item-based computation).

    +

    Determine if a given value is included in the array or object, +based on ===.

    -
    _.max = (obj, iterator, context) ->
    -  return Math.max.apply(Math, obj) if not iterator and _.isArray(obj)
    -  result = computed: -Infinity
    -  _.each obj, (value, index, list) ->
    -    computed = if iterator then iterator.call(context, value, index, list) else value
    -    computed >= result.computed and (result = {value: value, computed: computed})
    -  result.value
    +
    _.include = (obj, target) ->
    +  return _.indexOf(obj, target) isnt -1 if nativeIndexOf and obj.indexOf is nativeIndexOf
    +  return true for own key, val of obj when val is target
    +  false
    @@ -512,17 +494,13 @@ based on ===.

    -

    Return the minimum element (or element-based computation).

    +

    Invoke a method with arguments on every item in a collection.

    -
    _.min = (obj, iterator, context) ->
    -  return Math.min.apply(Math, obj) if not iterator and _.isArray(obj)
    -  result = computed: Infinity
    -  _.each obj, (value, index, list) ->
    -    computed = if iterator then iterator.call(context, value, index, list) else value
    -    computed < result.computed and (result = {value: value, computed: computed})
    -  result.value
    +
    _.invoke = (obj, method) ->
    +  args = _.rest arguments, 2
    +  (if method then val[method] else val).apply(val, args) for val in obj
    @@ -533,17 +511,15 @@ based on ===.

    -

    Sort the object's values by a criterion produced by an iterator.

    +

    Convenience version of a common use case of map: fetching a property.

    -
    _.sortBy = (obj, iterator, context) ->
    -  _.pluck(((_.map obj, (value, index, list) ->
    -    {value: value, criteria: iterator.call(context, value, index, list)}
    -  ).sort((left, right) ->
    -    a = left.criteria; b = right.criteria
    -    if a < b then -1 else if a > b then 1 else 0
    -  )), 'value')
    +
    _.pluck = (obj, key) ->
    +  _.map(obj, (val) -> val[key])
    +
    +
    +
    @@ -554,19 +530,17 @@ based on ===.

    -

    Use a comparator function to figure out at what index an object should -be inserted so as to maintain order. Uses binary search.

    +

    Return the maximum item or (item-based computation).

    -
    _.sortedIndex = (array, obj, iterator) ->
    -  iterator ||= _.identity
    -  low =  0
    -  high = array.length
    -  while low < high
    -    mid = (low + high) >> 1
    -    if iterator(array[mid]) < iterator(obj) then low = mid + 1 else high = mid
    -  low
    +
    _.max = (obj, iterator, context) ->
    +  return Math.max.apply(Math, obj) if not iterator and _.isArray(obj)
    +  result = computed: -Infinity
    +  _.each obj, (value, index, list) ->
    +    computed = if iterator then iterator.call(context, value, index, list) else value
    +    computed >= result.computed and (result = {value: value, computed: computed})
    +  result.value
    @@ -577,16 +551,17 @@ be inserted so as to maintain order. Uses binary search.

    -

    Convert anything iterable into a real, live array.

    +

    Return the minimum element (or element-based computation).

    -
    _.toArray = (iterable) ->
    -  return []                   if (!iterable)
    -  return iterable.toArray()   if (iterable.toArray)
    -  return iterable             if (_.isArray(iterable))
    -  return slice.call(iterable) if (_.isArguments(iterable))
    -  _.values(iterable)
    +
    _.min = (obj, iterator, context) ->
    +  return Math.min.apply(Math, obj) if not iterator and _.isArray(obj)
    +  result = computed: Infinity
    +  _.each obj, (value, index, list) ->
    +    computed = if iterator then iterator.call(context, value, index, list) else value
    +    computed < result.computed and (result = {value: value, computed: computed})
    +  result.value
    @@ -597,11 +572,20 @@ be inserted so as to maintain order. Uses binary search.

    -

    Return the number of elements in an object.

    +

    Sort the object’s values by a criterion produced by an iterator.

    -
    _.size = (obj) -> _.toArray(obj).length
    +
    _.sortBy = (obj, iterator, context) ->
    +  _.pluck(((_.map obj, (value, index, list) ->
    +    {value: value, criteria: iterator.call(context, value, index, list)}
    +  ).sort((left, right) ->
    +    a = left.criteria; b = right.criteria
    +    if a < b then -1 else if a > b then 1 else 0
    +  )), 'value')
    +
    +
    +
    @@ -609,13 +593,23 @@ be inserted so as to maintain order. Uses binary search.

  • -
    +
    -

    Array Functions

    +

    Use a comparator function to figure out at what index an object should +be inserted so as to maintain order. Uses binary search.

    +
    _.sortedIndex = (array, obj, iterator) ->
    +  iterator ||= _.identity
    +  low =  0
    +  high = array.length
    +  while low < high
    +    mid = (low + high) >> 1
    +    if iterator(array[mid]) < iterator(obj) then low = mid + 1 else high = mid
    +  low
    +
  • @@ -625,14 +619,16 @@ be inserted so as to maintain order. Uses binary search.

    -

    Get the first element of an array. Passing n will return the first N -values in the array. Aliased as head. The guard check allows it to work -with map.

    +

    Convert anything iterable into a real, live array.

    -
    _.first = (array, n, guard) ->
    -  if n and not guard then slice.call(array, 0, n) else array[0]
    +
    _.toArray = (iterable) ->
    +  return []                   if (!iterable)
    +  return iterable.toArray()   if (iterable.toArray)
    +  return iterable             if (_.isArray(iterable))
    +  return slice.call(iterable) if (_.isArguments(iterable))
    +  _.values(iterable)
    @@ -643,15 +639,11 @@ with map.

    -

    Returns everything but the first entry of the array. Aliased as tail. -Especially useful on the arguments object. Passing an index will return -the rest of the values in the array from that index onward. The guard -check allows it to work with map.

    +

    Return the number of elements in an object.

    -
    _.rest = (array, index, guard) ->
    -  slice.call(array, if _.isUndefined(index) or guard then 1 else index)
    +
    _.size = (obj) -> _.toArray(obj).length
    @@ -662,12 +654,10 @@ check allows it to work with map.

    -

    Get the last element of an array.

    +

    Array Functions

    -
    _.last = (array) -> array[array.length - 1]
    - @@ -677,12 +667,9 @@ check allows it to work with map.

    -

    Trim out all falsy values from an array.

    - + -
    _.compact = (array) -> item for item in array when item
    - @@ -692,16 +679,14 @@ check allows it to work with map.

    -

    Return a completely flattened version of an array.

    +

    Get the first element of an array. Passing n will return the first N +values in the array. Aliased as head. The guard check allows it to work +with map.

    -
    _.flatten = (array) ->
    -  _.reduce array, (memo, value) ->
    -    return memo.concat(_.flatten(value)) if _.isArray value
    -    memo.push value
    -    memo
    -  , []
    +
    _.first = (array, n, guard) ->
    +  if n and not guard then slice.call(array, 0, n) else array[0]
    @@ -712,13 +697,15 @@ check allows it to work with map.

    -

    Return a version of the array that does not contain the specified value(s).

    +

    Returns everything but the first entry of the array. Aliased as tail. +Especially useful on the arguments object. Passing an index will return +the rest of the values in the array from that index onward. The guard +check allows it to work with map.

    -
    _.without = (array) ->
    -  values = _.rest arguments
    -  val for val in _.toArray(array) when not _.include values, val
    +
    _.rest = (array, index, guard) ->
    +  slice.call(array, if _.isUndefined(index) or guard then 1 else index)
    @@ -729,16 +716,11 @@ check allows it to work with map.

    -

    Produce a duplicate-free version of the array. If the array has already -been sorted, you have the option of using a faster algorithm.

    +

    Get the last element of an array.

    -
    _.uniq = (array, isSorted) ->
    -  memo = []
    -  for el, i in _.toArray array
    -    memo.push el if i is 0 || (if isSorted is true then _.last(memo) isnt el else not _.include(memo, el))
    -  memo
    +
    _.last = (array) -> array[array.length - 1]
    @@ -749,16 +731,11 @@ been sorted, you have the option of using a faster algorithm.

    -

    Produce an array that contains every item shared between all the -passed-in arrays.

    +

    Trim out all falsy values from an array.

    -
    _.intersect = (array) ->
    -  rest = _.rest arguments
    -  _.select _.uniq(array), (item) ->
    -    _.all rest, (other) ->
    -      _.indexOf(other, item) >= 0
    +
    _.compact = (array) -> item for item in array when item
    @@ -769,17 +746,16 @@ passed-in arrays.

    -

    Zip together multiple lists into a single array -- elements that share -an index go together.

    +

    Return a completely flattened version of an array.

    -
    _.zip = ->
    -  length =  _.max _.pluck arguments, 'length'
    -  results = new Array length
    -  for i in [0...length]
    -    results[i] = _.pluck arguments, String i
    -  results
    +
    _.flatten = (array) ->
    +  _.reduce array, (memo, value) ->
    +    return memo.concat(_.flatten(value)) if _.isArray value
    +    memo.push value
    +    memo
    +  , []
    @@ -790,18 +766,13 @@ an index go together.

    -

    If the browser doesn't supply us with indexOf (I'm looking at you, MSIE), -we need this function. Return the position of the first occurrence of an -item in an array, or -1 if the item is not included in the array.

    +

    Return a version of the array that does not contain the specified value(s).

    -
    _.indexOf = (array, item) ->
    -  return array.indexOf item if nativeIndexOf and array.indexOf is nativeIndexOf
    -  i = 0; l = array.length
    -  while l - i
    -    if array[i] is item then return i else i++
    -  -1
    +
    _.without = (array) ->
    +  values = _.rest arguments
    +  val for val in _.toArray(array) when not _.include values, val
    @@ -812,17 +783,16 @@ item in an array, or -1 if the item is not included in the array.

    -

    Provide JavaScript 1.6's lastIndexOf, delegating to the native function, -if possible.

    +

    Produce a duplicate-free version of the array. If the array has already +been sorted, you have the option of using a faster algorithm.

    -
    _.lastIndexOf = (array, item) ->
    -  return array.lastIndexOf(item) if nativeLastIndexOf and array.lastIndexOf is nativeLastIndexOf
    -  i = array.length
    -  while i
    -    if array[i] is item then return i else i--
    -  -1
    +
    _.uniq = (array, isSorted) ->
    +  memo = []
    +  for el, i in _.toArray array
    +    memo.push el if i is 0 || (if isSorted is true then _.last(memo) isnt el else not _.include(memo, el))
    +  memo
    @@ -833,26 +803,16 @@ if possible.

    -

    Generate an integer Array containing an arithmetic progression. A port of -the native Python range function.

    +

    Produce an array that contains every item shared between all the +passed-in arrays.

    -
    _.range = (start, stop, step) ->
    -  a         = arguments
    -  solo      = a.length <= 1
    -  i = start = if solo then 0 else a[0]
    -  stop      = if solo then a[0] else a[1]
    -  step      = a[2] or 1
    -  len       = Math.ceil((stop - start) / step)
    -  return []   if len <= 0
    -  range     = new Array len
    -  idx       = 0
    -  loop
    -    return range if (if step > 0 then i - stop else stop - i) >= 0
    -    range[idx] = i
    -    idx++
    -    i+= step
    +
    _.intersect = (array) ->
    +  rest = _.rest arguments
    +  _.select _.uniq(array), (item) ->
    +    _.all rest, (other) ->
    +      _.indexOf(other, item) >= 0
    @@ -860,13 +820,21 @@ if possible.

  • -
    +
    -

    Function Functions

    +

    Zip together multiple lists into a single array — elements that share +an index go together.

    +
    _.zip = ->
    +  length =  _.max _.pluck arguments, 'length'
    +  results = new Array length
    +  for i in [0...length]
    +    results[i] = _.pluck arguments, String i
    +  results
    +
  • @@ -876,14 +844,18 @@ if possible.

    -

    Create a function bound to a given object (assigning this, and arguments, -optionally). Binding with arguments is also known as curry.

    +

    If the browser doesn’t supply us with indexOf (I’m looking at you, MSIE), +we need this function. Return the position of the first occurrence of an +item in an array, or -1 if the item is not included in the array.

    -
    _.bind = (func, obj) ->
    -  args = _.rest arguments, 2
    -  -> func.apply obj or root, args.concat arguments
    +
    _.indexOf = (array, item) ->
    +  return array.indexOf item if nativeIndexOf and array.indexOf is nativeIndexOf
    +  i = 0; l = array.length
    +  while l - i
    +    if array[i] is item then return i else i++
    +  -1
    @@ -894,15 +866,17 @@ optionally). Binding with arguments is also known as curry.

    -

    Bind all of an object's methods to that object. Useful for ensuring that -all callbacks defined on an object belong to it.

    +

    Provide JavaScript 1.6’s lastIndexOf, delegating to the native function, +if possible.

    -
    _.bindAll = (obj) ->
    -  funcs = if arguments.length > 1 then _.rest(arguments) else _.functions(obj)
    -  _.each funcs, (f) -> obj[f] = _.bind obj[f], obj
    -  obj
    +
    _.lastIndexOf = (array, item) ->
    +  return array.lastIndexOf(item) if nativeLastIndexOf and array.lastIndexOf is nativeLastIndexOf
    +  i = array.length
    +  while i
    +    if array[i] is item then return i else i--
    +  -1
    @@ -913,14 +887,26 @@ all callbacks defined on an object belong to it.

    -

    Delays a function for the given number of milliseconds, and then calls -it with the arguments supplied.

    +

    Generate an integer Array containing an arithmetic progression. A port of +the native Python range function.

    -
    _.delay = (func, wait) ->
    -  args = _.rest arguments, 2
    -  setTimeout((-> func.apply(func, args)), wait)
    +
    _.range = (start, stop, step) ->
    +  a         = arguments
    +  solo      = a.length <= 1
    +  i = start = if solo then 0 else a[0]
    +  stop      = if solo then a[0] else a[1]
    +  step      = a[2] or 1
    +  len       = Math.ceil((stop - start) / step)
    +  return []   if len <= 0
    +  range     = new Array len
    +  idx       = 0
    +  loop
    +    return range if (if step > 0 then i - stop else stop - i) >= 0
    +    range[idx] = i
    +    idx++
    +    i+= step
    @@ -931,18 +917,10 @@ it with the arguments supplied.

    -

    Memoize an expensive function by storing its results.

    +

    Function Functions

    -
    _.memoize = (func, hasher) ->
    -  memo = {}
    -  hasher or= _.identity
    -  ->
    -    key = hasher.apply this, arguments
    -    return memo[key] if key of memo
    -    memo[key] = func.apply this, arguments
    - @@ -952,14 +930,9 @@ it with the arguments supplied.

    -

    Defers a function, scheduling it to run after the current call stack has -cleared.

    - + -
    _.defer = (func) ->
    -  _.delay.apply _, [func, 1].concat _.rest arguments
    - @@ -969,14 +942,14 @@ cleared.

    -

    Returns the first function passed as an argument to the second, -allowing you to adjust arguments, run code before and after, and -conditionally execute the original function.

    +

    Create a function bound to a given object (assigning this, and arguments, +optionally). Binding with arguments is also known as curry.

    -
    _.wrap = (func, wrapper) ->
    -  -> wrapper.apply wrapper, [func].concat arguments
    +
    _.bind = (func, obj) ->
    +  args = _.rest arguments, 2
    +  -> func.apply obj or root, args.concat arguments
    @@ -987,18 +960,15 @@ conditionally execute the original function.

    -

    Returns a function that is the composition of a list of functions, each -consuming the return value of the function that follows.

    +

    Bind all of an object’s methods to that object. Useful for ensuring that +all callbacks defined on an object belong to it.

    -
    _.compose = ->
    -  funcs = arguments
    -  ->
    -    args = arguments
    -    for i in [funcs.length - 1..0] by -1
    -      args = [funcs[i].apply(this, args)]
    -    args[0]
    +
    _.bindAll = (obj) ->
    +  funcs = if arguments.length > 1 then _.rest(arguments) else _.functions(obj)
    +  _.each funcs, (f) -> obj[f] = _.bind obj[f], obj
    +  obj
    @@ -1006,13 +976,18 @@ consuming the return value of the function that follows.

  • -
    +
    -

    Object Functions

    +

    Delays a function for the given number of milliseconds, and then calls +it with the arguments supplied.

    +
    _.delay = (func, wait) ->
    +  args = _.rest arguments, 2
    +  setTimeout((-> func.apply(func, args)), wait)
    +
  • @@ -1022,13 +997,17 @@ consuming the return value of the function that follows.

    -

    Retrieve the names of an object's properties.

    +

    Memoize an expensive function by storing its results.

    -
    _.keys = nativeKeys or (obj) ->
    -  return _.range 0, obj.length if _.isArray(obj)
    -  key for key, val of obj
    +
    _.memoize = (func, hasher) ->
    +  memo = {}
    +  hasher or= _.identity
    +  ->
    +    key = hasher.apply this, arguments
    +    return memo[key] if key of memo
    +    memo[key] = func.apply this, arguments
    @@ -1039,12 +1018,13 @@ consuming the return value of the function that follows.

    -

    Retrieve the values of an object's properties.

    +

    Defers a function, scheduling it to run after the current call stack has +cleared.

    -
    _.values = (obj) ->
    -  _.map obj, _.identity
    +
    _.defer = (func) ->
    +  _.delay.apply _, [func, 1].concat _.rest arguments
    @@ -1055,12 +1035,14 @@ consuming the return value of the function that follows.

    -

    Return a sorted list of the function names available in Underscore.

    +

    Returns the first function passed as an argument to the second, +allowing you to adjust arguments, run code before and after, and +conditionally execute the original function.

    -
    _.functions = (obj) ->
    -  _.filter(_.keys(obj), (key) -> _.isFunction(obj[key])).sort()
    +
    _.wrap = (func, wrapper) ->
    +  -> wrapper.apply wrapper, [func].concat arguments
    @@ -1071,14 +1053,18 @@ consuming the return value of the function that follows.

    -

    Extend a given object with all of the properties in a source object.

    +

    Returns a function that is the composition of a list of functions, each +consuming the return value of the function that follows.

    -
    _.extend = (obj) ->
    -  for source in _.rest(arguments)
    -    obj[key] = val for key, val of source
    -  obj
    +
    _.compose = ->
    +  funcs = arguments
    +  ->
    +    args = arguments
    +    for i in [funcs.length - 1..0] by -1
    +      args = [funcs[i].apply(this, args)]
    +    args[0]
    @@ -1089,14 +1075,10 @@ consuming the return value of the function that follows.

    -

    Create a (shallow-cloned) duplicate of an object.

    +

    Object Functions

    -
    _.clone = (obj) ->
    -  return obj.slice 0 if _.isArray obj
    -  _.extend {}, obj
    - @@ -1106,15 +1088,9 @@ consuming the return value of the function that follows.

    -

    Invokes interceptor with the obj, and then returns obj. -The primary purpose of this method is to "tap into" a method chain, in order to perform operations on intermediate results within the chain.

    - + -
    _.tap = (obj, interceptor) ->
    -  interceptor obj
    -  obj
    - @@ -1124,11 +1100,13 @@ The primary purpose of this method is to "tap into" a method chain, in
    -

    Perform a deep comparison to check if two objects are equal.

    +

    Retrieve the names of an object’s properties.

    -
    _.isEqual = (a, b) ->
    +
    _.keys = nativeKeys or (obj) ->
    +  return _.range 0, obj.length if _.isArray(obj)
    +  key for key, val of obj
    @@ -1139,11 +1117,12 @@ The primary purpose of this method is to "tap into" a method chain, in
    -

    Check object identity.

    +

    Retrieve the values of an object’s properties.

    -
      return true if a is b
    +
    _.values = (obj) ->
    +  _.map obj, _.identity
    @@ -1154,12 +1133,15 @@ The primary purpose of this method is to "tap into" a method chain, in
    -

    Different types?

    +

    Return a sorted list of the function names available in Underscore.

    -
      atype = typeof(a); btype = typeof(b)
    -  return false if atype isnt btype
    +
    _.functions = (obj) ->
    +  _.filter(_.keys(obj), (key) -> _.isFunction(obj[key])).sort()
    +
    +
    +
    @@ -1170,11 +1152,14 @@ The primary purpose of this method is to "tap into" a method chain, in
    -

    Basic equality test (watch out for coercions).

    +

    Extend a given object with all of the properties in a source object.

    -
      return true if `a == b`
    +
    _.extend = (obj) ->
    +  for source in _.rest(arguments)
    +    obj[key] = val for key, val of source
    +  obj
    @@ -1185,11 +1170,13 @@ The primary purpose of this method is to "tap into" a method chain, in
    -

    One is falsy and the other truthy.

    +

    Create a (shallow-cloned) duplicate of an object.

    -
      return false if (!a and b) or (a and !b)
    +
    _.clone = (obj) ->
    +  return obj.slice 0 if _.isArray obj
    +  _.extend {}, obj
    @@ -1200,11 +1187,14 @@ The primary purpose of this method is to "tap into" a method chain, in
    -

    One of them implements an isEqual()?

    +

    Invokes interceptor with the obj, and then returns obj. +The primary purpose of this method is to “tap into” a method chain, in order to perform operations on intermediate results within the chain.

    -
      return a.isEqual(b) if a.isEqual
    +
    _.tap = (obj, interceptor) ->
    +  interceptor obj
    +  obj
    @@ -1215,11 +1205,11 @@ The primary purpose of this method is to "tap into" a method chain, in
    -

    Check dates' integer values.

    +

    Perform a deep comparison to check if two objects are equal.

    -
      return a.getTime() is b.getTime() if _.isDate(a) and _.isDate(b)
    +
    _.isEqual = (a, b) ->
    @@ -1230,11 +1220,11 @@ The primary purpose of this method is to "tap into" a method chain, in
    -

    Both are NaN?

    +

    Check object identity.

    -
      return false if _.isNaN(a) and _.isNaN(b)
    +
      return true if a is b
    @@ -1245,15 +1235,12 @@ The primary purpose of this method is to "tap into" a method chain, in
    -

    Compare regular expressions.

    +

    Different types?

    -
      if _.isRegExp(a) and _.isRegExp(b)
    -    return a.source     is b.source and
    -           a.global     is b.global and
    -           a.ignoreCase is b.ignoreCase and
    -           a.multiline  is b.multiline
    +
      atype = typeof(a); btype = typeof(b)
    +  return false if atype isnt btype
    @@ -1264,11 +1251,11 @@ The primary purpose of this method is to "tap into" a method chain, in
    -

    If a is not an object by this point, we can't handle it.

    +

    Basic equality test (watch out for coercions).

    -
      return false if atype isnt 'object'
    +
      return true if `a == b`
    @@ -1279,11 +1266,11 @@ The primary purpose of this method is to "tap into" a method chain, in
    -

    Check for different array lengths before comparing contents.

    +

    One is falsy and the other truthy.

    -
      return false if a.length and (a.length isnt b.length)
    +
      return false if (!a and b) or (a and !b)
    @@ -1294,11 +1281,11 @@ The primary purpose of this method is to "tap into" a method chain, in
    -

    Nothing else worked, deep compare the contents.

    +

    One of them implements an isEqual()?

    -
      aKeys = _.keys(a); bKeys = _.keys(b)
    +
      return a.isEqual(b) if a.isEqual
    @@ -1309,11 +1296,11 @@ The primary purpose of this method is to "tap into" a method chain, in
    -

    Different object sizes?

    +

    Check dates’ integer values.

    -
      return false if aKeys.length isnt bKeys.length
    +
      return a.getTime() is b.getTime() if _.isDate(a) and _.isDate(b)
    @@ -1324,12 +1311,11 @@ The primary purpose of this method is to "tap into" a method chain, in
    -

    Recursive comparison of contents.

    +

    Both are NaN?

    -
      return false for key, val of a when !(key of b) or !_.isEqual(val, b[key])
    -  true
    +
      return false if _.isNaN(a) and _.isNaN(b)
    @@ -1340,14 +1326,15 @@ The primary purpose of this method is to "tap into" a method chain, in
    -

    Is a given array or object empty?

    +

    Compare regular expressions.

    -
    _.isEmpty = (obj) ->
    -  return obj.length is 0 if _.isArray(obj) or _.isString(obj)
    -  return false for own key of obj
    -  true
    +
      if _.isRegExp(a) and _.isRegExp(b)
    +    return a.source     is b.source and
    +           a.global     is b.global and
    +           a.ignoreCase is b.ignoreCase and
    +           a.multiline  is b.multiline
    @@ -1358,11 +1345,11 @@ The primary purpose of this method is to "tap into" a method chain, in
    -

    Is a given value a DOM element?

    +

    If a is not an object by this point, we can’t handle it.

    -
    _.isElement   = (obj) -> obj and obj.nodeType is 1
    +
      return false if atype isnt 'object'
    @@ -1373,11 +1360,11 @@ The primary purpose of this method is to "tap into" a method chain, in
    -

    Is a given value an array?

    +

    Check for different array lengths before comparing contents.

    -
    _.isArray     = nativeIsArray or (obj) -> !!(obj and obj.concat and obj.unshift and not obj.callee)
    +
      return false if a.length and (a.length isnt b.length)
    @@ -1388,11 +1375,11 @@ The primary purpose of this method is to "tap into" a method chain, in
    -

    Is a given variable an arguments object?

    +

    Nothing else worked, deep compare the contents.

    -
    _.isArguments = (obj) -> obj and obj.callee
    +
      aKeys = _.keys(a); bKeys = _.keys(b)
    @@ -1403,11 +1390,11 @@ The primary purpose of this method is to "tap into" a method chain, in
    -

    Is the given value a function?

    +

    Different object sizes?

    -
    _.isFunction  = (obj) -> !!(obj and obj.constructor and obj.call and obj.apply)
    +
      return false if aKeys.length isnt bKeys.length
    @@ -1418,11 +1405,12 @@ The primary purpose of this method is to "tap into" a method chain, in
    -

    Is the given value a string?

    +

    Recursive comparison of contents.

    -
    _.isString    = (obj) -> !!(obj is '' or (obj and obj.charCodeAt and obj.substr))
    +
      return false for key, val of a when !(key of b) or !_.isEqual(val, b[key])
    +  true
    @@ -1433,11 +1421,14 @@ The primary purpose of this method is to "tap into" a method chain, in
    -

    Is a given value a number?

    +

    Is a given array or object empty?

    -
    _.isNumber    = (obj) -> (obj is +obj) or toString.call(obj) is '[object Number]'
    +
    _.isEmpty = (obj) ->
    +  return obj.length is 0 if _.isArray(obj) or _.isString(obj)
    +  return false for own key of obj
    +  true
    @@ -1448,11 +1439,11 @@ The primary purpose of this method is to "tap into" a method chain, in
    -

    Is a given value a boolean?

    +

    Is a given value a DOM element?

    -
    _.isBoolean   = (obj) -> obj is true or obj is false
    +
    _.isElement   = (obj) -> obj and obj.nodeType is 1
    @@ -1463,11 +1454,11 @@ The primary purpose of this method is to "tap into" a method chain, in
    -

    Is a given value a Date?

    +

    Is a given value an array?

    -
    _.isDate      = (obj) -> !!(obj and obj.getTimezoneOffset and obj.setUTCFullYear)
    +
    _.isArray     = nativeIsArray or (obj) -> !!(obj and obj.concat and obj.unshift and not obj.callee)
    @@ -1478,11 +1469,11 @@ The primary purpose of this method is to "tap into" a method chain, in
    -

    Is the given value a regular expression?

    +

    Is a given variable an arguments object?

    -
    _.isRegExp    = (obj) -> !!(obj and obj.exec and (obj.ignoreCase or obj.ignoreCase is false))
    +
    _.isArguments = (obj) -> obj and obj.callee
    @@ -1493,12 +1484,11 @@ The primary purpose of this method is to "tap into" a method chain, in
    -

    Is the given value NaN -- this one is interesting. NaN != NaN, and -isNaN(undefined) == true, so we make sure it's a number first.

    +

    Is the given value a function?

    -
    _.isNaN       = (obj) -> _.isNumber(obj) and window.isNaN(obj)
    +
    _.isFunction  = (obj) -> !!(obj and obj.constructor and obj.call and obj.apply)
    @@ -1509,11 +1499,11 @@ The primary purpose of this method is to "tap into" a method chain, in
    -

    Is a given value equal to null?

    +

    Is the given value a string?

    -
    _.isNull      = (obj) -> obj is null
    +
    _.isString    = (obj) -> !!(obj is '' or (obj and obj.charCodeAt and obj.substr))
    @@ -1524,11 +1514,11 @@ The primary purpose of this method is to "tap into" a method chain, in
    -

    Is a given variable undefined?

    +

    Is a given value a number?

    -
    _.isUndefined = (obj) -> typeof obj is 'undefined'
    +
    _.isNumber    = (obj) -> (obj is +obj) or toString.call(obj) is '[object Number]'
    @@ -1536,13 +1526,15 @@ The primary purpose of this method is to "tap into" a method chain, in
  • -
    +
    -

    Utility Functions

    +

    Is a given value a boolean?

    +
    _.isBoolean   = (obj) -> obj is true or obj is false
    +
  • @@ -1552,14 +1544,11 @@ The primary purpose of this method is to "tap into" a method chain, in
    -

    Run Underscore.js in noConflict mode, returning the _ variable to its -previous owner. Returns a reference to the Underscore object.

    +

    Is a given value a Date?

    -
    _.noConflict = ->
    -  root._ = previousUnderscore
    -  this
    +
    _.isDate      = (obj) -> !!(obj and obj.getTimezoneOffset and obj.setUTCFullYear)
    @@ -1570,11 +1559,11 @@ previous owner. Returns a reference to the Underscore object.

    -

    Keep the identity function around for default iterators.

    +

    Is the given value a regular expression?

    -
    _.identity = (value) -> value
    +
    _.isRegExp    = (obj) -> !!(obj and obj.exec and (obj.ignoreCase or obj.ignoreCase is false))
    @@ -1585,12 +1574,12 @@ previous owner. Returns a reference to the Underscore object.

    -

    Run a function n times.

    +

    Is the given value NaN — this one is interesting. NaN != NaN, and +isNaN(undefined) == true, so we make sure it’s a number first.

    -
    _.times = (n, iterator, context) ->
    -  iterator.call context, i for i in [0...n]
    +
    _.isNaN       = (obj) -> _.isNumber(obj) and window.isNaN(obj)
    @@ -1601,11 +1590,11 @@ previous owner. Returns a reference to the Underscore object.

    -

    Break out of the middle of an iteration.

    +

    Is a given value equal to null?

    -
    _.breakLoop = -> throw breaker
    +
    _.isNull      = (obj) -> obj is null
    @@ -1616,14 +1605,11 @@ previous owner. Returns a reference to the Underscore object.

    -

    Add your own custom functions to the Underscore object, ensuring that -they're correctly added to the OOP wrapper as well.

    +

    Is a given variable undefined?

    -
    _.mixin = (obj) ->
    -  for name in _.functions(obj)
    -    addToWrapper name, _[name] = obj[name]
    +
    _.isUndefined = (obj) -> typeof obj is 'undefined'
    @@ -1634,15 +1620,10 @@ they're correctly added to the OOP wrapper as well.

    -

    Generate a unique integer id (unique within the entire client session). -Useful for temporary DOM ids.

    +

    Utility Functions

    -
    idCounter = 0
    -_.uniqueId = (prefix) ->
    -  (prefix or '') + idCounter++
    - @@ -1652,17 +1633,9 @@ _.uniqueId = (prefix) -
    -

    By default, Underscore uses ERB-style template delimiters, change the -following template settings to use alternative delimiters.

    - + -
    _.templateSettings = {
    -  start:        '<%'
    -  end:          '%>'
    -  interpolate:  /<%=(.+?)%>/g
    -}
    - @@ -1672,30 +1645,14 @@ following template settings to use alternative delimiters.

    -

    JavaScript templating a-la ERB, pilfered from John Resig's -Secrets of the JavaScript Ninja, page 83. -Single-quote fix from Rick Strahl. -With alterations for arbitrary delimiters, and to preserve whitespace.

    +

    Run Underscore.js in noConflict mode, returning the _ variable to its +previous owner. Returns a reference to the Underscore object.

    -
    _.template = (str, data) ->
    -  c = _.templateSettings
    -  endMatch = new RegExp("'(?=[^"+c.end.substr(0, 1)+"]*"+escapeRegExp(c.end)+")","g")
    -  fn = new Function 'obj',
    -    'var p=[],print=function(){p.push.apply(p,arguments);};' +
    -    'with(obj||{}){p.push(\'' +
    -    str.replace(/\r/g, '\\r')
    -       .replace(/\n/g, '\\n')
    -       .replace(/\t/g, '\\t')
    -       .replace(endMatch,"✄")
    -       .split("'").join("\\'")
    -       .split("✄").join("'")
    -       .replace(c.interpolate, "',$1,'")
    -       .split(c.start).join("');")
    -       .split(c.end).join("p.push('") +
    -       "');}return p.join('');"
    -  if data then fn(data) else fn
    +
    _.noConflict = ->
    +  root._ = previousUnderscore
    +  this
    @@ -1703,13 +1660,15 @@ With alterations for arbitrary delimiters, and to preserve whitespace.

  • -
    +
    -

    Aliases

    +

    Keep the identity function around for default iterators.

    +
    _.identity = (value) -> value
    +
  • @@ -1719,10 +1678,145 @@ With alterations for arbitrary delimiters, and to preserve whitespace.

    +

    Run a function n times.

    + + + +
    _.times = (n, iterator, context) ->
    +  iterator.call context, i for i in [0...n]
    + + + + +
  • +
    + +
    + +
    +

    Break out of the middle of an iteration.

    + +
    + +
    _.breakLoop = -> throw breaker
    + +
  • + + +
  • +
    + +
    + +
    +

    Add your own custom functions to the Underscore object, ensuring that +they’re correctly added to the OOP wrapper as well.

    + +
    + +
    _.mixin = (obj) ->
    +  for name in _.functions(obj)
    +    addToWrapper name, _[name] = obj[name]
    + +
  • + + +
  • +
    + +
    + +
    +

    Generate a unique integer id (unique within the entire client session). +Useful for temporary DOM ids.

    + +
    + +
    idCounter = 0
    +_.uniqueId = (prefix) ->
    +  (prefix or '') + idCounter++
    + +
  • + + +
  • +
    + +
    + +
    +

    By default, Underscore uses ERB-style template delimiters, change the +following template settings to use alternative delimiters.

    + +
    + +
    _.templateSettings = {
    +  start:        '<%'
    +  end:          '%>'
    +  interpolate:  /<%=(.+?)%>/g
    +}
    + +
  • + + +
  • +
    + +
    + +
    +

    JavaScript templating a-la ERB, pilfered from John Resig’s +Secrets of the JavaScript Ninja, page 83. +Single-quote fix from Rick Strahl. +With alterations for arbitrary delimiters, and to preserve whitespace.

    + +
    + +
    _.template = (str, data) ->
    +  c = _.templateSettings
    +  endMatch = new RegExp("'(?=[^"+c.end.substr(0, 1)+"]*"+escapeRegExp(c.end)+")","g")
    +  fn = new Function 'obj',
    +    'var p=[],print=function(){p.push.apply(p,arguments);};' +
    +    'with(obj||{}){p.push(\'' +
    +    str.replace(/\r/g, '\\r')
    +       .replace(/\n/g, '\\n')
    +       .replace(/\t/g, '\\t')
    +       .replace(endMatch,"✄")
    +       .split("'").join("\\'")
    +       .split("✄").join("'")
    +       .replace(c.interpolate, "',$1,'")
    +       .split(c.start).join("');")
    +       .split(c.end).join("p.push('") +
    +       "');}return p.join('');"
    +  if data then fn(data) else fn
    + +
  • + + +
  • +
    + +
    + +
    +

    Aliases

    + +
    + +
  • + + +
  • +
    + +
    + +
    -
    _.forEach  = _.each
    +            
    +_.forEach  = _.each
     _.foldl    = _.inject = _.reduce
     _.foldr    = _.reduceRight
     _.select   = _.filter
    @@ -1736,139 +1830,16 @@ _.methods  = _.functions
  • -
  • -
    - -
    - -
    -

    Setup the OOP Wrapper

    - -
    - -
  • - - -
  • -
    - -
    - -
    -

    If Underscore is called as a function, it returns a wrapped object that -can be used OO-style. This wrapper holds altered versions of all the -underscore functions. Wrapped objects may be chained.

    - -
    - -
    wrapper = (obj) ->
    -  this._wrapped = obj
    -  this
    - -
  • - - -
  • -
    - -
    - -
    -

    Helper function to continue chaining intermediate results.

    - -
    - -
    result = (obj, chain) ->
    -  if chain then _(obj).chain() else obj
    - -
  • - - -
  • -
    - -
    - -
    -

    A method to easily add functions to the OOP wrapper.

    - -
    - -
    addToWrapper = (name, func) ->
    -  wrapper.prototype[name] = ->
    -    args = _.toArray arguments
    -    unshift.call args, this._wrapped
    -    result func.apply(_, args), this._chain
    - -
  • - - -
  • -
    - -
    - -
    -

    Add all ofthe Underscore functions to the wrapper object.

    - -
    - -
    _.mixin _
    - -
  • - - -
  • -
    - -
    - -
    -

    Add all mutator Array functions to the wrapper.

    - -
    - -
    _.each ['pop', 'push', 'reverse', 'shift', 'sort', 'splice', 'unshift'], (name) ->
    -  method = Array.prototype[name]
    -  wrapper.prototype[name] = ->
    -    method.apply(this._wrapped, arguments)
    -    result(this._wrapped, this._chain)
    - -
  • - - -
  • -
    - -
    - -
    -

    Add all accessor Array functions to the wrapper.

    - -
    - -
    _.each ['concat', 'join', 'slice'], (name) ->
    -  method = Array.prototype[name]
    -  wrapper.prototype[name] = ->
    -    result(method.apply(this._wrapped, arguments), this._chain)
    - -
  • - -
  • -

    Start chaining a wrapped Underscore object.

    +

    Setup the OOP Wrapper

    -
    wrapper::chain = ->
    -  this._chain = true
    -  this
    -
  • @@ -1878,11 +1849,146 @@ underscore functions. Wrapped objects may be chained.

    + + + + + + +
  • +
    + +
    + +
    +

    If Underscore is called as a function, it returns a wrapped object that +can be used OO-style. This wrapper holds altered versions of all the +underscore functions. Wrapped objects may be chained.

    + +
    + +
    wrapper = (obj) ->
    +  this._wrapped = obj
    +  this
    + +
  • + + +
  • +
    + +
    + +
    +

    Helper function to continue chaining intermediate results.

    + +
    + +
    result = (obj, chain) ->
    +  if chain then _(obj).chain() else obj
    + +
  • + + +
  • +
    + +
    + +
    +

    A method to easily add functions to the OOP wrapper.

    + +
    + +
    addToWrapper = (name, func) ->
    +  wrapper.prototype[name] = ->
    +    args = _.toArray arguments
    +    unshift.call args, this._wrapped
    +    result func.apply(_, args), this._chain
    + +
  • + + +
  • +
    + +
    + +
    +

    Add all ofthe Underscore functions to the wrapper object.

    + +
    + +
    _.mixin _
    + +
  • + + +
  • +
    + +
    + +
    +

    Add all mutator Array functions to the wrapper.

    + +
    + +
    _.each ['pop', 'push', 'reverse', 'shift', 'sort', 'splice', 'unshift'], (name) ->
    +  method = Array.prototype[name]
    +  wrapper.prototype[name] = ->
    +    method.apply(this._wrapped, arguments)
    +    result(this._wrapped, this._chain)
    + +
  • + + +
  • +
    + +
    + +
    +

    Add all accessor Array functions to the wrapper.

    + +
    + +
    _.each ['concat', 'join', 'slice'], (name) ->
    +  method = Array.prototype[name]
    +  wrapper.prototype[name] = ->
    +    result(method.apply(this._wrapped, arguments), this._chain)
    + +
  • + + +
  • +
    + +
    + +
    +

    Start chaining a wrapped Underscore object.

    + +
    + +
    wrapper::chain = ->
    +  this._chain = true
    +  this
    + +
  • + + +
  • +
    + +
    + +

    Extracts the result from a wrapped and chained object.

    -
    wrapper::value = -> this._wrapped
    +
    wrapper::value = -> this._wrapped
  • diff --git a/index.html b/index.html index 99845ae8..3ad536ab 100644 --- a/index.html +++ b/index.html @@ -87,7 +87,6 @@ Source Maps — src/sourcemap -
    @@ -114,8 +113,7 @@ 1.7.1

    -
    -sudo npm install -g coffee-script
    +
    npm install -g coffee-script

    @@ -261,27 +259,30 @@ cubes = (function() {

    To install, first make sure you have a working copy of the latest stable version of Node.js, and npm - (the Node Package Manager). You can then install CoffeeScript with npm: + (the Node Package Manager). You can then install CoffeeScript globally with npm:

     npm install -g coffee-script

    - (Leave off the -g if you don't wish to install globally.) + When you need CoffeeScript as a dependency, install it locally:

    +
    +npm install --save coffee-script
    +

    If you'd prefer to install the latest master version of CoffeeScript, you can clone the CoffeeScript source repository from GitHub, or download the source directly. - To install the lastest master CoffeeScript compiler with npm: + To install the latest master CoffeeScript compiler with npm:

    -npm install -g http://github.com/jashkenas/coffeescript/tarball/master
    +npm install -g jashkenas/coffeescript

    Or, if you want to install to /usr/local, and don't want to use @@ -1742,7 +1743,7 @@ futurists = { }; _ref = futurists.poet, name = _ref.name, (_ref1 = _ref.address, street = _ref1[0], city = _ref1[1]); -;alert("name + "-" + street");'>run: "name + "-" + street"


    +;alert(name + "-" + street);'>run: name + "-" + street

    Destructuring assignment can even be combined with splats.

    @@ -1788,7 +1789,7 @@ _ref = text.split(" "), first = _ref[run: "first + " " + last"
    +;alert(first + " " + last);'>run: first + " " + last

    Destructuring assignment is also useful when combined with class constructors to assign properties to your instance from an options object passed to the constructor. @@ -2339,7 +2340,7 @@ task('build:parser', 'rebuild t

    - The best list of + The best list of open-source CoffeeScript examples can be found on GitHub. But just to throw out few more:

    @@ -2449,10 +2450,11 @@ task('build:parser', 'rebuild t

    - - 1.7.1 - January 29, 2014 - +

    + + 1.7.1 + +
    • Fixed a typo that broke node module lookup when running a script directly with the coffee binary. @@ -2460,10 +2462,11 @@ task('build:parser', 'rebuild t

    - - 1.7.0 - January 28, 2014 - +

    + + 1.7.0 + +
    • When requiring CoffeeScript files in Node you must now explicitly register the compiler. This can be done with require 'coffee-script/register' or CoffeeScript.register(). Also for configuration such as Mocha's, use coffee-script/register. @@ -2498,7 +2501,7 @@ task('build:parser', 'rebuild t Closing brackets can now be indented and therefore no longer cause unexpected error.
    • - Several breaking compilation fixes. Non-callable literals (strings, numbers etc.) don't compile in a call now and multiple postfix conditionals compile properly. Postfix conditionals and loops always bind object literals. Conditional assignment compiles properly in subexpressions. super is disallowed outside of methods and works correctly inside for loops. + Several breaking compilation fixes. Non-callable literals (strings, numbers etc.) don't compile in a call now and multiple postfix conditionals compile properly. Postfix conditionals and loops always bind object literals. Conditional assignment compiles properly in subexpressions. super is disallowed outside of methods and works correctly inside for loops.
    • Formatting of compiled block comments has been improved. @@ -2512,10 +2515,11 @@ task('build:parser', 'rebuild t

    - - 1.6.3 - June 2, 2013 - +

    + + 1.6.3 + +
    • The CoffeeScript REPL now remembers your history between sessions. @@ -2541,10 +2545,11 @@ task('build:parser', 'rebuild t

      - - 1.6.2 - March 18, 2013 - +

      + + 1.6.2 + +
      • Source maps have been used to provide automatic line-mapping when @@ -2570,10 +2575,11 @@ task('build:parser', 'rebuild t

        - - 1.6.1 - March 5, 2013 - +

        + + 1.6.1 + +
        • First release of source maps. Pass the @@ -2599,10 +2605,11 @@ task('build:parser', 'rebuild t

          - - 1.5.0 - Feb 25, 2013 - +

          + + 1.5.0 + +
          • First release of Literate CoffeeScript. @@ -2627,10 +2634,11 @@ task('build:parser', 'rebuild t

            - - 1.4.0 - Oct 23, 2012 - +

            + + 1.4.0 + +
            • The CoffeeScript compiler now strips Microsoft's UTF-8 BOM if it @@ -2648,10 +2656,11 @@ task('build:parser', 'rebuild t

              - - 1.3.3 - May 15, 2012 - +

              + + 1.3.3 + +
              • Due to the new semantics of JavaScript's strict mode, CoffeeScript no @@ -2677,10 +2686,11 @@ task('build:parser', 'rebuild t

                - - 1.3.1 - April 10, 2012 - +

                + + 1.3.1 + +
                • CoffeeScript now enforces all of JavaScript's Strict Mode early syntax @@ -2727,10 +2737,11 @@ task('build:parser', 'rebuild t

                  - - 1.2.0 - Dec. 18, 2011 - +

                  + + 1.2.0 + +
                  • Multiple improvements to coffee --watch and --join. @@ -2754,10 +2765,11 @@ task('build:parser', 'rebuild t

                    - - 1.1.3 - Nov. 8, 2011 - +

                    + + 1.1.3 + +
                    • Ahh, whitespace. CoffeeScript's compiled JS now tries to space things @@ -2797,10 +2809,11 @@ task('build:parser', 'rebuild t

                      - - 1.1.2 - August 4, 2011 - +

                      + + 1.1.2 + + Fixes for block comment formatting, ?= compilation, implicit calls against control structures, implicit invocation of a try/catch block, variadic arguments leaking from local scope, line numbers in syntax errors @@ -2811,17 +2824,21 @@ task('build:parser', 'rebuild t

                      - 1.1.1 - May 10, 2011 - +

                      + + 1.1.1 + + Bugfix release for classes with external constructor functions, see issue #1182.

                      - 1.1.0 - May 1, 2011 - +

                      + + 1.1.0 + + When running via the coffee executable, process.argv and friends now report coffee instead of node. Better compatibility with Node.js 0.4.x module lookup changes. @@ -2837,9 +2854,11 @@ task('build:parser', 'rebuild t

                      - 1.0.1 - Jan 31, 2011 - +

                      + + 1.0.1 + + Fixed a lexer bug with Unicode identifiers. Updated REPL for compatibility with Node.js 0.3.7. Fixed requiring relative paths in the REPL. Trailing return and return undefined are now optimized away. @@ -2850,9 +2869,11 @@ task('build:parser', 'rebuild t

                      - 1.0.0 - Dec 24, 2010 - +

                      + + 1.0.0 + + CoffeeScript loops no longer try to preserve block scope when functions are being generated within the loop body. Instead, you can use the do keyword to create a convenient closure wrapper. @@ -2864,9 +2885,11 @@ task('build:parser', 'rebuild t

                      - 0.9.6 - Dec 6, 2010 - +

                      + + 0.9.6 + + The REPL now properly formats stacktraces, and stays alive through asynchronous exceptions. Using --watch now prints timestamps as files are compiled. Fixed some accidentally-leaking variables within @@ -2878,9 +2901,11 @@ task('build:parser', 'rebuild t

                      - 0.9.5 - Nov 21, 2010 - +

                      + + 0.9.5 + + 0.9.5 should be considered the first release candidate for CoffeeScript 1.0. There have been a large number of internal changes since the previous release, many contributed from satyr's Coco @@ -2894,9 +2919,11 @@ task('build:parser', 'rebuild t

                      - 0.9.4 - Sep 21, 2010 - +

                      + + 0.9.4 + + CoffeeScript now uses appropriately-named temporary variables, and recycles their references after use. Added require.extensions support for Node.js 0.3. Loading CoffeeScript in the browser now adds just a @@ -2905,9 +2932,11 @@ task('build:parser', 'rebuild t

                      - 0.9.3 - Sep 16, 2010 - +

                      + + 0.9.3 + + CoffeeScript switch statements now compile into JS switch statements — they previously compiled into if/else chains for JavaScript 1.3 compatibility. @@ -2916,9 +2945,11 @@ task('build:parser', 'rebuild t

                      - 0.9.2 - Aug 23, 2010 - +

                      + + 0.9.2 + + Specifying the start and end of a range literal is now optional, eg. array[3..]. You can now say a not instanceof b. Fixed important bugs with nested significant and non-significant indentation (Issue #637). @@ -2932,9 +2963,11 @@ task('build:parser', 'rebuild t

                      - 0.9.1 - Aug 11, 2010 - +

                      + + 0.9.1 + + Bugfix release for 0.9.1. Greatly improves the handling of mixed implicit objects, implicit function calls, and implicit indentation. String and regex interpolation is now strictly #{ ... } (Ruby style). @@ -2943,9 +2976,11 @@ task('build:parser', 'rebuild t

                      - 0.9.0 - Aug 4, 2010 - +

                      + + 0.9.0 + + The CoffeeScript 0.9 series is considered to be a release candidate for 1.0; let's give her a shakedown cruise. 0.9.0 introduces a massive backwards-incompatible change: Assignment now uses =, and object @@ -2969,17 +3004,21 @@ task('build:parser', 'rebuild t

                      - 0.7.2 - Jul 12, 2010 - +

                      + + 0.7.2 + + Quick bugfix (right after 0.7.1) for a problem that prevented coffee command-line options from being parsed in some circumstances.

                      - 0.7.1 - Jul 11, 2010 - +

                      + + 0.7.1 + + Block-style comments are now passed through and printed as JavaScript block comments -- making them useful for licenses and copyright headers. Better support for running coffee scripts standalone via hashbangs. @@ -2987,9 +3026,11 @@ task('build:parser', 'rebuild t

                      - 0.7.0 - Jun 28, 2010 - +

                      + + 0.7.0 + + Official CoffeeScript variable style is now camelCase, as in JavaScript. Reserved words are now allowed as object keys, and will be quoted for you. Range comprehensions now generate cleaner code, but you have to specify by -1 @@ -3006,9 +3047,11 @@ task('build:parser', 'rebuild t

                      - 0.6.2 - May 15, 2010 - +

                      + + 0.6.2 + + The coffee command will now preserve directory structure when compiling a directory full of scripts. Fixed two omissions that were preventing the CoffeeScript compiler from running live within Internet Explorer. @@ -3023,26 +3066,32 @@ task('build:parser', 'rebuild t

                      - 0.6.1 - Apr 12, 2010 - +

                      + + 0.6.1 + + Upgraded CoffeeScript for compatibility with the new Node.js v0.1.90 series.

                      - 0.6.0 - Apr 3, 2010 - +

                      + + 0.6.0 + + Trailing commas are now allowed, a-la Python. Static properties may be assigned directly within class definitions, using @property notation.

                      - 0.5.6 - Mar 23, 2010 - +

                      + + 0.5.6 + + Interpolation can now be used within regular expressions and heredocs, as well as strings. Added the <- bind operator. Allowing assignment to half-expressions instead of special ||=-style @@ -3053,9 +3102,11 @@ task('build:parser', 'rebuild t

                      - 0.5.5 - Mar 8, 2010 - +

                      + + 0.5.5 + + String interpolation, contributed by Stan Angeloff. Since --run has been the default since 0.5.3, updating @@ -3064,18 +3115,22 @@ task('build:parser', 'rebuild t

                      - 0.5.4 - Mar 3, 2010 - +

                      + + 0.5.4 + + Bugfix that corrects the Node.js global constants __filename and __dirname. Tweaks for more flexible parsing of nested function literals and improperly-indented comments. Updates for the latest Node.js API.

                      - 0.5.3 - Feb 27, 2010 - +

                      + + 0.5.3 + + CoffeeScript now has a syntax for defining classes. Many of the core components (Nodes, Lexer, Rewriter, Scope, Optparse) are using them. Cakefiles can use optparse.coffee to define options for tasks. @@ -3085,9 +3140,11 @@ task('build:parser', 'rebuild t

                      - 0.5.2 - Feb 25, 2010 - +

                      + + 0.5.2 + + Added a compressed version of the compiler for inclusion in web pages as
                      extras/coffee-script.js. It'll automatically run any script tags with type text/coffeescript for you. Added a --stdio option @@ -3096,9 +3153,11 @@ task('build:parser', 'rebuild t

                      - 0.5.1 - Feb 24, 2010 - +

                      + + 0.5.1 + + Improvements to null soaking with the existential operator, including soaks on indexed properties. Added conditions to while loops, so you can use them as filters with when, in the same manner as @@ -3106,27 +3165,33 @@ task('build:parser', 'rebuild t

                      - 0.5.0 - Feb 21, 2010 - +

                      + + 0.5.0 + + CoffeeScript 0.5.0 is a major release, While there are no language changes, the Ruby compiler has been removed in favor of a self-hosting compiler written in pure CoffeeScript.

                      - 0.3.2 - Feb 8, 2010 - +

                      + + 0.3.2 + + @property is now a shorthand for this.property.
                      Switched the default JavaScript engine from Narwhal to Node.js. Pass the --narwhal flag if you'd like to continue using it.

                      - 0.3.0 - Jan 26, 2010 - +

                      + + 0.3.0 + + CoffeeScript 0.3 includes major syntax changes:
                      The function symbol was changed to @@ -3142,9 +3207,11 @@ task('build:parser', 'rebuild t

                      - 0.2.6 - Jan 17, 2010 - +

                      + + 0.2.6 + + Added Python-style chained comparisons, the conditional existence operator ?=, and some examples from Beautiful Code. Bugfixes relating to statement-to-expression conversion, arguments-to-array @@ -3152,9 +3219,11 @@ task('build:parser', 'rebuild t

                      - 0.2.5 - Jan 13, 2010 - +

                      + + 0.2.5 + + The conditions in switch statements can now take multiple values at once — If any of them are true, the case will run. Added the long arrow ==>, which defines and immediately binds a function to this. While loops can @@ -3163,26 +3232,32 @@ task('build:parser', 'rebuild t

                      - 0.2.4 - Jan 12, 2010 - +

                      + + 0.2.4 + + Added ECMAScript Harmony style destructuring assignment, for dealing with extracting values from nested arrays and objects. Added indentation-sensitive heredocs for nicely formatted strings or chunks of code.

                      - 0.2.3 - Jan 11, 2010 - +

                      + + 0.2.3 + + Axed the unsatisfactory ino keyword, replacing it with of for object comprehensions. They now look like: for prop, value of object.

                      - 0.2.2 - Jan 10, 2010 - +

                      + + 0.2.2 + + When performing a comprehension over an object, use ino, instead of in, which helps us generate smaller, more efficient code at compile time. @@ -3203,16 +3278,20 @@ task('build:parser', 'rebuild t

                      - 0.2.1 - Jan 5, 2010 - +

                      + + 0.2.1 + + Arguments objects are now converted into real arrays when referenced.

                      - 0.2.0 - Jan 5, 2010 - +

                      + + 0.2.0 + + Major release. Significant whitespace. Better statement-to-expression conversion. Splats. Splice literals. Object comprehensions. Blocks. The existential operator. Many thanks to all the folks who posted issues, @@ -3222,18 +3301,22 @@ task('build:parser', 'rebuild t

                      - 0.1.6 - Dec 27, 2009 - +

                      + + 0.1.6 + + Bugfix for running coffee --interactive and --run from outside of the CoffeeScript directory. Bugfix for nested function/if-statements.

                      - 0.1.5 - Dec 26, 2009 - +

                      + + 0.1.5 + + Array slice literals and array comprehensions can now both take Ruby-style ranges to specify the start and end. JavaScript variable declaration is now pushed up to the top of the scope, making all assignment statements into @@ -3242,9 +3325,11 @@ task('build:parser', 'rebuild t

                      - 0.1.4 - Dec 25, 2009 - +

                      + + 0.1.4 + + The official CoffeeScript extension is now .coffee instead of .cs, which properly belongs to C#. @@ -3256,9 +3341,11 @@ task('build:parser', 'rebuild t

                      - 0.1.3 - Dec 25, 2009 - +

                      + + 0.1.3 + + The coffee command now includes --interactive, which launches an interactive CoffeeScript session, and --run, which directly compiles and executes a script. Both options depend on a @@ -3272,9 +3359,11 @@ task('build:parser', 'rebuild t

                      - 0.1.2 - Dec 24, 2009 - +

                      + + 0.1.2 + + Fixed a bug with calling super() through more than one level of inheritance, with the re-addition of the extends keyword. Added experimental Narwhal @@ -3286,16 +3375,20 @@ task('build:parser', 'rebuild t

                      - 0.1.1 - Dec 24, 2009 - +

                      + + 0.1.1 + + Added instanceof and typeof as operators.

                      - 0.1.0 - Dec 24, 2009 - +

                      + + 0.1.0 + + Initial CoffeeScript release.

                      @@ -3307,19 +3400,22 @@ task('build:parser', 'rebuild t # Set up the compilation function, to run when you stop typing. compileSource = -> source = $('#repl_source').val() + results = $('#repl_results') window.compiledJS = '' try window.compiledJS = CoffeeScript.compile source, bare: on - el = $('#repl_results')[0] + el = results[0] if el.innerText el.innerText = window.compiledJS else - $(el).text window.compiledJS - $('#error').hide() + results.text(window.compiledJS) + results.removeClass 'error' + $('.minibutton.run').removeClass 'error' catch {location, message} if location? message = "Error on line #{location.first_line + 1}: #{message}" - $('#error').text(message).show() + results.text(message).addClass 'error' + $('.minibutton.run').addClass 'error' # Update permalink $('#repl_permalink').attr 'href', "##{sourceFragment}#{encodeURIComponent source}"