diff --git a/Cakefile b/Cakefile index d276c4e942..a1d7c3d479 100644 --- a/Cakefile +++ b/Cakefile @@ -146,14 +146,14 @@ task 'doc:site', 'watch and continually rebuild the documentation for the websit if file in ['generator_iteration', 'generators', 'modules'] cshtml = cshtml.replace /(yield|import|export|from|as|default) /g, '$1 ' jshtml = "
#{hljs.highlight('javascript', js).value}
" - append = if executable is yes then '' else "alert(#{executable});" + append = if executable is yes then '' else "alert(#{executable});".replace /"/g, '"' if executable and executable isnt yes cs.replace /(\S)\s*\Z/m, "$1\n\nalert #{executable}" run = if executable is true then 'run' else "run: #{executable}" name = "example#{counter}" script = "" load = if showLoad then "
load
" else '' - button = if executable then "
#{run}
" else '' + button = if executable then """
#{run}
""" else '' "
#{cshtml}#{jshtml}#{script}#{load}#{button}
" monthNames = [ @@ -221,6 +221,7 @@ task 'doc:site', 'watch and continually rebuild the documentation for the websit codeFor: codeFor() releaseHeader: releaseHeader majorVersion: majorVersion + fullVersion: CoffeeScript.VERSION fs.writeFileSync "docs/v#{majorVersion}/index.html", output log 'compiled', green, "#{indexFile} → docs/v#{majorVersion}/index.html" diff --git a/docs/v1/annotated-source/coffee-script.html b/docs/v1/annotated-source/coffee-script.html index fdaed58382..a52f3d8699 100644 --- a/docs/v1/annotated-source/coffee-script.html +++ b/docs/v1/annotated-source/coffee-script.html @@ -144,7 +144,7 @@

coffee-script.coffee

-
exports.VERSION = '1.11.1'
+            
exports.VERSION = '1.12.0'
 
 exports.FILE_EXTENSIONS = ['.coffee', '.litcoffee', '.coffee.md']
@@ -179,10 +179,7 @@

coffee-script.coffee

base64encode = (src) -> switch
   when typeof Buffer is 'function'
     new Buffer(src).toString('base64')
-  when typeof btoa is 'function'
-    btoa(src)
-  else
-    throw new Error('Unable to base64 encode inline sourcemap.')
+ when typeof btoa is 'function'
@@ -193,6 +190,27 @@

coffee-script.coffee

+

The contents of a <script> block are encoded via UTF-16, so if any extended +characters are used in the block, btoa will fail as it maxes out at UTF-8. +See https://developer.mozilla.org/en-US/docs/Web/API/WindowBase64/Base64_encoding_and_decoding#The_Unicode_Problem +for the gory details, and for the solution implemented here.

+ + + +
    btoa encodeURIComponent(src).replace /%([0-9A-F]{2})/g, (match, p1) ->
+      String.fromCharCode '0x' + p1
+  else
+    throw new Error('Unable to base64 encode inline sourcemap.')
+ + + + +
  • +
    + +
    + +

    Function wrapper to add source file information to SyntaxErrors thrown by the lexer/parser/compiler.

    @@ -209,11 +227,11 @@

    coffee-script.coffee

  • -
  • +
  • - +

    Compile CoffeeScript code to JavaScript, using the Coffee/Jison compiler.

    If options.sourceMap is specified, then options.filename must also be specified. All @@ -238,11 +256,11 @@

    coffee-script.coffee

  • -
  • +
  • - +

    Pass a list of referenced variables, so that generated variables won’t get the same name.

    @@ -256,11 +274,11 @@

    coffee-script.coffee

  • -
  • +
  • - +

    Check for import or export; if found, force bare mode

    @@ -284,11 +302,11 @@

    coffee-script.coffee

  • -
  • +
  • - +

    Update the sourcemap with data from each fragment

    @@ -299,11 +317,11 @@

    coffee-script.coffee

  • -
  • +
  • - +

    Do not include empty, whitespace, or semicolon-only fragments.

    @@ -324,11 +342,11 @@

    coffee-script.coffee

  • -
  • +
  • - +

    Copy the code from each fragment into the final JavaScript.

    @@ -361,11 +379,11 @@

    coffee-script.coffee

  • -
  • +
  • - +

    Tokenize a string of CoffeeScript code, and return the array of tokens.

    @@ -377,11 +395,11 @@

    coffee-script.coffee

  • -
  • +
  • - +

    Parse a string of CoffeeScript code or an array of lexed tokens, and return the AST. You can then compile it by calling .compile() on the root, @@ -398,11 +416,11 @@

    coffee-script.coffee

  • -
  • +
  • - +

    Compile and execute a string of CoffeeScript (on the server), correctly setting __filename, __dirname, and relative require().

    @@ -415,11 +433,11 @@

    coffee-script.coffee

  • -
  • +
  • - +

    Set the filename.

    @@ -431,11 +449,11 @@

    coffee-script.coffee

  • -
  • +
  • - +

    Clear the module cache.

    @@ -446,11 +464,11 @@

    coffee-script.coffee

  • -
  • +
  • - +

    Assign paths for node_modules loading

    @@ -465,11 +483,11 @@

    coffee-script.coffee

  • -
  • +
  • - +

    Compile.

    @@ -484,11 +502,11 @@

    coffee-script.coffee

  • -
  • +
  • - +

    Compile and evaluate a string of CoffeeScript (in a Node.js-like environment). The CoffeeScript REPL uses this to run the input.

    @@ -518,11 +536,11 @@

    coffee-script.coffee

  • -
  • +
  • - +

    define module/require only if they chose not to specify their own

    @@ -539,11 +557,11 @@

    coffee-script.coffee

  • -
  • +
  • - +

    use the same hack node currently uses for their own REPL

    @@ -565,11 +583,11 @@

    coffee-script.coffee

  • -
  • +
  • - +

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

    @@ -597,11 +615,11 @@

    coffee-script.coffee

  • -
  • +
  • - +

    As the filename and code of a dynamically loaded file will be different from the original file compiled with CoffeeScript.run, add that @@ -616,11 +634,11 @@

    coffee-script.coffee

  • -
  • +
  • - +

    Instantiate a Lexer for our use here.

    @@ -631,11 +649,11 @@

    coffee-script.coffee

  • -
  • +
  • - +

    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 @@ -663,11 +681,11 @@

    coffee-script.coffee

  • -
  • +
  • - +

    Make all the AST nodes visible to the parser.

    @@ -678,11 +696,11 @@

    coffee-script.coffee

  • -
  • +
  • - +

    Override Jison’s default error handling function.

    @@ -693,11 +711,11 @@

    coffee-script.coffee

  • -
  • +
  • - +

    Disregard Jison’s message, it contains redundant line number information. Disregard the token, we take its value directly from the lexer in case @@ -721,11 +739,11 @@

    coffee-script.coffee

  • -
  • +
  • - +

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

    coffee-script.coffee

  • -
  • +
  • - +

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

    @@ -771,11 +789,11 @@

    coffee-script.coffee

  • -
  • +
  • - +

    Check for a sourceMap position

    @@ -797,13 +815,13 @@

    coffee-script.coffee

    typeName = frame.getTypeName() if functionName - tp = as = '' + tp = as = '' if typeName and functionName.indexOf typeName tp = "#{typeName}." if methodName and functionName.indexOf(".#{methodName}") isnt functionName.length - methodName.length - 1 - as = " [as #{methodName}]" + as = " [as #{methodName}]" - "#{tp}#{functionName}#{as} (#{fileLocation})" + "#{tp}#{functionName}#{as} (#{fileLocation})" else "#{typeName}.#{methodName or '<anonymous>'} (#{fileLocation})" else if isConstructor @@ -816,11 +834,11 @@

    coffee-script.coffee

  • -
  • +
  • - +

    Map of filenames -> sourceMap object.

    @@ -831,11 +849,11 @@

    coffee-script.coffee

  • -
  • +
  • - +

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

    @@ -852,11 +870,11 @@

    coffee-script.coffee

  • -
  • +
  • - +

    Based on michaelficarra/CoffeeScriptRedux NodeJS / V8 have no support for transforming positions in stack traces using diff --git a/docs/v1/annotated-source/grammar.html b/docs/v1/annotated-source/grammar.html index 970a433f21..5e77ca8347 100644 --- a/docs/v1/annotated-source/grammar.html +++ b/docs/v1/annotated-source/grammar.html @@ -981,6 +981,7 @@

    Grammatical Rules

      Invocation: [
    +    o 'Value OptFuncExist String',              -> new TaggedTemplateCall $1, $3, $2
         o 'Value OptFuncExist Arguments',           -> new Call $1, $3, $2
         o 'Invocation OptFuncExist Arguments',      -> new Call $1, $3, $2
         o 'Super'
    @@ -1344,12 +1345,12 @@ 

    Grammatical Rules

    ForBody: [ o 'FOR Range', -> source: (LOC(2) new Value($2)) o 'FOR Range BY Expression', -> source: (LOC(2) new Value($2)), step: $4 - o 'ForStart ForSource', -> $2.own = $1.own; $2.name = $1[0]; $2.index = $1[1]; $2 + o 'ForStart ForSource', -> $2.own = $1.own; $2.ownTag = $1.ownTag; $2.name = $1[0]; $2.index = $1[1]; $2 ] ForStart: [ o 'FOR ForVariables', -> $2 - o 'FOR OWN ForVariables', -> $3.own = yes; $3 + o 'FOR OWN ForVariables', -> $3.own = yes; $3.ownTag = (LOC(2) new Literal($2)); $3 ]
  • @@ -1416,6 +1417,8 @@

    Grammatical Rules

    o 'FORIN Expression BY Expression', -> source: $2, step: $4 o 'FORIN Expression WHEN Expression BY Expression', -> source: $2, guard: $4, step: $6 o 'FORIN Expression BY Expression WHEN Expression', -> source: $2, step: $4, guard: $6 + o 'FORFROM Expression', -> source: $2, from: yes + o 'FORFROM Expression WHEN Expression', -> source: $2, guard: $4, from: yes ] Switch: [ @@ -1527,7 +1530,7 @@

    Grammatical Rules

    -

    The existential operator.

    +

    The existential operator.

    @@ -1540,7 +1543,12 @@

    Grammatical Rules

    o 'Expression ** Expression', -> new Op $2, $1, $3 o 'Expression SHIFT Expression', -> new Op $2, $1, $3 o 'Expression COMPARE Expression', -> new Op $2, $1, $3 - o 'Expression LOGIC Expression', -> new Op $2, $1, $3 + o 'Expression & Expression', -> new Op $2, $1, $3 + o 'Expression ^ Expression', -> new Op $2, $1, $3 + o 'Expression | Expression', -> new Op $2, $1, $3 + o 'Expression && Expression', -> new Op $2, $1, $3 + o 'Expression || Expression', -> new Op $2, $1, $3 + o 'Expression BIN? Expression', -> new Op $2, $1, $3 o 'Expression RELATION Expression', -> if $2.charAt(0) is '!' new Op($2[1..], $1, $3).invert() @@ -1611,11 +1619,16 @@

    Precedence

    ['left', 'SHIFT'] ['left', 'RELATION'] ['left', 'COMPARE'] - ['left', 'LOGIC'] + ['left', '&'] + ['left', '^'] + ['left', '|'] + ['left', '&&'] + ['left', '||'] + ['left', 'BIN?'] ['nonassoc', 'INDENT', 'OUTDENT'] ['right', 'YIELD'] ['right', '=', ':', 'COMPOUND_ASSIGN', 'RETURN', 'THROW', 'EXTENDS'] - ['right', 'FORIN', 'FOROF', 'BY', 'WHEN'] + ['right', 'FORIN', 'FOROF', 'FORFROM', 'BY', 'WHEN'] ['right', 'IF', 'ELSE', 'FOR', 'WHILE', 'UNTIL', 'LOOP', 'SUPER', 'CLASS', 'IMPORT', 'EXPORT'] ['left', 'POST_IF'] ] diff --git a/docs/v1/annotated-source/helpers.html b/docs/v1/annotated-source/helpers.html index fd6cd37f49..41d9460192 100644 --- a/docs/v1/annotated-source/helpers.html +++ b/docs/v1/annotated-source/helpers.html @@ -478,7 +478,7 @@

    helpers.coffee

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

    diff --git a/docs/v1/annotated-source/lexer.html b/docs/v1/annotated-source/lexer.html index dab315e232..31c2d48dd7 100644 --- a/docs/v1/annotated-source/lexer.html +++ b/docs/v1/annotated-source/lexer.html @@ -216,15 +216,16 @@

    The Lexer Class

    @indents = [] # The stack of all current indentation levels. @ends = [] # The stack for pairing up tokens. @tokens = [] # Stream of parsed tokens in the form `['TYPE', value, location data]`. - @seenFor = no # Used to recognize FORIN and FOROF tokens. + @seenFor = no # Used to recognize FORIN, FOROF and FORFROM tokens. @seenImport = no # Used to recognize IMPORT FROM? AS? tokens. @seenExport = no # Used to recognize EXPORT FROM? AS? tokens. + @exportSpecifierList = no # Used to identify when in an EXPORT {...} FROM? ... @chunkLine = - opts.line or 0 # The start line for the current @chunk. + opts.line or 0 # The start line for the current @chunk. @chunkColumn = - opts.column or 0 # The start column of the current @chunk. - code = @clean code # The stripped, cleaned original source code. + opts.column or 0 # The start column of the current @chunk. + code = @clean code # The stripped, cleaned original source code. @@ -371,10 +372,14 @@

    Tokenizers

    if id is 'from' and @tag() is 'YIELD' @token 'FROM', id return id.length - if id is 'as' and @seenImport and (@tag() is 'IDENTIFIER' or @value() is '*') - @tokens[@tokens.length - 1][0] = 'IMPORT_ALL' if @value() is '*' - @token 'AS', id - return id.length + if id is 'as' and @seenImport + if @value() is '*' + @tokens[@tokens.length - 1][0] = 'IMPORT_ALL' + else if @value() in COFFEE_KEYWORDS + @tokens[@tokens.length - 1][0] = 'IDENTIFIER' + if @tag() in ['IMPORT_ALL', 'IDENTIFIER'] + @token 'AS', id + return id.length if id is 'as' and @seenExport and @tag() is 'IDENTIFIER' @token 'AS', id return id.length @@ -392,7 +397,8 @@

    Tokenizers

    else 'IDENTIFIER' - if tag is 'IDENTIFIER' and (id in JS_KEYWORDS or id in COFFEE_KEYWORDS) + if tag is 'IDENTIFIER' and (id in JS_KEYWORDS or id in COFFEE_KEYWORDS) and + not (@exportSpecifierList and id in COFFEE_KEYWORDS) tag = id.toUpperCase() if tag is 'WHEN' and @tag() in LINE_BREAK tag = 'LEADING_WHEN' @@ -415,6 +421,9 @@

    Tokenizers

    if @value() is '!' poppedToken = @tokens.pop() id = '!' + id + else if tag is 'IDENTIFIER' and @seenFor and id is 'from' + tag = 'FORFROM' + @seenFor = no if tag is 'IDENTIFIER' and id in RESERVED @error "reserved word '#{id}'", length: id.length @@ -426,10 +435,10 @@

    Tokenizers

    tag = switch id when '!' then 'UNARY' when '==', '!=' then 'COMPARE' - when '&&', '||' then 'LOGIC' when 'true', 'false' then 'BOOL' when 'break', 'continue', \ 'debugger' then 'STATEMENT' + when '&&', '||' then id else tag tagToken = @token tag, id, 0, idLength @@ -612,9 +621,8 @@

    Tokenizers

      jsToken: ->
    -    return 0 unless @chunk.charAt(0) is '`' and match = JSTOKEN.exec @chunk
    -    @token 'JS', (script = match[0])[1...-1], 0, script.length
    -    script.length
    + return 0 unless @chunk.charAt(0) is '`' and + (match = HERE_JSTOKEN.exec(@chunk) or JSTOKEN.exec(@chunk)) @@ -625,6 +633,40 @@

    Tokenizers

    +

    Convert escaped backticks to backticks, and escaped backslashes +just before escaped backticks to backslashes

    + + + +
        script = match[1].replace /\\+(`|$)/g, (string) ->
    + + + + +
  • +
    + +
    + +
    +

    string is always a value like ‘`‘, ‘\`‘, ‘\\`‘, etc. +By reducing it to its latter half, we turn ‘`‘ to ‘', '\\\‘ to ‘`‘, etc.

    + +
    + +
          string[-Math.ceil(string.length / 2)..]
    +    @token 'JS', script, 0, match[0].length
    +    match[0].length
    + +
  • + + +
  • +
    + +
    + +

    Matches regular expression literals, as well as multiline extended ones. Lexing regular expressions is difficult to distinguish from division, so we borrow some basic heuristics from JavaScript and Ruby.

    @@ -677,11 +719,11 @@

    Tokenizers

  • -
  • +
  • - +

    Matches newlines, indents, and outdents, and determines which is which. If we can detect that the current line is continued onto the next line, @@ -731,11 +773,11 @@

    Tokenizers

  • -
  • +
  • - +

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

    @@ -764,11 +806,11 @@

    Tokenizers

  • -
  • +
  • - +

    pair might call outdentToken, so preserve decreasedIndent

    @@ -787,11 +829,11 @@

    Tokenizers

  • -
  • +
  • - +

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

    @@ -808,11 +850,11 @@

    Tokenizers

  • -
  • +
  • - +

    Generate a newline token. Consecutive newlines get merged together.

    @@ -826,11 +868,11 @@

    Tokenizers

  • -
  • +
  • - +

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

    @@ -844,11 +886,11 @@

    Tokenizers

  • -
  • +
  • - +

    We treat all other single characters as a token. E.g.: ( ) , . ! Multi-character operators are also literal tokens, so that Jison can assign @@ -880,6 +922,11 @@

    Tokenizers

    @error message, origin[2] if message return value.length if skipToken + if value is '{' and prev?[0] is 'EXPORT' + @exportSpecifierList = yes + else if @exportSpecifierList and value is '}' + @exportSpecifierList = no + if value is ';' @seenFor = @seenImport = @seenExport = no tag = 'TERMINATOR' @@ -891,7 +938,7 @@

    Tokenizers

    else if value in UNARY then tag = 'UNARY' else if value in UNARY_MATH then tag = 'UNARY_MATH' else if value in SHIFT then tag = 'SHIFT' - else if value in LOGIC or value is '?' and prev?.spaced then tag = 'LOGIC' + else if value is '?' and prev?.spaced then tag = 'BIN?' else if prev and not prev.spaced if value is '(' and prev[0] in CALLABLE prev[0] = 'FUNC_EXIST' if prev[0] is '?' @@ -910,11 +957,11 @@

    Tokenizers

  • -
  • +
  • - +

    Token Manipulators

    @@ -923,11 +970,11 @@

    Token Manipulators

  • -
  • +
  • - +
    @@ -935,11 +982,11 @@

    Token Manipulators

  • -
  • +
  • - +

    A source of ambiguity in our grammar used to be parameter lists in function definitions versus argument lists in function calls. Walk backwards, tagging @@ -968,11 +1015,11 @@

    Token Manipulators

  • -
  • +
  • - +

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

    @@ -984,11 +1031,11 @@

    Token Manipulators

  • -
  • +
  • - +

    Match the contents of a delimited token and expand variables and expressions inside it using Ruby-like notation for substitution of arbitrary @@ -1020,11 +1067,11 @@

    Token Manipulators

  • -
  • +
  • - +

    Push a fake ‘NEOSTRING’ token, which will get turned into a real string later.

    @@ -1040,11 +1087,11 @@

    Token Manipulators

  • -
  • +
  • - +

    The 1s are to remove the # in #{.

    @@ -1057,11 +1104,11 @@

    Token Manipulators

  • -
  • +
  • - +

    Skip the trailing }.

    @@ -1072,11 +1119,11 @@

    Token Manipulators

  • -
  • +
  • - +

    Turn the leading and trailing { and } into parentheses. Unnecessary parentheses will be removed later.

    @@ -1091,11 +1138,11 @@

    Token Manipulators

  • -
  • +
  • - +

    Remove leading ‘TERMINATOR’ (if any).

    @@ -1106,11 +1153,11 @@

    Token Manipulators

  • -
  • +
  • - +

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

    @@ -1126,7 +1173,11 @@

    Token Manipulators

    [firstToken, ..., lastToken] = tokens firstToken[2].first_column -= delimiter.length - lastToken[2].last_column += delimiter.length + if lastToken[1].substr(-1) is '\n' + lastToken[2].last_line += 1 + lastToken[2].last_column = delimiter.length - 1 + else + lastToken[2].last_column += delimiter.length lastToken[2].last_column -= 1 if lastToken[1].length is 0 {tokens, index: offsetInChunk + delimiter.length}
    @@ -1134,11 +1185,11 @@

    Token Manipulators

  • -
  • +
  • - +

    Merge the array tokens of the fake token types ‘TOKENS’ and ‘NEOSTRING’ (as returned by matchWithInterpolations) into the token stream. The value @@ -1160,11 +1211,11 @@

    Token Manipulators

  • -
  • +
  • - +

    Optimize out empty interpolations (an empty pair of parentheses).

    @@ -1175,11 +1226,11 @@

    Token Manipulators

  • -
  • +
  • - +

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

    @@ -1193,11 +1244,11 @@

    Token Manipulators

  • -
  • +
  • - +

    Convert ‘NEOSTRING’ into ‘STRING’.

    @@ -1208,11 +1259,11 @@

    Token Manipulators

  • -
  • +
  • - +

    Optimize out empty strings. We ensure that the tokens stream always starts with a string token, though, to make sure that the result @@ -1229,11 +1280,11 @@

    Token Manipulators

  • -
  • +
  • - +

    However, there is one case where we can optimize away a starting empty string.

    @@ -1251,11 +1302,11 @@

    Token Manipulators

  • -
  • +
  • - +

    Create a 0-length “+” token.

    @@ -1287,11 +1338,11 @@

    Token Manipulators

  • -
  • +
  • - +

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

    @@ -1306,11 +1357,11 @@

    Token Manipulators

  • -
  • +
  • - +

    Auto-close INDENT to support syntax like this:

    el.click((event) ->
    @@ -1326,11 +1377,11 @@ 

    Token Manipulators

  • -
  • +
  • - +

    Helpers

    @@ -1339,11 +1390,11 @@

    Helpers

  • -
  • +
  • - +
    @@ -1351,11 +1402,11 @@

    Helpers

  • -
  • +
  • - +

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

    offset is a number of characters into @chunk.

    @@ -1385,11 +1436,11 @@

    Helpers

  • -
  • +
  • - +

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

    @@ -1404,11 +1455,11 @@

    Helpers

  • -
  • +
  • - +

    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.

    @@ -1426,11 +1477,11 @@

    Helpers

  • -
  • +
  • - +

    Add a token to the results. offset is the offset into the current @chunk where the token starts. @@ -1449,11 +1500,11 @@

    Helpers

  • -
  • +
  • - +

    Peek at the last tag in the token stream.

    @@ -1466,11 +1517,11 @@

    Helpers

  • -
  • +
  • - +

    Peek at the last value in the token stream.

    @@ -1483,11 +1534,11 @@

    Helpers

  • -
  • +
  • - +

    Are we in the midst of an unfinished expression?

    @@ -1496,7 +1547,8 @@

    Helpers

      unfinished: ->
         LINE_CONTINUER.test(@chunk) or
         @tag() in ['\\', '.', '?.', '?::', 'UNARY', 'MATH', 'UNARY_MATH', '+', '-',
    -               '**', 'SHIFT', 'RELATION', 'COMPARE', 'LOGIC', 'THROW', 'EXTENDS']
    +               '**', 'SHIFT', 'RELATION', 'COMPARE', '&', '^', '|', '&&', '||',
    +               'BIN?', 'THROW', 'EXTENDS']
     
       formatString: (str) ->
         str.replace STRING_OMIT, '$1'
    @@ -1507,11 +1559,11 @@ 

    Helpers

  • -
  • +
  • - +

    Validates escapes in strings and regexes.

    @@ -1535,11 +1587,11 @@

    Helpers

  • -
  • +
  • - +

    Constructs a string or regex by escaping certain characters.

    @@ -1559,11 +1611,11 @@

    Helpers

  • -
  • +
  • - +

    Ignore escaped backslashes.

    @@ -1582,11 +1634,11 @@

    Helpers

  • -
  • +
  • - +

    Throws an error at either a given offset from the current chunk or at the location of a token (token[2]).

    @@ -1605,11 +1657,11 @@

    Helpers

  • -
  • +
  • - +

    Helper functions

    @@ -1618,11 +1670,11 @@

    Helper functions

  • -
  • +
  • - +
    @@ -1643,11 +1695,11 @@

    Helper functions

  • -
  • +
  • - +

    Constants

    @@ -1656,11 +1708,11 @@

    Constants

  • -
  • +
  • - +
    @@ -1668,11 +1720,11 @@

    Constants

  • -
  • +
  • - +

    Keywords that CoffeeScript shares in common with JavaScript.

    @@ -1690,11 +1742,11 @@

    Constants

  • -
  • +
  • - +

    CoffeeScript-only keywords.

    @@ -1722,11 +1774,11 @@

    Constants

  • -
  • +
  • - +

    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, @@ -1745,11 +1797,11 @@

    Constants

  • -
  • +
  • - +

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

    @@ -1761,11 +1813,11 @@

    Constants

  • -
  • +
  • - +

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

    @@ -1776,11 +1828,11 @@

    Constants

  • -
  • +
  • - +

    Token matching regexes.

    @@ -1817,16 +1869,17 @@

    Constants

    MULTI_DENT = /^(?:\n[^\n\S]*)+/ -JSTOKEN = /^`[^\\`]*(?:\\.[^\\`]*)*`/
    +JSTOKEN = ///^ `(?!``) ((?: [^`\\] | \\[\s\S] )*) ` /// +HERE_JSTOKEN = ///^ ``` ((?: [^`\\] | \\[\s\S] | `(?!``) )*) ``` ///
  • -
  • +
  • - +

    String-matching-regexes.

    @@ -1849,11 +1902,11 @@

    Constants

  • -
  • +
  • - +

    Regex-matching-regexes.

    @@ -1887,11 +1940,11 @@

    Constants

  • -
  • +
  • - +

    Other regexes.

    @@ -1918,11 +1971,11 @@

    Constants

  • -
  • +
  • - +

    Compound assignment tokens.

    @@ -1936,11 +1989,11 @@

    Constants

  • -
  • +
  • - +

    Unary tokens.

    @@ -1953,26 +2006,11 @@

    Constants

  • -
  • -
    - -
    - -
    -

    Logical tokens.

    - -
    - -
    LOGIC = ['&&', '||', '&', '|', '^']
    - -
  • - - -
  • +
  • - +

    Bit-shifting tokens.

    @@ -1983,11 +2021,11 @@

    Constants

  • -
  • +
  • - +

    Comparison tokens.

    @@ -1998,11 +2036,11 @@

    Constants

  • -
  • +
  • - +

    Mathematical tokens.

    @@ -2013,11 +2051,11 @@

    Constants

  • -
  • +
  • - +

    Relational tokens that are negatable with not prefix.

    @@ -2028,11 +2066,11 @@

    Constants

  • -
  • +
  • - +

    Boolean tokens.

    @@ -2043,11 +2081,11 @@

    Constants

  • -
  • +
  • - +

    Tokens which could legitimately be invoked or indexed. An opening parentheses or bracket following these tokens will be recorded as the start @@ -2064,11 +2102,11 @@

    Constants

  • -
  • +
  • - +

    Tokens which a regular expression will never immediately follow (except spaced CALLABLEs in some cases), but which a division operator can.

    @@ -2081,11 +2119,11 @@

    Constants

  • -
  • +
  • - +

    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 @@ -2098,11 +2136,11 @@

    Constants

  • -
  • +
  • - +

    Additional indent in front of these is ignored.

    diff --git a/docs/v1/annotated-source/nodes.html b/docs/v1/annotated-source/nodes.html index 5c815d09bd..8d1c78bcc9 100644 --- a/docs/v1/annotated-source/nodes.html +++ b/docs/v1/annotated-source/nodes.html @@ -1688,10 +1688,18 @@

    RegexWithInterpolations

    -

    Extends

    +

    TaggedTemplateCall

    +
    +exports.TaggedTemplateCall = class TaggedTemplateCall extends Call
    +  constructor: (variable, arg, soak) ->
    +    arg = new StringWithInterpolations Block.wrap([ new Value arg ]) if arg instanceof StringLiteral
    +    super variable, [ arg ], soak
    +
    +  compileNode: (o) ->
    +
  • @@ -1701,9 +1709,38 @@

    Extends

    +

    Tell StringWithInterpolations whether to compile as ES2015 or not; will be removed in CoffeeScript 2.

    + + + +
        o.inTaggedTemplateCall = yes
    +    @variable.compileToFragments(o, LEVEL_ACCESS).concat @args[0].compileToFragments(o, LEVEL_LIST)
    + + + + +
  • +
    + +
    + +
    +

    Extends

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

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

    +Closure Library.

    @@ -1715,11 +1752,11 @@

    Extends

  • -
  • +
  • - +

    Hooks one constructor into another’s prototype chain.

    @@ -1731,11 +1768,11 @@

    Extends

  • -
  • +
  • - +

    Access

    @@ -1744,11 +1781,11 @@

    Access

  • -
  • +
  • - +

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

    @@ -1777,11 +1814,11 @@

    Access

  • -
  • +
  • - +

    Index

    @@ -1790,11 +1827,11 @@

    Index

  • -
  • +
  • - +

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

    @@ -1814,11 +1851,11 @@

    Index

  • -
  • +
  • - +

    Range

    @@ -1827,11 +1864,11 @@

    Range

  • -
  • +
  • - +

    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 @@ -1850,11 +1887,11 @@

    Range

  • -
  • +
  • - +

    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.

    @@ -1874,11 +1911,11 @@

    Range

  • -
  • +
  • - +

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

    @@ -1892,11 +1929,11 @@

    Range

  • -
  • +
  • - +

    Set up endpoints.

    @@ -1914,11 +1951,11 @@

    Range

  • -
  • +
  • - +

    Generate the condition.

    @@ -1927,8 +1964,8 @@

    Range

        condPart = if @stepNum?
           if @stepNum > 0 then "#{lt} #{@toVar}" else "#{gt} #{@toVar}"
         else if known
    -      [from, to] = [@fromNum, @toNum]
    -      if from <= to then "#{lt} #{to}" else "#{gt} #{to}"
    +      [from, to] = [@fromNum, @toNum]
    +      if from <= to then "#{lt} #{to}" else "#{gt} #{to}"
         else
           cond = if @stepVar then "#{@stepVar} > 0" else "#{@fromVar} <= #{@toVar}"
           "#{cond} ? #{lt} #{@toVar} : #{gt} #{@toVar}"
    @@ -1936,11 +1973,11 @@

    Range

  • -
  • +
  • - +

    Generate the step.

    @@ -1950,9 +1987,9 @@

    Range

    "#{idx} += #{@stepVar}" else if known if namedIndex - if from <= to then "++#{idx}" else "--#{idx}" + if from <= to then "++#{idx}" else "--#{idx}" else - if from <= to then "#{idx}++" else "#{idx}--" + if from <= to then "#{idx}++" else "#{idx}--" else if namedIndex "#{cond} ? ++#{idx} : --#{idx}" @@ -1965,11 +2002,11 @@

    Range

  • -
  • +
  • - +

    The final loop body.

    @@ -1980,11 +2017,11 @@

    Range

  • -
  • +
  • - +

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

    @@ -2015,11 +2052,11 @@

    Range

  • -
  • +
  • - +

    Slice

    @@ -2028,11 +2065,11 @@

    Slice

  • -
  • +
  • - +

    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 @@ -2050,11 +2087,11 @@

    Slice

  • -
  • +
  • - +

    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. @@ -2063,17 +2100,17 @@

    Slice

      compileNode: (o) ->
    -    {to, from} = @range
    -    fromCompiled = from and from.compileToFragments(o, LEVEL_PAREN) or [@makeCode '0']
    + {to, from} = @range + fromCompiled = from and from.compileToFragments(o, LEVEL_PAREN) or [@makeCode '0']
  • -
  • +
  • - +

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

    @@ -2095,11 +2132,11 @@

    Slice

  • -
  • +
  • - +

    Obj

    @@ -2108,11 +2145,11 @@

    Obj

  • -
  • +
  • - +

    An object literal, nothing fancy.

    @@ -2185,11 +2222,11 @@

    Obj

  • -
  • +
  • - +

    Arr

    @@ -2198,11 +2235,11 @@

    Arr

  • -
  • +
  • - +

    An array literal.

    @@ -2241,11 +2278,11 @@

    Arr

  • -
  • +
  • - +

    Class

    @@ -2254,11 +2291,11 @@

    Class

  • -
  • +
  • - +

    The CoffeeScript class definition. Initialize a Class with its name, an optional superclass, and a @@ -2278,11 +2315,11 @@

    Class

  • -
  • +
  • - +

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

    @@ -2306,11 +2343,11 @@

    Class

  • -
  • +
  • - +

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

    @@ -2328,11 +2365,11 @@

    Class

  • -
  • +
  • - +

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

    @@ -2348,11 +2385,11 @@

    Class

  • -
  • +
  • - +

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

    @@ -2391,11 +2428,11 @@

    Class

  • -
  • +
  • - +

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

    @@ -2419,11 +2456,11 @@

    Class

  • -
  • +
  • - +

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

    Class

  • -
  • +
  • - +

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

    @@ -2468,11 +2505,11 @@

    Class

  • -
  • +
  • - +

    Instead of generating the JavaScript string directly, we build up the equivalent syntax tree and compile that, in pieces. You can see the @@ -2515,11 +2552,11 @@

    Class

  • -
  • +
  • - +

    Import and Export

    @@ -2591,11 +2628,27 @@

    Import and Export

  • -
  • +
  • - + +
    +

    Prevent exporting an anonymous class; all exported members must be named

    + +
    + +
          if @clause instanceof Class and not @clause.variable
    +        @clause.error 'anonymous classes cannot be exported'
    + +
  • + + +
  • +
    + +
    +

    When the ES2015 class keyword is supported, don’t add a var here

    @@ -2649,11 +2702,11 @@

    Import and Export

  • -
  • +
  • - +

    The name of the variable entering the local scope

    @@ -2679,11 +2732,11 @@

    Import and Export

  • -
  • +
  • - +

    Per the spec, symbols can’t be imported multiple times (e.g. import { foo, foo } from 'lib' is invalid)

    @@ -2707,11 +2760,11 @@

    Import and Export

  • -
  • +
  • - +

    Assign

    @@ -2720,11 +2773,11 @@

    Assign

  • -
  • +
  • - +

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

    @@ -2754,11 +2807,11 @@

    Assign

  • -
  • +
  • - +

    Compile an assignment, delegating to compilePatternMatch or compileSplice if appropriate. Keep track of the name of the base object @@ -2788,8 +2841,22 @@

    Assign

    varBase = @variable.unwrapAll() unless varBase.isAssignable() @variable.error "'#{@variable.compile o}' can't be assigned" - unless varBase.hasProperties?() - if @moduleDeclaration # `moduleDeclaration` can be `'import'` or `'export'` + unless varBase.hasProperties?()
    + +
  • + + +
  • +
    + +
    + +
    +

    moduleDeclaration can be 'import' or 'export'

    + +
    + +
            if @moduleDeclaration
               @checkAssignability o, varBase
               o.scope.add varBase.value, @moduleDeclaration
             else if @param
    @@ -2814,11 +2881,11 @@ 

    Assign

  • -
  • +
  • - +

    Brief implementation of recursive pattern matching, when assigning array or object literals to a value. Peeks at their properties to assign inner names.

    @@ -2841,11 +2908,11 @@

    Assign

  • -
  • +
  • - +

    Pick the property straight off the value when there’s just one to pick (no need to cache the value into a variable).

    @@ -2858,11 +2925,11 @@

    Assign

  • -
  • +
  • - +

    A regular object pattern-match.

    @@ -2881,11 +2948,11 @@

    Assign

  • -
  • +
  • - +

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

    @@ -2900,11 +2967,11 @@

    Assign

  • -
  • +
  • - +

    A regular array pattern-match.

    @@ -2926,11 +2993,11 @@

    Assign

  • -
  • +
  • - +

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

    @@ -2972,11 +3039,11 @@

    Assign

  • -
  • +
  • - +

    A regular object pattern-match.

    @@ -2995,11 +3062,11 @@

    Assign

  • -
  • +
  • - +

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

    @@ -3014,11 +3081,11 @@

    Assign

  • -
  • +
  • - +

    A regular array pattern-match.

    @@ -3040,11 +3107,11 @@

    Assign

  • -
  • +
  • - +

    When compiling a conditional assignment, take care to ensure that the operands are only evaluated once, even though we have to reference them @@ -3058,11 +3125,11 @@

    Assign

  • -
  • +
  • - +

    Disallow conditional assignment of undefined variables.

    @@ -3081,11 +3148,11 @@

    Assign

  • -
  • +
  • - +

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

    @@ -3099,11 +3166,11 @@

    Assign

  • -
  • +
  • - +

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

    @@ -3111,14 +3178,14 @@

    Assign

      compileSplice: (o) ->
    -    {range: {from, to, exclusive}} = @variable.properties.pop()
    +    {range: {from, to, exclusive}} = @variable.properties.pop()
         name = @variable.compile o
    -    if from
    -      [fromDecl, fromRef] = @cacheToCodeFragments from.cache o, LEVEL_OP
    +    if from
    +      [fromDecl, fromRef] = @cacheToCodeFragments from.cache o, LEVEL_OP
         else
           fromDecl = fromRef = '0'
         if to
    -      if from?.isNumber() and to.isNumber()
    +      if from?.isNumber() and to.isNumber()
             to = to.compile(o) - fromRef
             to += 1 unless exclusive
           else
    @@ -3133,11 +3200,11 @@ 

    Assign

  • -
  • +
  • - +

    Code

    @@ -3146,11 +3213,11 @@

    Code

  • -
  • +
  • - +

    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 @@ -3177,11 +3244,11 @@

    Code

  • -
  • +
  • - +

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

    Code

  • -
  • +
  • - +

    Handle bound functions early.

    @@ -3275,11 +3342,11 @@

    Code

  • -
  • +
  • - +

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

    @@ -3292,11 +3359,11 @@

    Code

  • -
  • +
  • - +

    Param

    @@ -3305,11 +3372,11 @@

    Param

  • -
  • +
  • - +

    A parameter in a function definition. Beyond a typical JavaScript parameter, these parameters can also attach themselves to the context of the function, @@ -3350,11 +3417,11 @@

    Param

  • -
  • +
  • - +

    Iterates the name or names of a Param. In a sense, a destructured parameter represents multiple JS parameters. This @@ -3371,11 +3438,11 @@

    Param

  • -
  • +
  • - +
    @@ -103,17 +104,29 @@

    - The golden rule of CoffeeScript is: "It's just JavaScript". The code + The golden rule of CoffeeScript is: “It’s just JavaScript”. The code compiles one-to-one into the equivalent JS, and there is no interpretation at runtime. You can use any existing JavaScript library seamlessly from CoffeeScript (and vice-versa). The compiled output is - readable and pretty-printed, will work in every JavaScript runtime, and tends - to run as fast or faster than the equivalent handwritten JavaScript. + readable, pretty-printed, and tends to run as fast or faster than the + equivalent handwritten JavaScript. +

    + +

    + The CoffeeScript compiler goes to great lengths to generate output JavaScript + that runs in every JavaScript runtime, but there are exceptions. Use + generator functions, + for…from, or + tagged template literals only if you + know that your target + runtimes can support them. If you use modules, + you will need to use an additional tool to resolve + them.

    Latest Version: - 1.11.1 + 1.12.0

    npm install -g coffee-script
    @@ -197,7 +210,7 @@

    } return results; })(); -
    run: cubes

    +;alert(cubes);">run: cubes

    @@ -256,7 +269,7 @@

    Node.js utility. The core compiler however, does not depend on Node, and can be run in any JavaScript environment, or in the - browser (see "Try CoffeeScript", above). + browser (see “Try CoffeeScript”, above).

    @@ -276,7 +289,7 @@

    npm install --save coffee-script

    - If you'd prefer to install the latest master version of CoffeeScript, you + If you’d prefer to install the latest master version of CoffeeScript, you can clone the CoffeeScript source repository from GitHub, or download @@ -288,7 +301,7 @@

    npm install -g jashkenas/coffeescript

    - Or, if you want to install to /usr/local, and don't want to use + Or, if you want to install to /usr/local, and don’t want to use npm to manage it, open the coffee-script directory and run:

    @@ -437,7 +450,7 @@

    --no-header - Suppress the "Generated by CoffeeScript" header. + Suppress the “Generated by CoffeeScript” header. @@ -481,10 +494,10 @@

    Besides being used as an ordinary programming language, CoffeeScript may - also be written in "literate" mode. If you name your file with a - .litcoffee extension, you can write it as a Markdown document — + also be written in “literate” mode. If you name your file with a + .litcoffee extension, you can write it as a Markdown document — a document that also happens to be executable CoffeeScript code. The compiler - will treat any indented blocks (Markdown's way of indicating source code) + will treat any indented blocks (Markdown’s way of indicating source code) as code, and ignore the rest as comments.

    @@ -497,7 +510,7 @@

    - I'm fairly excited about this direction for the language, and am looking + I’m fairly excited about this direction for the language, and am looking forward to writing (and more importantly, reading) more programs in this style. More information about Literate CoffeeScript, including an example program, @@ -522,12 +535,12 @@

    Many of the examples can be run (where it makes sense) by pressing the run - button on the right, and can be loaded into the "Try CoffeeScript" + button on the right, and can be loaded into the “Try CoffeeScript” console by pressing the load button on the left.

    First, the basics: CoffeeScript uses significant whitespace to delimit blocks of code. - You don't need to use semicolons ; to terminate expressions, + You don’t need to use semicolons ; to terminate expressions, ending the line will do just as well (although semicolons can still be used to fit multiple expressions onto a single line). Instead of using curly braces @@ -538,7 +551,7 @@

    - You don't need to use parentheses to invoke a function if you're passing + You don’t need to use parentheses to invoke a function if you’re passing arguments. The implicit call wraps forward to the end of the line or block expression.
    console.log sys.inspect objectconsole.log(sys.inspect(object));

    @@ -561,7 +574,7 @@

    cube = function(x) { return square(x) * x; }; -
    load
    load
    run: cube(5)

    Functions may also have default values for arguments, which will be used if the incoming argument is missing (null or undefined). @@ -585,15 +598,15 @@

    } return "Filling the " + container + " with " + liquid + "..."; }; -
    load
    load
    run: fill("cup")

    +;alert(fill("cup"));">run: fill("cup")

    @@ -641,32 +654,32 @@

    age: 9 } }; -
    load
    load
    run: song.join(" ... ")

    +;alert(song.join(" … "));">run: song.join(" … ")

    - In JavaScript, you can't use reserved words, like class, as properties + In JavaScript, you can’t use reserved words, like class, as properties of an object, without quoting them as strings. CoffeeScript notices reserved words - used as keys in objects and quotes them for you, so you don't have to worry + used as keys in objects and quotes them for you, so you don’t have to worry about it (say, when using jQuery).

    $('.account').attr class: 'active'
    @@ -678,12 +691,37 @@ 

    log(object["class"]);

    load

    +

    + CoffeeScript has a shortcut for creating objects when you want the key + to be set with a variable of the same name. +

    +
    name = "Michelangelo"
    +mask = "orange"
    +weapon = "nunchuks"
    +turtle = {name, mask, weapon}
    +output = "#{turtle.name} wears an #{turtle.mask} mask. Watch out for his #{turtle.weapon}!"
    +
    var mask, name, output, turtle, weapon;
    +
    +name = "Michelangelo";
    +
    +mask = "orange";
    +
    +weapon = "nunchuks";
    +
    +turtle = {
    +  name: name,
    +  mask: mask,
    +  weapon: weapon
    +};
    +
    +output = turtle.name + " wears an " + turtle.mask + " mask. Watch out for his " + turtle.weapon + "!";
    +
    load

    Lexical Scoping and Variable Safety The CoffeeScript compiler takes care to make sure that all of your variables - are properly declared within lexical scope — you never need to write + are properly declared within lexical scope — you never need to write var yourself.

    outer = 1
    @@ -702,7 +740,7 @@ 

    }; inner = changeNumbers(); -

    load
    load
    run: inner

    Notice how all of the variable declarations have been pushed up to the top of the closest scope, the first time they appear. - outer is not redeclared within the inner function, because it's + outer is not redeclared within the inner function, because it’s already in scope; inner within the function, on the other hand, should not be able to change the value of the external variable of the same name, and therefore has a declaration of its own.

    - This behavior is effectively identical to Ruby's scope for local variables. - Because you don't have direct access to the var keyword, - it's impossible to shadow an outer variable on purpose, you may only refer - to it. So be careful that you're not reusing the name of an external - variable accidentally, if you're writing a deeply nested function. + This behavior is effectively identical to Ruby’s scope for local variables. + Because you don’t have direct access to the var keyword, + it’s impossible to shadow an outer variable on purpose, you may only refer + to it. So be careful that you’re not reusing the name of an external + variable accidentally, if you’re writing a deeply nested function.

    Although suppressed within this documentation for clarity, all CoffeeScript output is wrapped in an anonymous function: - (function(){ ... })(); This safety wrapper, combined with the + (function(){ … })(); This safety wrapper, combined with the automatic generation of the var keyword, make it exceedingly difficult to pollute the global namespace by accident.

    - If you'd like to create top-level variables for other scripts to use, + If you’d like to create top-level variables for other scripts to use, attach them as properties on window; attach them as properties on the exports object in CommonJS; or use an export statement. If you’re targeting both CommonJS and the browser, the @@ -750,13 +788,13 @@

    If, Else, Unless, and Conditional Assignment If/else statements can be written without the use of parentheses and curly brackets. As with functions and other block expressions, - multi-line conditionals are delimited by indentation. There's also a handy + multi-line conditionals are delimited by indentation. There’s also a handy postfix form, with the if or unless at the end.

    CoffeeScript can compile if statements into JavaScript expressions, using the ternary operator when possible, and closure wrapping otherwise. There - is no explicit ternary statement in CoffeeScript — you simply use + is no explicit ternary statement in CoffeeScript — you simply use a regular if statement on a single line.

    mood = greatlyImproved if singing
    @@ -782,11 +820,11 @@ 

    } date = friday ? sue : jill; -

    load

    +
    load

    - Splats... + Splats… The JavaScript arguments object is a useful way to work with functions that accept variable numbers of arguments. CoffeeScript provides splats ..., both for function definition as well as invocation, @@ -839,10 +877,10 @@

    alert("Silver: " + silver); alert("The Field: " + rest); -
    load
    load
    return rest = others; }; -contenders = ["Michael Phelps", "Liu Xiang", "Yao Ming", "Allyson Felix", "Shawn Johnson", "Roman Sebrle", "Guo Jingjing", "Tyson Gay", "Asafa Powell", "Usain Bolt"]; +contenders = ["Michael Phelps", "Liu Xiang", "Yao Ming", "Allyson Felix", "Shawn Johnson", "Roman Sebrle", "Guo Jingjing", "Tyson Gay", "Asafa Powell", "Usain Bolt"]; awardMedals.apply(null, contenders); -alert("Gold: " + gold); +alert("Gold: " + gold); -alert("Silver: " + silver); +alert("Silver: " + silver); -alert("The Field: " + rest); -;'>run

    +alert("The Field: " + rest); +;">run

    Loops and Comprehensions - Most of the loops you'll write in CoffeeScript will be comprehensions + Most of the loops you’ll write in CoffeeScript will be comprehensions over arrays, objects, and ranges. Comprehensions replace (and compile into) for loops, with optional guard clauses and the value of the current array index. Unlike for loops, array comprehensions are expressions, and can be returned @@ -905,7 +943,7 @@

    eat(food); } } -
    load

    +
    load

    Comprehensions should be able to handle most places where you otherwise would use a loop, each/forEach, map, or select/filter, for example: @@ -925,7 +963,7 @@

    } return results; })(); -
    load
    load
    run: countdown

    Note how because we are assigning the value of the comprehensions to a variable in the example above, CoffeeScript is collecting the result of each iteration into an array. Sometimes functions end with loops that are - intended to run only for their side-effects. Be careful that you're not + intended to run only for their side-effects. Be careful that you’re not accidentally returning the results of the comprehension in these cases, - by adding a meaningful return value — like true — or null, + by adding a meaningful return value — like true — or null, to the bottom of your function.

    @@ -951,7 +989,7 @@

    evens = (x for x in [0..10] by 2)

    - If you don't need the current iteration value you may omit it:
    + If you don’t need the current iteration value you may omit it:
    browser.closeCurrentTab() for [0...count]

    @@ -980,7 +1018,7 @@

    } return results; })(); -
    load
    load
    run: ages.join(", ")

    +;alert(ages.join(", "));">run: ages.join(", ")

    If you would like to iterate over just the keys that are defined on the object itself, by adding a hasOwnProperty check to avoid properties that may be inherited from the prototype, use
    for own key, value of object

    +

    + To iterate a generator function, use from. + See Generator Functions.

    The only low-level loop that CoffeeScript provides is the while loop. The main difference from JavaScript is that the while loop can be used @@ -1041,7 +1082,7 @@

    } return results; })(); -
    load
    load
    run: lyrics.join("\n")

    +;alert(lyrics.join("\n"));">run: lyrics.join("\n")

    For readability, the until keyword is equivalent to while not, and the loop keyword is equivalent to while true.

    - When using a JavaScript loop to generate functions, it's common to insert + When using a JavaScript loop to generate functions, it’s common to insert a closure wrapper in order to ensure that loop variables are closed over, - and all the generated functions don't just share the final values. CoffeeScript + and all the generated functions don’t just share the final values. CoffeeScript provides the do keyword, which immediately invokes a passed function, forwarding any arguments.

    @@ -1089,7 +1130,7 @@

    filename = list[i]; fn(filename); } -
    load

    +
    load

    @@ -1120,7 +1161,7 @@

    end = numbers.slice(-2); copy = numbers.slice(0); -
    load
    load
    run: middle

    The same syntax can be used with assignment to replace a segment of an array with new values, splicing it. @@ -1144,19 +1185,19 @@

    numbers = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]; [].splice.apply(numbers, [3, 4].concat(ref = [-3, -4, -5, -6])), ref; -
    load
    load
    run: numbers

    - Note that JavaScript strings are immutable, and can't be spliced. + Note that JavaScript strings are immutable, and can’t be spliced.

    Everything is an Expression (at least, as much as possible) - You might have noticed how even though we don't add return statements + You might have noticed how even though we don’t add return statements to CoffeeScript functions, they nonetheless return their final value. The CoffeeScript compiler tries to make sure that all statements in the language can be used as expressions. Watch how the return gets @@ -1189,41 +1230,41 @@

    }; eldest = 24 > 21 ? "Liz" : "Ike"; -
    load
    load
    21 ? "Liz" : "Ike"; -;alert(eldest);'>run: eldest

    +eldest = 24 > 21 ? "Liz" : "Ike"; +;alert(eldest);">run: eldest

    - Even though functions will always return their final value, it's both possible + Even though functions will always return their final value, it’s both possible and encouraged to return early from a function body writing out the explicit - return (return value), when you know that you're done. + return (return value), when you know that you’re done.

    Because variable declarations occur at the top of scope, assignment can - be used within expressions, even for variables that haven't been seen before: + be used within expressions, even for variables that haven’t been seen before:

    six = (one = 1) + (two = 2) + (three = 3)
     
    var one, six, three, two;
     
     six = (one = 1) + (two = 2) + (three = 3);
    -
    load
    load
    run: six

    Things that would otherwise be statements in JavaScript, when used as part of an expression in CoffeeScript, are converted into expressions @@ -1243,7 +1284,7 @@

    } return results; })()).slice(0, 10); -
    load
    load
    run: globals

    As well as silly things, like passing a try/catch statement directly into a function call: @@ -1274,22 +1315,22 @@

    return "And the error is ... " + error; } })()); -
    load
    load
    run

    +;">run

    - There are a handful of statements in JavaScript that can't be meaningfully + There are a handful of statements in JavaScript that can’t be meaningfully converted into expressions, namely break, continue, and return. If you make use of them within a block of code, - CoffeeScript won't try to perform the conversion. + CoffeeScript won’t try to perform the conversion.

    @@ -1345,7 +1386,7 @@

    modulo(-7, 5) === 3; tabs.selectTabAtIndex(modulo(tabs.currentIndex - count, tabs.length)); -
    load

    +
    load

    All together now:

    @@ -1401,16 +1442,16 @@

    } print(inspect("My name is " + this.name)); -
    load

    +
    load

    The Existential Operator - It's a little difficult to check for the existence of a variable in - JavaScript. if (variable) ... comes close, but fails for zero, - the empty string, and false. CoffeeScript's existential operator ? returns true unless + It’s a little difficult to check for the existence of a variable in + JavaScript. if (variable) … comes close, but fails for zero, + the empty string, and false. CoffeeScript’s existential operator ? returns true unless a variable is null or undefined, which makes it analogous - to Ruby's nil? + to Ruby’s nil?

    It can also be used for safer conditional assignment than ||= @@ -1435,9 +1476,9 @@

    } footprints = typeof yeti !== "undefined" && yeti !== null ? yeti : "bear"; -
    load
    load
    speed = 15; } -footprints = typeof yeti !== "undefined" && yeti !== null ? yeti : "bear"; -;alert(footprints);'>run: footprints

    +footprints = typeof yeti !== "undefined" && yeti !== null ? yeti : "bear"; +;alert(footprints);">run: footprints

    The accessor variant of the existential operator ?. can be used to soak up null references in a chain of properties. Use it instead of the dot accessor . in cases where the base value may be null - or undefined. If all of the properties exist then you'll get the expected + or undefined. If all of the properties exist then you’ll get the expected result, if the chain is broken, undefined is returned instead of the TypeError that would be raised otherwise.

    @@ -1461,9 +1502,9 @@

    var ref, zip;
     
     zip = typeof lottery.drawWinner === "function" ? (ref = lottery.drawWinner().address) != null ? ref.zipcode : void 0 : void 0;
    -
    load

    +
    load

    - Soaking up nulls is similar to Ruby's + Soaking up nulls is similar to Ruby’s andand gem, and to the safe navigation operator in Groovy. @@ -1472,16 +1513,16 @@

    Classes, Inheritance, and Super - JavaScript's prototypal inheritance has always been a bit of a + JavaScript’s prototypal inheritance has always been a bit of a brain-bender, with a whole family tree of libraries that provide a cleaner - syntax for classical inheritance on top of JavaScript's prototypes: + syntax for classical inheritance on top of JavaScript’s prototypes: Base2, Prototype.js, JS.Class, etc. The libraries provide syntactic sugar, but the built-in inheritance would - be completely usable if it weren't for a couple of small exceptions: - it's awkward to call super (the prototype object's - implementation of the current function), and it's awkward to correctly + be completely usable if it weren’t for a couple of small exceptions: + it’s awkward to call super (the prototype object’s + implementation of the current function), and it’s awkward to correctly set the prototype chain.

    @@ -1571,7 +1612,7 @@

    sam.move(); tom.move(); -
    load
    load
    } Snake.prototype.move = function() { - alert("Slithering..."); + alert("Slithering..."); return Snake.__super__.move.call(this, 5); }; @@ -1612,7 +1653,7 @@

    } Horse.prototype.move = function() { - alert("Galloping..."); + alert("Galloping..."); return Horse.__super__.move.call(this, 45); }; @@ -1620,31 +1661,31 @@

    })(Animal); -sam = new Snake("Sammy the Python"); +sam = new Snake("Sammy the Python"); -tom = new Horse("Tommy the Palomino"); +tom = new Horse("Tommy the Palomino"); sam.move(); tom.move(); -;'>run


    +;">run

    - If structuring your prototypes classically isn't your cup of tea, CoffeeScript + If structuring your prototypes classically isn’t your cup of tea, CoffeeScript provides a couple of lower-level conveniences. The extends operator helps with proper prototype setup, and can be used to create an inheritance chain between any pair of constructor functions; :: gives you - quick access to an object's prototype; and super() - is converted into a call against the immediate ancestor's method of the same name. + quick access to an object’s prototype; and super() + is converted into a call against the immediate ancestor’s method of the same name.

    String::dasherize = ->
       this.replace /_/g, "-"
     
    String.prototype.dasherize = function() {
       return this.replace(/_/g, "-");
     };
    -
    load
    load
    run: "one_two".dasherize()

    +;alert("one_two".dasherize());">run: "one_two".dasherize()

    Finally, class definitions are blocks of executable code, which make for interesting metaprogramming possibilities. Because in the context of a class definition, @@ -1673,16 +1714,16 @@

    theSwitch = 0; ref = [theSwitch, theBait], theBait = ref[0], theSwitch = ref[1]; -
    load
    load
    run: theBait

    - But it's also helpful for dealing with functions that return multiple + But it’s also helpful for dealing with functions that return multiple values.

    weatherReport = (location) ->
    @@ -1697,14 +1738,14 @@ 

    }; ref = weatherReport("Berkeley, CA"), city = ref[0], temp = ref[1], forecast = ref[2]; -

    load
    load
    run: forecast

    +ref = weatherReport("Berkeley, CA"), city = ref[0], temp = ref[1], forecast = ref[2]; +;alert(forecast);">run: forecast

    Destructuring assignment can be used with any depth of array and object nesting, to help pull out deeply nested properties. @@ -1732,19 +1773,19 @@

    }; ref = futurists.poet, name = ref.name, (ref1 = ref.address, street = ref1[0], city = ref1[1]); -
    load
    load
    run: name + "-" + street

    +;alert(name + "-" + street);">run: name + "-" + street

    Destructuring assignment can even be combined with splats.

    @@ -1757,13 +1798,13 @@

    tag = "<impossible>"; ref = tag.split(""), open = ref[0], contents = 3 <= ref.length ? slice.call(ref, 1, i = ref.length - 1) : (i = 1, []), close = ref[i++]; -
    load
    load
    "; +tag = ""; -ref = tag.split(""), open = ref[0], contents = 3 <= ref.length ? slice.call(ref, 1, i = ref.length - 1) : (i = 1, []), close = ref[i++]; -;alert(contents.join(""));'>run: contents.join("")

    +ref = tag.split(""), open = ref[0], contents = 3 <= ref.length ? slice.call(ref, 1, i = ref.length - 1) : (i = 1, []), close = ref[i++]; +;alert(contents.join(""));">run: contents.join("")

    Expansion can be used to retrieve elements from the end of an array without having to assign the rest of its values. It works in function parameter lists as well.

    @@ -1776,12 +1817,12 @@

    text = "Every literary critic believes he will outwit history and have the last word"; ref = text.split(" "), first = ref[0], last = ref[ref.length - 1]; -
    load
    load
    run: first + " " + last

    +ref = text.split(" "), first = ref[0], last = ref[ref.length - 1]; +;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. @@ -1807,7 +1848,7 @@

    name: 'Tim', age: 4 }); -
    load
    load
    run: tim.age + " " + tim.height

    +;alert(tim.age + " " + tim.height);">run: tim.age + " " + tim.height

    The above example also demonstrates that if properties are missing in the destructured object or array, you can, just like in JavaScript, provide @@ -1837,7 +1878,7 @@

    In JavaScript, the this keyword is dynamically scoped to mean the object that the current function is attached to. If you pass a function as a callback or attach it to a different object, the original value of this - will be lost. If you're not familiar with this behavior, + will be lost. If you’re not familiar with this behavior, this Digital Web article gives a good overview of the quirks.

    @@ -1847,7 +1888,7 @@

    when using callback-based libraries like Prototype or jQuery, for creating iterator functions to pass to each, or event-handler functions to use with on. Functions created with the fat arrow are able to access - properties of the this where they're defined. + properties of the this where they’re defined.

    Account = (customer, cart) ->
       @customer = customer
    @@ -1866,10 +1907,10 @@ 

    }; })(this)); }; -

    load

    +
    load

    If we had used -> in the callback above, @customer would - have referred to the undefined "customer" property of the DOM element, + have referred to the undefined “customer” property of the DOM element, and trying to call purchase() on it would have raised an exception.

    @@ -1878,10 +1919,11 @@

    constructed.

    + CoffeeScript functions also support - ES6 generator functions - through the yield keyword. There's no function*(){} - nonsense — a generator in CoffeeScript is simply a function that yields. + ES2015 generator functions + through the yield keyword. There’s no function*(){} + nonsense — a generator in CoffeeScript is simply a function that yields.

    perfectSquares = ->
       num = 0
    @@ -1903,7 +1945,7 @@ 

    }; window.ps || (window.ps = perfectSquares()); -

    load
    load
    run: ps.next().value

    yield* is called yield from, and yield return - may be used if you need to force a generator that doesn't yield. + may be used if you need to force a generator that doesn’t yield.

    +

    + + You can iterate over a generator function using for…from. +

    +
    fibonacci = ->
    +  [previous, current] = [1, 1]
    +  loop
    +    [previous, current] = [current, previous + current]
    +    yield current
    +  return
    +
    +getFibonacciNumbers = (length) ->
    +  results = [1]
    +  for n from fibonacci()
    +    results.push n
    +    break if results.length is length
    +  results
    +
    var fibonacci, getFibonacciNumbers;
    +
    +fibonacci = function*() {
    +  var current, previous, ref, ref1;
    +  ref = [1, 1], previous = ref[0], current = ref[1];
    +  while (true) {
    +    ref1 = [current, previous + current], previous = ref1[0], current = ref1[1];
    +    yield current;
    +  }
    +};
    +
    +getFibonacciNumbers = function(length) {
    +  var n, ref, results;
    +  results = [1];
    +  ref = fibonacci();
    +  for (n of ref) {
    +    results.push(n);
    +    if (results.length === length) {
    +      break;
    +    }
    +  }
    +  return results;
    +};
    +
    load
    run: getFibonacciNumbers(10)

    Embedded JavaScript - Hopefully, you'll never need to use it, but if you ever need to intersperse + Hopefully, you’ll never need to use it, but if you ever need to intersperse snippets of JavaScript within your CoffeeScript, you can use backticks to pass it straight through.

    @@ -1936,12 +2042,55 @@

    hi = function() { return [document.title, "Hello JavaScript"].join(": "); }; -
    load
    load
    run: hi()

    +

    + Escape backticks with backslashes: \` becomes `. +

    +

    + Escape backslashes before backticks with more backslashes: \\\` + becomes \`. +

    +
    markdown = `function () {
    +  return \`In Markdown, write code like \\\`this\\\`\`;
    +}`
    +
    var markdown;
    +
    +markdown = function () {
    +  return `In Markdown, write code like \`this\``;
     };
    -;alert(hi());'>run: hi()

    +
    load
    run: markdown()

    +

    + You can also embed blocks of JavaScript using triple backticks. That’s easier + than escaping backticks, if you need them inside your JavaScript block. +

    +
    ```
    +function time() {
    +  return `The time is ${new Date().toLocaleTimeString()}`;
    +}
    +```
    +
    
    +function time() {
    +  return `The time is ${new Date().toLocaleTimeString()}`;
    +}
    +;
    +
    +
    load
    run: time()

    @@ -1991,7 +2140,7 @@

    default: go(work); } -
    load

    +
    load

    Switch statements can also be used without a control expression, turning them in to a cleaner alternative to if/else chains. @@ -2022,7 +2171,7 @@

    return 'A'; } })(); -
    load

    +
    load

    @@ -2049,14 +2198,14 @@

    } finally { cleanUp(); } -
    load

    +
    load

    Chained Comparisons CoffeeScript borrows chained comparisons - from Python — making it easy to test if a value falls within a + from Python — making it easy to test if a value falls within a certain range.

    cholesterol = 127
    @@ -2067,18 +2216,18 @@ 

    cholesterol = 127; healthy = (200 > cholesterol && cholesterol > 60); -

    load
    load
    run: healthy

    String Interpolation, Block Strings, and Block Comments Ruby-style string interpolation is included in CoffeeScript. Double-quoted - strings allow for interpolated values, using #{ ... }, + strings allow for interpolated values, using #{ … }, and single-quoted strings are literal. You may even use interpolation in object keys.

    @@ -2093,14 +2242,14 @@

    quote = "A picture is a fact. -- " + author; sentence = (22 / 7) + " is a decent approximation of π"; -
    load
    load
    run: sentence

    +sentence = (22 / 7) + " is a decent approximation of π"; +;alert(sentence);">run: sentence

    Multiline strings are allowed in CoffeeScript. Lines are joined by a single space unless they end with a backslash. Indentation is ignored.

    @@ -2113,13 +2262,13 @@

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

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

    Block strings can be used to hold formatted or indentation-sensitive text - (or, if you just don't feel like escaping quotes and apostrophes). The + (or, if you just don’t feel like escaping quotes and apostrophes). The indentation level that begins the block is maintained throughout, so you can keep it all aligned with the body of your code.

    @@ -2131,15 +2280,15 @@

    var html;
     
     html = "<strong>\n  cup of coffeescript\n</strong>";
    -
    load
    load
    \n cup of coffeescript\n"; -;alert(html);'>run: html

    +html = "\n cup of coffeescript\n"; +;alert(html);">run: html

    Double-quoted block strings, like other double-quoted strings, allow interpolation.

    - Sometimes you'd like to pass a block comment through to the generated + Sometimes you’d like to pass a block comment through to the generated JavaScript. For example, when you need to embed a licensing header at the top of a file. Block comments, which mirror the syntax for block strings, are preserved in the generated code. @@ -2154,14 +2303,72 @@

    Released under the MIT License */ -
    load

    +
    load

    + +

    + + Tagged Template Literals + CoffeeScript supports + ES2015 tagged template literals, + which enable customized string interpolation. If you immediately prefix a string + with a function name (no space between the two), CoffeeScript will output this + “function plus string” combination as an ES2015 tagged template literal, which will + behave accordingly: + the function is called, with the parameters being the input text and expression parts + that make up the interpolated string. The function can then assemble these parts + into an output string, providing custom string interpolation. +

    +

    + Be aware that the CoffeeScript compiler is outputting ES2015 syntax for this feature, + so your target JavaScript runtime(s) must support this syntax for your code to work; + or you could use tools like Babel or + Traceur Compiler to convert + this ES2015 syntax into compatible JavaScript. +

    +
    upperCaseExpr = (textParts, expressions...) ->
    +  textParts.reduce (text, textPart, i) ->
    +    text + expressions[i - 1].toUpperCase() + textPart
    +
    +greet = (name, adjective) ->
    +  upperCaseExpr"""
    +               Hi #{name}. You look #{adjective}!
    +               """
    +
    var greet, upperCaseExpr,
    +  slice = [].slice;
    +
    +upperCaseExpr = function() {
    +  var expressions, textParts;
    +  textParts = arguments[0], expressions = 2 <= arguments.length ? slice.call(arguments, 1) : [];
    +  return textParts.reduce(function(text, textPart, i) {
    +    return text + expressions[i - 1].toUpperCase() + textPart;
    +  });
    +};
    +
    +greet = function(name, adjective) {
    +  return upperCaseExpr`Hi ${name}. You look ${adjective}!`;
    +};
    +
    load
    run: greet("greg", "awesome")

    Block Regular Expressions - Similar to block strings and comments, CoffeeScript supports block regexes — + Similar to block strings and comments, CoffeeScript supports block regexes — extended regular expressions that ignore internal whitespace and can contain - comments and interpolation. Modeled after Perl's /x modifier, CoffeeScript's + comments and interpolation. Modeled after Perl’s /x modifier, CoffeeScript’s block regexes are delimited by /// and go a long way towards making complex regular expressions readable. To quote from the CoffeeScript source:

    @@ -2177,7 +2384,7 @@

    var OPERATOR;
     
     OPERATOR = /^(?:[-=]>|[-+*\/%<>&|^!?=]=|>>>=?|([-+:])\1|([&|<>])\2=?|\?\.|\.{2,3})/;
    -
    load

    +
    load

    @@ -2203,7 +2410,7 @@

    export { sqrt } export { sqrt as squareRoot } -export { Mathematics as default, sqrt as squareRoot } +export { Mathematics as default, sqrt as squareRoot } export * from 'underscore' export { max, min } from 'underscore' @@ -2272,8 +2479,9 @@

    max, min } from 'underscore'; -
    load

    +
    load

    + Note that the CoffeeScript compiler does not resolve modules; writing an import or export statement in CoffeeScript will produce an import or export statement in the resulting output. @@ -2299,7 +2507,7 @@

    CoffeeScript includes a (very) simple build system similar to Make and Rake. Naturally, - it's called Cake, and is used for the tasks that build and test the CoffeeScript + it’s called Cake, and is used for the tasks that build and test the CoffeeScript language itself. Tasks are defined in a file named Cakefile, and can be invoked by running cake [task] from within the directory. To print a list of all the tasks and options, just type cake. @@ -2310,8 +2518,8 @@

    in your Cakefile. Define a task with a name, a long description, and the function to invoke when the task is run. If your task takes a command-line option, you can define the option with short and long flags, and it will - be made available in the options object. Here's a task that uses - the Node.js API to rebuild CoffeeScript's parser: + be made available in the options object. Here’s a task that uses + the Node.js API to rebuild CoffeeScript’s parser:

    fs = require 'fs'
     
    @@ -2335,15 +2543,15 @@ 

    dir = options.output || 'lib'; return fs.writeFile(dir + "/parser.js", code); }); -

    load

    +
    load

    - If you need to invoke one task before another — for example, running + If you need to invoke one task before another — for example, running build before test, you can use the invoke function: invoke 'build'. Cake tasks are a minimal way to expose your CoffeeScript functions to the command line, so - don't expect any fanciness built-in. - If you need dependencies, or async callbacks, it's best to put them in your - code itself — not the cake task. + don’t expect any fanciness built-in. + If you need dependencies, or async callbacks, it’s best to put them in your + code itself — not the cake task.

    @@ -2372,16 +2580,16 @@

    - While it's not recommended for serious use, CoffeeScripts may be included + While it’s not recommended for serious use, CoffeeScripts may be included directly within the browser using <script type="text/coffeescript"> tags. The source includes a compressed and minified version of the compiler - (Download current version here, 39k when gzipped) + (Download current version here, 51k when gzipped) as v1/browser-compiler/coffee-script.js. Include this file on a page with inline CoffeeScript tags, and it will compile and evaluate them in order.

    - In fact, the little bit of glue script that runs "Try CoffeeScript" above, + In fact, the little bit of glue script that runs “Try CoffeeScript” above, as well as the jQuery for the menu, is implemented in just this way. View source and look at the bottom of the page to see the example. Including the script also gives you access to CoffeeScript.compile() @@ -2389,7 +2597,7 @@

    - The usual caveats about CoffeeScript apply — your inline scripts will + The usual caveats about CoffeeScript apply — your inline scripts will run within a closure wrapper, so if you want to expose global variables or functions, attach them to the window object.

    @@ -2421,8 +2629,8 @@

  • CoffeeScript: Accelerated JavaScript Development - is Trevor Burnham's thorough - introduction to the language. By the end of the book, you'll have built + is Trevor Burnham’s thorough + introduction to the language. By the end of the book, you’ll have built a fast-paced multiplayer word game, writing both the client-side and Node.js portions in CoffeeScript.
  • @@ -2434,7 +2642,7 @@

  • CoffeeScript Ristretto - is a deep dive into CoffeeScript's semantics from simple functions up through + is a deep dive into CoffeeScript’s semantics from simple functions up through closures, higher-order functions, objects, classes, combinators, and decorators. By Reg Braithwaite.
  • @@ -2448,7 +2656,7 @@

    from Packt, introduces CoffeeScript while walking through the process of building a demonstration web application. A CoffeeScript Application Development Coookbook - with over 90 "recipes" is also available. + with over 90 “recipes” is also available.
  • CoffeeScript in Action @@ -2477,7 +2685,7 @@

    into the equivalent JS.

  • - If you're looking for less of a time commitment, RailsCasts' + If you’re looking for less of a time commitment, RailsCasts’ CoffeeScript Basics should have you covered, hitting all of the important notes about CoffeeScript in 11 minutes. @@ -2496,29 +2704,32 @@

    • - github's Hubot, + GitHub’s Hubot, a friendly IRC robot that can perform any number of useful and useless tasks.
    • - sstephenson's Pow, + sstephenson’s Pow, a zero-configuration Rack server, with comprehensive annotated source.
    • - technoweenie's Coffee-Resque, + technoweenie’s Coffee-Resque, a port of Resque for Node.js.
    • - assaf's Zombie.js, + assaf’s Zombie.js, a headless, full-stack, faux-browser testing library for Node.js.
    • - stephank's Orona, a remake of + stephank’s Orona, a remake of the Bolo tank game for modern browsers.
    • - github's Atom, + GitHub’s Atom, a hackable text editor built on web technologies.
    • +
    • + Basecamp’s Trix, a rich text editor for web apps. +

    @@ -2531,13 +2742,17 @@

    Use bin/coffee to test your changes,
    bin/cake test to run the test suite,
    bin/cake build to rebuild the CoffeeScript compiler, and
    - bin/cake build:parser to regenerate the Jison parser if you're + bin/cake build:parser to regenerate the Jison parser if you’re working on the grammar.

    - git checkout lib && bin/cake build:full is a good command to run when you're working - on the core language. It'll refresh the lib directory + git checkout lib && bin/cake build:full is a good command to run when you’re working + on the core language. It’ll refresh the lib directory (in case you broke something), build your altered compiler, use that to rebuild itself (a good sanity test) and then run all of the tests. If - they pass, there's a good chance you've made a successful change. + they pass, there’s a good chance you’ve made a successful change. +

  • +
  • + Browser Tests
    + Run CoffeeScript’s test suite in your current browser.
  • CoffeeScript Issues
    @@ -2545,11 +2760,11 @@

  • CoffeeScript Google Group
    - If you'd like to ask a question, the mailing list is a good place to get help. + If you’d like to ask a question, the mailing list is a good place to get help.
  • The CoffeeScript Wiki
    - If you've ever learned a neat CoffeeScript tip or trick, or ran into a gotcha — share it on the wiki. + If you’ve ever learned a neat CoffeeScript tip or trick, or ran into a gotcha — share it on the wiki. The wiki also serves as a directory of handy text editor extensions, web framework plugins, @@ -2561,9 +2776,9 @@

  • JS2Coffee
    - Is a very well done reverse JavaScript-to-CoffeeScript compiler. It's + Is a very well done reverse JavaScript-to-CoffeeScript compiler. It’s not going to be perfect (infer what your JavaScript classes are, when - you need bound functions, and so on...) — but it's a great starting + you need bound functions, and so on…) — but it’s a great starting point for converting simple scripts.
  • @@ -2593,6 +2808,63 @@

    Change Log

    +

    +

    + + 1.12.0 + + + +

    +

    @@ -2607,7 +2879,7 @@

    Bugfix for indentation-stripping in """ strings.

  • - Bugfix for not being able to use the name "arguments" for a prototype + Bugfix for not being able to use the name “arguments” for a prototype property of class.
  • @@ -2726,7 +2998,7 @@

    • - CoffeeScript now supports ES6-style destructuring defaults. + CoffeeScript now supports ES2015-style destructuring defaults.
    • (offsetHeight: height) -> no longer compiles. That @@ -2830,7 +3102,7 @@

    • Internal compiler variable names no longer start with underscores. This makes the generated JavaScript a bit prettier, and also fixes an issue with - the completely broken and ungodly way that AngularJS "parses" function + the completely broken and ungodly way that AngularJS “parses” function arguments.
    • @@ -2851,7 +3123,7 @@

      • - CoffeeScript now supports ES6 generators. A generator is simply a function + CoffeeScript now supports ES2015 generators. A generator is simply a function that yields.
      • @@ -2935,7 +3207,7 @@

        • - 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. + 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.
        • Improved error messages, source maps and stack traces. Source maps now use the updated //# syntax. @@ -2953,7 +3225,7 @@

          $('body').click(function(e) {
             return $('.box').fadeIn('fast').addClass('.active');
           }).css('background', 'white');
          -
          load

          +
          load

          • Added **, // and %% operators and ... expansion in parameter lists and destructuring expressions. @@ -2965,7 +3237,7 @@

            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. @@ -3020,7 +3292,7 @@

            running CoffeeScript directly via the coffee command, and for automatic line-mapping when running CoffeeScript directly in the browser. Also, to provide better error messages for semantic errors - thrown by the compiler — + thrown by the compiler — with colors, even.

          • @@ -3053,8 +3325,8 @@

          • Fixed a 1.5.0 regression with multiple implicit calls against an indented implicit object. Combinations of implicit function calls - and implicit objects should generally be parsed better now — - but it still isn't good style to nest them too heavily. + and implicit objects should generally be parsed better now — + but it still isn’t good style to nest them too heavily.
          • .coffee.md is now also supported as a Literate CoffeeScript @@ -3105,7 +3377,7 @@

            • - The CoffeeScript compiler now strips Microsoft's UTF-8 BOM if it + The CoffeeScript compiler now strips Microsoft’s UTF-8 BOM if it exists, allowing you to compile BOM-borked source files.
            • @@ -3127,13 +3399,13 @@

              • - Due to the new semantics of JavaScript's strict mode, CoffeeScript no + Due to the new semantics of JavaScript’s strict mode, CoffeeScript no longer guarantees that constructor functions have names in all runtimes. See #2052 for discussion.
              • - Inside of a nested function inside of an instance method, it's now possible + Inside of a nested function inside of an instance method, it’s now possible to call super more reliably (walks recursively up).
              • @@ -3157,7 +3429,7 @@

                • - CoffeeScript now enforces all of JavaScript's Strict Mode early syntax + CoffeeScript now enforces all of JavaScript’s Strict Mode early syntax errors at compile time. This includes old-style octal literals, duplicate property names in object literals, duplicate parameters in a function definition, deleting naked variables, setting the value of @@ -3167,7 +3439,7 @@

                • The REPL now has a handy new multi-line mode for entering large - blocks of code. It's useful when copy-and-pasting examples into the + blocks of code. It’s useful when copy-and-pasting examples into the REPL. Enter multi-line mode with Ctrl-V. You may also now pipe input directly into the REPL.
                • @@ -3181,7 +3453,7 @@

                • A tweak to the semantics of do, which can now be used to - more easily simulate a namespace: do (x = 1, y = 2) -> ... + more easily simulate a namespace: do (x = 1, y = 2) -> …
                • Loop indices are now mutable within a loop iteration, and immutable @@ -3193,7 +3465,7 @@

                • Additional tweaks and improvements to coffee --watch under - Node's "new" file watching API. Watch will now beep by default + Node’s “new” file watching API. Watch will now beep by default if you introduce a syntax error into a watched script. We also now ignore hidden directories by default when watching recursively.
                • @@ -3210,7 +3482,7 @@

                • Multiple improvements to coffee --watch and --join. You may now use both together, as well as add and remove - files and directories within a --watch'd folder. + files and directories within a --watch’d folder.
                • The throw statement can now be used as part of an expression. @@ -3236,7 +3508,7 @@

                  • - Ahh, whitespace. CoffeeScript's compiled JS now tries to space things + Ahh, whitespace. CoffeeScript’s compiled JS now tries to space things out and keep it readable, as you can see in the examples on this page.
                  • @@ -3255,7 +3527,7 @@

                    folder to your path: require('coffee-script/lexer')

                  • - There's a new "link" feature in Try CoffeeScript on this webpage. Use + There’s a new “link” feature in Try CoffeeScript on this webpage. Use it to get a shareable permalink for your example script.
                  • @@ -3306,10 +3578,10 @@

                    When running via the coffee executable, process.argv and friends now report coffee instead of node. Better compatibility with Node.js 0.4.x module lookup changes. - The output in the REPL is now colorized, like Node's is. + The output in the REPL is now colorized, like Node’s is. Giving your concatenated CoffeeScripts a name when using --join is now mandatory. Fix for lexing compound division /= as a regex accidentally. - All text/coffeescript tags should now execute in the order they're included. + All text/coffeescript tags should now execute in the order they’re included. Fixed an issue with extended subclasses using external constructor functions. Fixed an edge-case infinite loop in addImplicitParentheses. Fixed exponential slowdown with long chains of function calls. @@ -3326,7 +3598,7 @@

                    Fixed a lexer bug with Unicode identifiers. Updated REPL for compatibility with Node.js 0.3.7. Fixed requiring relative paths in the REPL. Trailing return and return undefined are now optimized away. - Stopped requiring the core Node.js "util" module for + Stopped requiring the core Node.js util module for back-compatibility with Node.js 0.2.5. Fixed a case where a conditional return would cause fallthrough in a switch statement. Optimized empty objects in destructuring assignment. @@ -3372,14 +3644,14 @@

                    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 + many contributed from satyr’s Coco dialect of CoffeeScript. Heregexes (extended regexes) were added. Functions can now have default arguments. Class bodies are now executable code. Improved syntax errors for invalid CoffeeScript. undefined now works like null, and cannot be assigned a new value. There was a precedence change with respect to single-line comprehensions: result = i for i in list
                    used to parse as result = (i for i in list) - by default ... it now parses as
                    (result = i) for i in list. + by default … it now parses as
                    (result = i) for i in list.

                    @@ -3402,7 +3674,7 @@

                    CoffeeScript switch statements now compile into JS switch - statements — they previously compiled into if/else chains + statements — they previously compiled into if/else chains for JavaScript 1.3 compatibility. Soaking a function invocation is now supported. Users of the RubyMine editor should now be able to use --watch mode. @@ -3421,7 +3693,7 @@

                    Added a custom jsl.conf file for our preferred JavaScriptLint setup. Sped up Jison grammar compilation time by flattening rules for operations. Block comments can now be used with JavaScript-minifier-friendly syntax. - Added JavaScript's compound assignment bitwise operators. Bugfixes to + Added JavaScript’s compound assignment bitwise operators. Bugfixes to implicit object literals with leading number and string keys, as the subject of implicit calls, and as part of compound assignment.

                    @@ -3434,7 +3706,7 @@

                    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). + String and regex interpolation is now strictly #{ … } (Ruby style). The compiler now takes a --require flag, which specifies scripts to run before compilation.

                    @@ -3446,24 +3718,24 @@

                    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 + for 1.0; let’s give her a shakedown cruise. 0.9.0 introduces a massive backwards-incompatible change: Assignment now uses =, and object literals use :, as in JavaScript. This allows us to have implicit object literals, and YAML-style object definitions. Half assignments are removed, in favor of +=, or=, and friends. Interpolation now uses a hash mark # instead of the dollar sign - $ — because dollar signs may be part of a valid JS identifier. + $ — because dollar signs may be part of a valid JS identifier. Downwards range comprehensions are now safe again, and are optimized to straight for loops when created with integer endpoints. A fast, unguarded form of object comprehension was added: for all key, value of object. Mentioning the super keyword with no arguments now forwards all arguments passed to the function, as in Ruby. If you extend class B from parent class A, if - A has an extended method defined, it will be called, passing in B — + A has an extended method defined, it will be called, passing in B — this enables static inheritance, among other things. Cleaner output for functions bound with the fat arrow. @variables can now be used in parameter lists, with the parameter being automatically set as a property - on the object — useful in constructors and setter functions. + on the object — useful in constructors and setter functions. Constructor functions can now take splats.

                    @@ -3484,7 +3756,7 @@

                    Block-style comments are now passed through and printed as JavaScript block - comments -- making them useful for licenses and copyright headers. Better + comments – making them useful for licenses and copyright headers. Better support for running coffee scripts standalone via hashbangs. Improved syntax errors for tokens that are not in the grammar.

                    @@ -3498,7 +3770,7 @@

                    Official CoffeeScript variable style is now camelCase, as in JavaScript. Reserved words are now allowed as object keys, and will be quoted for you. Range comprehensions now generate cleaner code, but you have to specify by -1 - if you'd like to iterate downward. Reporting of syntax errors is greatly + if you’d like to iterate downward. Reporting of syntax errors is greatly improved from the previous release. Running coffee with no arguments now launches the REPL, with Readline support. The <- bind operator has been removed from CoffeeScript. The loop keyword was added, @@ -3519,7 +3791,7 @@

                    The coffee command will now preserve directory structure when compiling a directory full of scripts. Fixed two omissions that were preventing the CoffeeScript compiler from running live within Internet Explorer. - There's now a syntax for block comments, similar in spirit to CoffeeScript's heredocs. + There’s now a syntax for block comments, similar in spirit to CoffeeScript’s heredocs. ECMA Harmony DRY-style pattern matching is now supported, where the name of the property is the same as the name of the value: {name, length}: func. Pattern matching is now allowed within comprehension variables. unless @@ -3575,7 +3847,7 @@

                    Stan Angeloff. Since --run has been the default since 0.5.3, updating --stdio and --eval to run by default, pass --compile - as well if you'd like to print the result. + as well if you’d like to print the result.

                    @@ -3610,7 +3882,7 @@

                    Added a compressed version of the compiler for inclusion in web pages as -
                    v1/browser-compiler/coffee-script.js. It'll automatically run any script tags +
                    v1/browser-compiler/coffee-script.js. It’ll automatically run any script tags with type text/coffeescript for you. Added a --stdio option to the coffee command, for piped-in compiles.

                    @@ -3647,7 +3919,7 @@

                    @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. + the --narwhal flag if you’d like to continue using it.

                    @@ -3688,7 +3960,7 @@

                    0.2.5 - The conditions in switch statements can now take multiple values at once — + The conditions in switch statements can now take multiple values at once — If any of them are true, the case will run. Added the long arrow ==>, which defines and immediately binds a function to this. While loops can now be used as expressions, in the same way that comprehensions can. Splats @@ -3728,17 +4000,17 @@


                    Added :: as a shorthand for saying .prototype.
                    - The "splat" symbol has been changed from a prefix asterisk *, to + The “splat” symbol has been changed from a prefix asterisk *, to a postfix ellipsis ...
                    - Added JavaScript's in operator, + Added JavaScript’s in operator, empty return statements, and empty while loops.
                    Constructor functions that start with capital letters now include a safety check to make sure that the new instance of the object is returned.
                    The extends keyword now functions identically to goog.inherits - in Google's Closure Library. + in Google’s Closure Library.

                    @@ -3760,7 +4032,7 @@

                    conversion. Splats. Splice literals. Object comprehensions. Blocks. The existential operator. Many thanks to all the folks who posted issues, with special thanks to - Liam O'Connor-Davis for whitespace + Liam O’Connor-Davis for whitespace and expression help.

                    @@ -3832,7 +4104,7 @@

                    inheritance, with the re-addition of the extends keyword. Added experimental Narwhal support (as a Tusk package), contributed by - Tom Robinson, including + Tom Robinson, including bin/cs as a CoffeeScript REPL and interpreter. New --no-wrap option to suppress the safety function wrapper. diff --git a/docs/v1/test.html b/docs/v1/test.html new file mode 100644 index 0000000000..bece44991f --- /dev/null +++ b/docs/v1/test.html @@ -0,0 +1,9897 @@ + + + + + CoffeeScript Test Suite + + + + + + +

                    CoffeeScript Test Suite

                    + +
                    
                    +
                    +
                    +
                    +
                    +
                    +
                    +
                    +
                    +
                    +
                    +
                    +
                    +
                    +
                    +
                    +
                    +
                    +
                    +
                    +
                    +
                    +
                    +
                    +
                    +
                    +
                    +
                    +
                    +
                    +
                    +
                    +
                    +
                    +
                    +
                    +
                    +
                    +
                    +
                    +
                    +
                    +
                    +
                    +
                    diff --git a/documentation/index.html b/documentation/index.html
                    index 3b6b462da4..13b9bc37e2 100644
                    --- a/documentation/index.html
                    +++ b/documentation/index.html
                    @@ -28,7 +28,7 @@
                             Literals: Functions, Objects and Arrays
                             Lexical Scoping and Variable Safety
                             If, Else, Unless, and Conditional Assignment
                    -        Splats...
                    +        Splats…
                             Loops and Comprehensions
                             Array Slicing and Splicing
                             Everything is an Expression
                    @@ -77,18 +77,18 @@
                             Annotated Source
                           
                           
                         
                       
                    @@ -104,7 +104,7 @@
                         

                    - The golden rule of CoffeeScript is: "It's just JavaScript". The code + The golden rule of CoffeeScript is: “It’s just JavaScript”. The code compiles one-to-one into the equivalent JS, and there is no interpretation at runtime. You can use any existing JavaScript library seamlessly from CoffeeScript (and vice-versa). The compiled output is @@ -116,7 +116,7 @@ The CoffeeScript compiler goes to great lengths to generate output JavaScript that runs in every JavaScript runtime, but there are exceptions. Use generator functions, - for…from, or + for…from, or tagged template literals only if you know that your target runtimes can support them. If you use modules, @@ -126,7 +126,7 @@

                    Latest Version: - 1.11.1 + <%= fullVersion %>

                    npm install -g coffee-script
                    @@ -153,7 +153,7 @@

                    Node.js utility. The core compiler however, does not depend on Node, and can be run in any JavaScript environment, or in the - browser (see "Try CoffeeScript", above). + browser (see “Try CoffeeScript”, above).

                    @@ -173,7 +173,7 @@

                    npm install --save coffee-script

                    - If you'd prefer to install the latest master version of CoffeeScript, you + If you’d prefer to install the latest master version of CoffeeScript, you can clone the CoffeeScript source repository from GitHub, or download @@ -185,7 +185,7 @@

                    npm install -g jashkenas/coffeescript

                    - Or, if you want to install to /usr/local, and don't want to use + Or, if you want to install to /usr/local, and don’t want to use npm to manage it, open the coffee-script directory and run:

                    @@ -334,7 +334,7 @@

                    --no-header - Suppress the "Generated by CoffeeScript" header. + Suppress the “Generated by CoffeeScript” header. @@ -378,10 +378,10 @@

                    Besides being used as an ordinary programming language, CoffeeScript may - also be written in "literate" mode. If you name your file with a - .litcoffee extension, you can write it as a Markdown document — + also be written in “literate” mode. If you name your file with a + .litcoffee extension, you can write it as a Markdown document — a document that also happens to be executable CoffeeScript code. The compiler - will treat any indented blocks (Markdown's way of indicating source code) + will treat any indented blocks (Markdown’s way of indicating source code) as code, and ignore the rest as comments.

                    @@ -394,7 +394,7 @@

                    - I'm fairly excited about this direction for the language, and am looking + I’m fairly excited about this direction for the language, and am looking forward to writing (and more importantly, reading) more programs in this style. More information about Literate CoffeeScript, including an example program, @@ -419,12 +419,12 @@

                    Many of the examples can be run (where it makes sense) by pressing the run - button on the right, and can be loaded into the "Try CoffeeScript" + button on the right, and can be loaded into the “Try CoffeeScript” console by pressing the load button on the left.

                    First, the basics: CoffeeScript uses significant whitespace to delimit blocks of code. - You don't need to use semicolons ; to terminate expressions, + You don’t need to use semicolons ; to terminate expressions, ending the line will do just as well (although semicolons can still be used to fit multiple expressions onto a single line). Instead of using curly braces @@ -435,7 +435,7 @@

                    - You don't need to use parentheses to invoke a function if you're passing + You don’t need to use parentheses to invoke a function if you’re passing arguments. The implicit call wraps forward to the end of the line or block expression.
                    console.log sys.inspect objectconsole.log(sys.inspect(object));

                    @@ -462,11 +462,11 @@

                    the commas are optional. Objects may be created using indentation instead of explicit braces, similar to YAML.

                    - <%= codeFor('objects_and_arrays', 'song.join(" ... ")') %> + <%= codeFor('objects_and_arrays', 'song.join(" … ")') %>

                    - In JavaScript, you can't use reserved words, like class, as properties + In JavaScript, you can’t use reserved words, like class, as properties of an object, without quoting them as strings. CoffeeScript notices reserved words - used as keys in objects and quotes them for you, so you don't have to worry + used as keys in objects and quotes them for you, so you don’t have to worry about it (say, when using jQuery).

                    <%= codeFor('objects_reserved') %> @@ -480,34 +480,34 @@

                    Lexical Scoping and Variable Safety The CoffeeScript compiler takes care to make sure that all of your variables - are properly declared within lexical scope — you never need to write + are properly declared within lexical scope — you never need to write var yourself.

                    <%= codeFor('scope', 'inner') %>

                    Notice how all of the variable declarations have been pushed up to the top of the closest scope, the first time they appear. - outer is not redeclared within the inner function, because it's + outer is not redeclared within the inner function, because it’s already in scope; inner within the function, on the other hand, should not be able to change the value of the external variable of the same name, and therefore has a declaration of its own.

                    - This behavior is effectively identical to Ruby's scope for local variables. - Because you don't have direct access to the var keyword, - it's impossible to shadow an outer variable on purpose, you may only refer - to it. So be careful that you're not reusing the name of an external - variable accidentally, if you're writing a deeply nested function. + This behavior is effectively identical to Ruby’s scope for local variables. + Because you don’t have direct access to the var keyword, + it’s impossible to shadow an outer variable on purpose, you may only refer + to it. So be careful that you’re not reusing the name of an external + variable accidentally, if you’re writing a deeply nested function.

                    Although suppressed within this documentation for clarity, all CoffeeScript output is wrapped in an anonymous function: - (function(){ ... })(); This safety wrapper, combined with the + (function(){ … })(); This safety wrapper, combined with the automatic generation of the var keyword, make it exceedingly difficult to pollute the global namespace by accident.

                    - If you'd like to create top-level variables for other scripts to use, + If you’d like to create top-level variables for other scripts to use, attach them as properties on window; attach them as properties on the exports object in CommonJS; or use an export statement. If you’re targeting both CommonJS and the browser, the @@ -520,20 +520,20 @@

                    If, Else, Unless, and Conditional Assignment If/else statements can be written without the use of parentheses and curly brackets. As with functions and other block expressions, - multi-line conditionals are delimited by indentation. There's also a handy + multi-line conditionals are delimited by indentation. There’s also a handy postfix form, with the if or unless at the end.

                    CoffeeScript can compile if statements into JavaScript expressions, using the ternary operator when possible, and closure wrapping otherwise. There - is no explicit ternary statement in CoffeeScript — you simply use + is no explicit ternary statement in CoffeeScript — you simply use a regular if statement on a single line.

                    <%= codeFor('conditionals') %>

                    - Splats... + Splats… The JavaScript arguments object is a useful way to work with functions that accept variable numbers of arguments. CoffeeScript provides splats ..., both for function definition as well as invocation, @@ -544,7 +544,7 @@

                    Loops and Comprehensions - Most of the loops you'll write in CoffeeScript will be comprehensions + Most of the loops you’ll write in CoffeeScript will be comprehensions over arrays, objects, and ranges. Comprehensions replace (and compile into) for loops, with optional guard clauses and the value of the current array index. Unlike for loops, array comprehensions are expressions, and can be returned @@ -564,9 +564,9 @@

                    Note how because we are assigning the value of the comprehensions to a variable in the example above, CoffeeScript is collecting the result of each iteration into an array. Sometimes functions end with loops that are - intended to run only for their side-effects. Be careful that you're not + intended to run only for their side-effects. Be careful that you’re not accidentally returning the results of the comprehension in these cases, - by adding a meaningful return value — like true — or null, + by adding a meaningful return value — like true — or null, to the bottom of your function.

                    @@ -575,7 +575,7 @@

                    evens = (x for x in [0..10] by 2)

                    - If you don't need the current iteration value you may omit it:
                    + If you don’t need the current iteration value you may omit it:
                    browser.closeCurrentTab() for [0...count]

                    @@ -605,9 +605,9 @@

                    and the loop keyword is equivalent to while true.

                    - When using a JavaScript loop to generate functions, it's common to insert + When using a JavaScript loop to generate functions, it’s common to insert a closure wrapper in order to ensure that loop variables are closed over, - and all the generated functions don't just share the final values. CoffeeScript + and all the generated functions don’t just share the final values. CoffeeScript provides the do keyword, which immediately invokes a passed function, forwarding any arguments.

                    @@ -629,12 +629,12 @@

                    <%= codeFor('splices', 'numbers') %>

                    - Note that JavaScript strings are immutable, and can't be spliced. + Note that JavaScript strings are immutable, and can’t be spliced.

                    Everything is an Expression (at least, as much as possible) - You might have noticed how even though we don't add return statements + You might have noticed how even though we don’t add return statements to CoffeeScript functions, they nonetheless return their final value. The CoffeeScript compiler tries to make sure that all statements in the language can be used as expressions. Watch how the return gets @@ -643,13 +643,13 @@

                    <%= codeFor('expressions', 'eldest') %>

                    - Even though functions will always return their final value, it's both possible + Even though functions will always return their final value, it’s both possible and encouraged to return early from a function body writing out the explicit - return (return value), when you know that you're done. + return (return value), when you know that you’re done.

                    Because variable declarations occur at the top of scope, assignment can - be used within expressions, even for variables that haven't been seen before: + be used within expressions, even for variables that haven’t been seen before:

                    <%= codeFor('expressions_assignment', 'six') %>

                    @@ -665,10 +665,10 @@

                    <%= codeFor('expressions_try', true) %>

                    - There are a handful of statements in JavaScript that can't be meaningfully + There are a handful of statements in JavaScript that can’t be meaningfully converted into expressions, namely break, continue, and return. If you make use of them within a block of code, - CoffeeScript won't try to perform the conversion. + CoffeeScript won’t try to perform the conversion.

                    @@ -740,11 +740,11 @@

                    The Existential Operator - It's a little difficult to check for the existence of a variable in - JavaScript. if (variable) ... comes close, but fails for zero, - the empty string, and false. CoffeeScript's existential operator ? returns true unless + It’s a little difficult to check for the existence of a variable in + JavaScript. if (variable) … comes close, but fails for zero, + the empty string, and false. CoffeeScript’s existential operator ? returns true unless a variable is null or undefined, which makes it analogous - to Ruby's nil? + to Ruby’s nil?

                    It can also be used for safer conditional assignment than ||= @@ -755,13 +755,13 @@

                    The accessor variant of the existential operator ?. can be used to soak up null references in a chain of properties. Use it instead of the dot accessor . in cases where the base value may be null - or undefined. If all of the properties exist then you'll get the expected + or undefined. If all of the properties exist then you’ll get the expected result, if the chain is broken, undefined is returned instead of the TypeError that would be raised otherwise.

                    <%= codeFor('soaks') %>

                    - Soaking up nulls is similar to Ruby's + Soaking up nulls is similar to Ruby’s andand gem, and to the safe navigation operator in Groovy. @@ -770,16 +770,16 @@

                    Classes, Inheritance, and Super - JavaScript's prototypal inheritance has always been a bit of a + JavaScript’s prototypal inheritance has always been a bit of a brain-bender, with a whole family tree of libraries that provide a cleaner - syntax for classical inheritance on top of JavaScript's prototypes: + syntax for classical inheritance on top of JavaScript’s prototypes: Base2, Prototype.js, JS.Class, etc. The libraries provide syntactic sugar, but the built-in inheritance would - be completely usable if it weren't for a couple of small exceptions: - it's awkward to call super (the prototype object's - implementation of the current function), and it's awkward to correctly + be completely usable if it weren’t for a couple of small exceptions: + it’s awkward to call super (the prototype object’s + implementation of the current function), and it’s awkward to correctly set the prototype chain.

                    @@ -794,12 +794,12 @@

                    <%= codeFor('classes', true) %>

                    - If structuring your prototypes classically isn't your cup of tea, CoffeeScript + If structuring your prototypes classically isn’t your cup of tea, CoffeeScript provides a couple of lower-level conveniences. The extends operator helps with proper prototype setup, and can be used to create an inheritance chain between any pair of constructor functions; :: gives you - quick access to an object's prototype; and super() - is converted into a call against the immediate ancestor's method of the same name. + quick access to an object’s prototype; and super() + is converted into a call against the immediate ancestor’s method of the same name.

                    <%= codeFor('prototypes', '"one_two".dasherize()') %>

                    @@ -821,7 +821,7 @@

                    <%= codeFor('parallel_assignment', 'theBait') %>

                    - But it's also helpful for dealing with functions that return multiple + But it’s also helpful for dealing with functions that return multiple values.

                    <%= codeFor('multiple_return_values', 'forecast') %> @@ -856,7 +856,7 @@

                    In JavaScript, the this keyword is dynamically scoped to mean the object that the current function is attached to. If you pass a function as a callback or attach it to a different object, the original value of this - will be lost. If you're not familiar with this behavior, + will be lost. If you’re not familiar with this behavior, this Digital Web article gives a good overview of the quirks.

                    @@ -866,12 +866,12 @@

                    when using callback-based libraries like Prototype or jQuery, for creating iterator functions to pass to each, or event-handler functions to use with on. Functions created with the fat arrow are able to access - properties of the this where they're defined. + properties of the this where they’re defined.

                    <%= codeFor('fat_arrow') %>

                    If we had used -> in the callback above, @customer would - have referred to the undefined "customer" property of the DOM element, + have referred to the undefined “customer” property of the DOM element, and trying to call purchase() on it would have raised an exception.

                    @@ -883,24 +883,24 @@

                    CoffeeScript functions also support ES2015 generator functions - through the yield keyword. There's no function*(){} - nonsense — a generator in CoffeeScript is simply a function that yields. + through the yield keyword. There’s no function*(){} + nonsense — a generator in CoffeeScript is simply a function that yields.

                    <%= codeFor('generators', 'ps.next().value') %>

                    yield* is called yield from, and yield return - may be used if you need to force a generator that doesn't yield. + may be used if you need to force a generator that doesn’t yield.

                    - You can iterate over a generator function using for…from. + You can iterate over a generator function using for…from.

                    <%= codeFor('generator_iteration', 'getFibonacciNumbers(10)') %>

                    Embedded JavaScript - Hopefully, you'll never need to use it, but if you ever need to intersperse + Hopefully, you’ll never need to use it, but if you ever need to intersperse snippets of JavaScript within your CoffeeScript, you can use backticks to pass it straight through.

                    @@ -914,7 +914,7 @@

                    <%= codeFor('embedded_escaped', 'markdown()') %>

                    - You can also embed blocks of JavaScript using triple backticks. That's easier + You can also embed blocks of JavaScript using triple backticks. That’s easier than escaping backticks, if you need them inside your JavaScript block.

                    <%= codeFor('embedded_block', 'time()') %> @@ -955,7 +955,7 @@

                    Chained Comparisons CoffeeScript borrows chained comparisons - from Python — making it easy to test if a value falls within a + from Python — making it easy to test if a value falls within a certain range.

                    <%= codeFor('comparisons', 'healthy') %> @@ -964,7 +964,7 @@

                    String Interpolation, Block Strings, and Block Comments Ruby-style string interpolation is included in CoffeeScript. Double-quoted - strings allow for interpolated values, using #{ ... }, + strings allow for interpolated values, using #{ … }, and single-quoted strings are literal. You may even use interpolation in object keys.

                    @@ -975,7 +975,7 @@

                    <%= codeFor('strings', 'mobyDick') %>

                    Block strings can be used to hold formatted or indentation-sensitive text - (or, if you just don't feel like escaping quotes and apostrophes). The + (or, if you just don’t feel like escaping quotes and apostrophes). The indentation level that begins the block is maintained throughout, so you can keep it all aligned with the body of your code.

                    @@ -984,7 +984,7 @@

                    Double-quoted block strings, like other double-quoted strings, allow interpolation.

                    - Sometimes you'd like to pass a block comment through to the generated + Sometimes you’d like to pass a block comment through to the generated JavaScript. For example, when you need to embed a licensing header at the top of a file. Block comments, which mirror the syntax for block strings, are preserved in the generated code. @@ -998,7 +998,7 @@

                    ES2015 tagged template literals, which enable customized string interpolation. If you immediately prefix a string with a function name (no space between the two), CoffeeScript will output this - 'function plus string' combination as an ES2015 tagged template literal, which will + “function plus string” combination as an ES2015 tagged template literal, which will behave accordingly: the function is called, with the parameters being the input text and expression parts that make up the interpolated string. The function can then assemble these parts @@ -1016,9 +1016,9 @@

                    Block Regular Expressions - Similar to block strings and comments, CoffeeScript supports block regexes — + Similar to block strings and comments, CoffeeScript supports block regexes — extended regular expressions that ignore internal whitespace and can contain - comments and interpolation. Modeled after Perl's /x modifier, CoffeeScript's + comments and interpolation. Modeled after Perl’s /x modifier, CoffeeScript’s block regexes are delimited by /// and go a long way towards making complex regular expressions readable. To quote from the CoffeeScript source:

                    @@ -1058,7 +1058,7 @@

                    CoffeeScript includes a (very) simple build system similar to Make and Rake. Naturally, - it's called Cake, and is used for the tasks that build and test the CoffeeScript + it’s called Cake, and is used for the tasks that build and test the CoffeeScript language itself. Tasks are defined in a file named Cakefile, and can be invoked by running cake [task] from within the directory. To print a list of all the tasks and options, just type cake. @@ -1069,18 +1069,18 @@

                    in your Cakefile. Define a task with a name, a long description, and the function to invoke when the task is run. If your task takes a command-line option, you can define the option with short and long flags, and it will - be made available in the options object. Here's a task that uses - the Node.js API to rebuild CoffeeScript's parser: + be made available in the options object. Here’s a task that uses + the Node.js API to rebuild CoffeeScript’s parser:

                    <%= codeFor('cake_tasks') %>

                    - If you need to invoke one task before another — for example, running + If you need to invoke one task before another — for example, running build before test, you can use the invoke function: invoke 'build'. Cake tasks are a minimal way to expose your CoffeeScript functions to the command line, so - don't expect any fanciness built-in. - If you need dependencies, or async callbacks, it's best to put them in your - code itself — not the cake task. + don’t expect any fanciness built-in. + If you need dependencies, or async callbacks, it’s best to put them in your + code itself — not the cake task.

                    @@ -1109,16 +1109,16 @@

                    - While it's not recommended for serious use, CoffeeScripts may be included + While it’s not recommended for serious use, CoffeeScripts may be included directly within the browser using <script type="text/coffeescript"> tags. The source includes a compressed and minified version of the compiler - (Download current version here, 39k when gzipped) + (Download current version here, 51k when gzipped) as v<%= majorVersion %>/browser-compiler/coffee-script.js. Include this file on a page with inline CoffeeScript tags, and it will compile and evaluate them in order.

                    - In fact, the little bit of glue script that runs "Try CoffeeScript" above, + In fact, the little bit of glue script that runs “Try CoffeeScript” above, as well as the jQuery for the menu, is implemented in just this way. View source and look at the bottom of the page to see the example. Including the script also gives you access to CoffeeScript.compile() @@ -1126,7 +1126,7 @@

                    - The usual caveats about CoffeeScript apply — your inline scripts will + The usual caveats about CoffeeScript apply — your inline scripts will run within a closure wrapper, so if you want to expose global variables or functions, attach them to the window object.

                    @@ -1158,8 +1158,8 @@

                  • CoffeeScript: Accelerated JavaScript Development - is Trevor Burnham's thorough - introduction to the language. By the end of the book, you'll have built + is Trevor Burnham’s thorough + introduction to the language. By the end of the book, you’ll have built a fast-paced multiplayer word game, writing both the client-side and Node.js portions in CoffeeScript.
                  • @@ -1171,7 +1171,7 @@

                  • CoffeeScript Ristretto - is a deep dive into CoffeeScript's semantics from simple functions up through + is a deep dive into CoffeeScript’s semantics from simple functions up through closures, higher-order functions, objects, classes, combinators, and decorators. By Reg Braithwaite.
                  • @@ -1185,7 +1185,7 @@

                    from Packt, introduces CoffeeScript while walking through the process of building a demonstration web application. A CoffeeScript Application Development Coookbook - with over 90 "recipes" is also available. + with over 90 “recipes” is also available.
                  • CoffeeScript in Action @@ -1214,7 +1214,7 @@

                    into the equivalent JS.

                  • - If you're looking for less of a time commitment, RailsCasts' + If you’re looking for less of a time commitment, RailsCasts’ CoffeeScript Basics should have you covered, hitting all of the important notes about CoffeeScript in 11 minutes. @@ -1233,29 +1233,32 @@

                    • - github's Hubot, + GitHub’s Hubot, a friendly IRC robot that can perform any number of useful and useless tasks.
                    • - sstephenson's Pow, + sstephenson’s Pow, a zero-configuration Rack server, with comprehensive annotated source.
                    • - technoweenie's Coffee-Resque, + technoweenie’s Coffee-Resque, a port of Resque for Node.js.
                    • - assaf's Zombie.js, + assaf’s Zombie.js, a headless, full-stack, faux-browser testing library for Node.js.
                    • - stephank's Orona, a remake of + stephank’s Orona, a remake of the Bolo tank game for modern browsers.
                    • - github's Atom, + GitHub’s Atom, a hackable text editor built on web technologies.
                    • +
                    • + Basecamp’s Trix, a rich text editor for web apps. +

                    @@ -1268,13 +1271,17 @@

                    Use bin/coffee to test your changes,
                    bin/cake test to run the test suite,
                    bin/cake build to rebuild the CoffeeScript compiler, and
                    - bin/cake build:parser to regenerate the Jison parser if you're + bin/cake build:parser to regenerate the Jison parser if you’re working on the grammar.

                    - git checkout lib && bin/cake build:full is a good command to run when you're working - on the core language. It'll refresh the lib directory + git checkout lib && bin/cake build:full is a good command to run when you’re working + on the core language. It’ll refresh the lib directory (in case you broke something), build your altered compiler, use that to rebuild itself (a good sanity test) and then run all of the tests. If - they pass, there's a good chance you've made a successful change. + they pass, there’s a good chance you’ve made a successful change. +

                  • +
                  • + Browser Tests
                    + Run CoffeeScript’s test suite in your current browser.
                  • CoffeeScript Issues
                    @@ -1282,11 +1289,11 @@

                  • CoffeeScript Google Group
                    - If you'd like to ask a question, the mailing list is a good place to get help. + If you’d like to ask a question, the mailing list is a good place to get help.
                  • The CoffeeScript Wiki
                    - If you've ever learned a neat CoffeeScript tip or trick, or ran into a gotcha — share it on the wiki. + If you’ve ever learned a neat CoffeeScript tip or trick, or ran into a gotcha — share it on the wiki. The wiki also serves as a directory of handy text editor extensions, web framework plugins, @@ -1298,9 +1305,9 @@

                  • JS2Coffee
                    - Is a very well done reverse JavaScript-to-CoffeeScript compiler. It's + Is a very well done reverse JavaScript-to-CoffeeScript compiler. It’s not going to be perfect (infer what your JavaScript classes are, when - you need bound functions, and so on...) — but it's a great starting + you need bound functions, and so on…) — but it’s a great starting point for converting simple scripts.
                  • @@ -1330,6 +1337,59 @@

                    Change Log

                    +

                    + <%= releaseHeader('2016-12-04', '1.12.0', '1.11.1') %> +

                      +
                    • + CoffeeScript now supports ES2015 + tagged template literals. + Note that using tagged template literals in your code + makes you responsible for ensuring that either your runtime supports + tagged template literals or that you transpile the output JavaScript + further to a version your target runtime(s) support. +
                    • +
                    • + CoffeeScript now provides a + for…from + syntax for outputting ES2015 + + for…of. (Sorry they couldn’t match, + but we came up with for…of first for something + else.) This allows iterating over generators or any other iterable + object. Note that using for…from in your code + makes you responsible for ensuring that either your runtime supports + for…from or that you transpile the output + JavaScript further to a version your target runtime(s) support. +
                    • +
                    • + Triple backticks (```) allow the creation of embedded + JavaScript blocks where escaping single backticks is not required, + which should improve interoperability with ES2015 template literals + and with Markdown. +
                    • +
                    • + Within single-backtick embedded JavaScript, backticks can now be + escaped via \`. +
                    • +
                    • + The browser tests now run in the browser again, and are accessible + here if you would like + to test your browser. +
                    • +
                    • + CoffeeScript-only keywords in ES2015 imports and + exports are now ignored. +
                    • +
                    • + The compiler now throws an error on trying to export an anonymous class. +
                    • +
                    • + Bugfixes related to tokens and location data, for better source maps + and improved compatibility with downstream tools. +
                    • +
                    +

                    +

                    <%= releaseHeader('2016-10-02', '1.11.1', '1.11.0') %>

                      @@ -1340,7 +1400,7 @@

                      Bugfix for indentation-stripping in """ strings.
                    • - Bugfix for not being able to use the name "arguments" for a prototype + Bugfix for not being able to use the name “arguments” for a prototype property of class.
                    • @@ -1543,7 +1603,7 @@

                    • Internal compiler variable names no longer start with underscores. This makes the generated JavaScript a bit prettier, and also fixes an issue with - the completely broken and ungodly way that AngularJS "parses" function + the completely broken and ungodly way that AngularJS “parses” function arguments.
                    • @@ -1632,7 +1692,7 @@

                      <%= releaseHeader('2014-01-28', '1.7.0', '1.6.3') %>
                      • - When requiring CoffeeScript files in Node you must now explicitly register the compiler. This can be done with require 'coffee-script/register' or CoffeeScript.register(). Also for configuration such as Mocha's, use coffee-script/register. + 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.
                      • Improved error messages, source maps and stack traces. Source maps now use the updated //# syntax. @@ -1653,7 +1713,7 @@

                        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. @@ -1700,7 +1760,7 @@

                        running CoffeeScript directly via the coffee command, and for automatic line-mapping when running CoffeeScript directly in the browser. Also, to provide better error messages for semantic errors - thrown by the compiler — + thrown by the compiler — with colors, even.

                      • @@ -1729,8 +1789,8 @@

                      • Fixed a 1.5.0 regression with multiple implicit calls against an indented implicit object. Combinations of implicit function calls - and implicit objects should generally be parsed better now — - but it still isn't good style to nest them too heavily. + and implicit objects should generally be parsed better now — + but it still isn’t good style to nest them too heavily.
                      • .coffee.md is now also supported as a Literate CoffeeScript @@ -1773,7 +1833,7 @@

                        <%= releaseHeader('2012-10-23', '1.4.0', '1.3.3') %>
                        • - The CoffeeScript compiler now strips Microsoft's UTF-8 BOM if it + The CoffeeScript compiler now strips Microsoft’s UTF-8 BOM if it exists, allowing you to compile BOM-borked source files.
                        • @@ -1791,13 +1851,13 @@

                          <%= releaseHeader('2012-05-15', '1.3.3', '1.3.1') %>
                          • - Due to the new semantics of JavaScript's strict mode, CoffeeScript no + Due to the new semantics of JavaScript’s strict mode, CoffeeScript no longer guarantees that constructor functions have names in all runtimes. See #2052 for discussion.
                          • - Inside of a nested function inside of an instance method, it's now possible + Inside of a nested function inside of an instance method, it’s now possible to call super more reliably (walks recursively up).
                          • @@ -1817,7 +1877,7 @@

                            <%= releaseHeader('2012-04-10', '1.3.1', '1.2.0') %>
                            • - CoffeeScript now enforces all of JavaScript's Strict Mode early syntax + CoffeeScript now enforces all of JavaScript’s Strict Mode early syntax errors at compile time. This includes old-style octal literals, duplicate property names in object literals, duplicate parameters in a function definition, deleting naked variables, setting the value of @@ -1827,7 +1887,7 @@

                            • The REPL now has a handy new multi-line mode for entering large - blocks of code. It's useful when copy-and-pasting examples into the + blocks of code. It’s useful when copy-and-pasting examples into the REPL. Enter multi-line mode with Ctrl-V. You may also now pipe input directly into the REPL.
                            • @@ -1841,7 +1901,7 @@

                            • A tweak to the semantics of do, which can now be used to - more easily simulate a namespace: do (x = 1, y = 2) -> ... + more easily simulate a namespace: do (x = 1, y = 2) -> …
                            • Loop indices are now mutable within a loop iteration, and immutable @@ -1853,7 +1913,7 @@

                            • Additional tweaks and improvements to coffee --watch under - Node's "new" file watching API. Watch will now beep by default + Node’s “new” file watching API. Watch will now beep by default if you introduce a syntax error into a watched script. We also now ignore hidden directories by default when watching recursively.
                            • @@ -1866,7 +1926,7 @@

                            • Multiple improvements to coffee --watch and --join. You may now use both together, as well as add and remove - files and directories within a --watch'd folder. + files and directories within a --watch’d folder.
                            • The throw statement can now be used as part of an expression. @@ -1888,7 +1948,7 @@

                              <%= releaseHeader('2011-11-08', '1.1.3', '1.1.2') %>
                              • - Ahh, whitespace. CoffeeScript's compiled JS now tries to space things + Ahh, whitespace. CoffeeScript’s compiled JS now tries to space things out and keep it readable, as you can see in the examples on this page.
                              • @@ -1907,7 +1967,7 @@

                                folder to your path: require('coffee-script/lexer')

                              • - There's a new "link" feature in Try CoffeeScript on this webpage. Use + There’s a new “link” feature in Try CoffeeScript on this webpage. Use it to get a shareable permalink for your example script.
                              • @@ -1946,10 +2006,10 @@

                                When running via the coffee executable, process.argv and friends now report coffee instead of node. Better compatibility with Node.js 0.4.x module lookup changes. - The output in the REPL is now colorized, like Node's is. + The output in the REPL is now colorized, like Node’s is. Giving your concatenated CoffeeScripts a name when using --join is now mandatory. Fix for lexing compound division /= as a regex accidentally. - All text/coffeescript tags should now execute in the order they're included. + All text/coffeescript tags should now execute in the order they’re included. Fixed an issue with extended subclasses using external constructor functions. Fixed an edge-case infinite loop in addImplicitParentheses. Fixed exponential slowdown with long chains of function calls. @@ -1962,7 +2022,7 @@

                                Fixed a lexer bug with Unicode identifiers. Updated REPL for compatibility with Node.js 0.3.7. Fixed requiring relative paths in the REPL. Trailing return and return undefined are now optimized away. - Stopped requiring the core Node.js "util" module for + Stopped requiring the core Node.js util module for back-compatibility with Node.js 0.2.5. Fixed a case where a conditional return would cause fallthrough in a switch statement. Optimized empty objects in destructuring assignment. @@ -1996,14 +2056,14 @@

                                <%= releaseHeader('2010-11-21', '0.9.5', '0.9.4') %> 0.9.5 should be considered the first release candidate for CoffeeScript 1.0. There have been a large number of internal changes since the previous release, - many contributed from satyr's Coco + many contributed from satyr’s Coco dialect of CoffeeScript. Heregexes (extended regexes) were added. Functions can now have default arguments. Class bodies are now executable code. Improved syntax errors for invalid CoffeeScript. undefined now works like null, and cannot be assigned a new value. There was a precedence change with respect to single-line comprehensions: result = i for i in list
                                used to parse as result = (i for i in list) - by default ... it now parses as
                                (result = i) for i in list. + by default … it now parses as
                                (result = i) for i in list.

                                @@ -2018,7 +2078,7 @@

                                <%= releaseHeader('2010-09-16', '0.9.3', '0.9.2') %> CoffeeScript switch statements now compile into JS switch - statements — they previously compiled into if/else chains + statements — they previously compiled into if/else chains for JavaScript 1.3 compatibility. Soaking a function invocation is now supported. Users of the RubyMine editor should now be able to use --watch mode. @@ -2033,7 +2093,7 @@

                                Added a custom jsl.conf file for our preferred JavaScriptLint setup. Sped up Jison grammar compilation time by flattening rules for operations. Block comments can now be used with JavaScript-minifier-friendly syntax. - Added JavaScript's compound assignment bitwise operators. Bugfixes to + Added JavaScript’s compound assignment bitwise operators. Bugfixes to implicit object literals with leading number and string keys, as the subject of implicit calls, and as part of compound assignment.

                                @@ -2042,7 +2102,7 @@

                                <%= releaseHeader('2010-08-11', '0.9.1', '0.9.0') %> Bugfix release for 0.9.1. Greatly improves the handling of mixed implicit objects, implicit function calls, and implicit indentation. - String and regex interpolation is now strictly #{ ... } (Ruby style). + String and regex interpolation is now strictly #{ … } (Ruby style). The compiler now takes a --require flag, which specifies scripts to run before compilation.

                                @@ -2050,24 +2110,24 @@

                                <%= releaseHeader('2010-08-04', '0.9.0', '0.7.2') %> The CoffeeScript 0.9 series is considered to be a release candidate - for 1.0; let's give her a shakedown cruise. 0.9.0 introduces a massive + for 1.0; let’s give her a shakedown cruise. 0.9.0 introduces a massive backwards-incompatible change: Assignment now uses =, and object literals use :, as in JavaScript. This allows us to have implicit object literals, and YAML-style object definitions. Half assignments are removed, in favor of +=, or=, and friends. Interpolation now uses a hash mark # instead of the dollar sign - $ — because dollar signs may be part of a valid JS identifier. + $ — because dollar signs may be part of a valid JS identifier. Downwards range comprehensions are now safe again, and are optimized to straight for loops when created with integer endpoints. A fast, unguarded form of object comprehension was added: for all key, value of object. Mentioning the super keyword with no arguments now forwards all arguments passed to the function, as in Ruby. If you extend class B from parent class A, if - A has an extended method defined, it will be called, passing in B — + A has an extended method defined, it will be called, passing in B — this enables static inheritance, among other things. Cleaner output for functions bound with the fat arrow. @variables can now be used in parameter lists, with the parameter being automatically set as a property - on the object — useful in constructors and setter functions. + on the object — useful in constructors and setter functions. Constructor functions can now take splats.

                                @@ -2080,7 +2140,7 @@

                                <%= releaseHeader('2010-07-11', '0.7.1', '0.7.0') %> Block-style comments are now passed through and printed as JavaScript block - comments -- making them useful for licenses and copyright headers. Better + comments – making them useful for licenses and copyright headers. Better support for running coffee scripts standalone via hashbangs. Improved syntax errors for tokens that are not in the grammar.

                                @@ -2090,7 +2150,7 @@

                                Official CoffeeScript variable style is now camelCase, as in JavaScript. Reserved words are now allowed as object keys, and will be quoted for you. Range comprehensions now generate cleaner code, but you have to specify by -1 - if you'd like to iterate downward. Reporting of syntax errors is greatly + if you’d like to iterate downward. Reporting of syntax errors is greatly improved from the previous release. Running coffee with no arguments now launches the REPL, with Readline support. The <- bind operator has been removed from CoffeeScript. The loop keyword was added, @@ -2107,7 +2167,7 @@

                                The coffee command will now preserve directory structure when compiling a directory full of scripts. Fixed two omissions that were preventing the CoffeeScript compiler from running live within Internet Explorer. - There's now a syntax for block comments, similar in spirit to CoffeeScript's heredocs. + There’s now a syntax for block comments, similar in spirit to CoffeeScript’s heredocs. ECMA Harmony DRY-style pattern matching is now supported, where the name of the property is the same as the name of the value: {name, length}: func. Pattern matching is now allowed within comprehension variables. unless @@ -2147,7 +2207,7 @@

                                Stan Angeloff. Since --run has been the default since 0.5.3, updating --stdio and --eval to run by default, pass --compile - as well if you'd like to print the result. + as well if you’d like to print the result.

                                @@ -2170,7 +2230,7 @@

                                <%= releaseHeader('2010-02-25', '0.5.2', '0.5.1') %> Added a compressed version of the compiler for inclusion in web pages as -
                                v<%= majorVersion %>/browser-compiler/coffee-script.js. It'll automatically run any script tags +
                                v<%= majorVersion %>/browser-compiler/coffee-script.js. It’ll automatically run any script tags with type text/coffeescript for you. Added a --stdio option to the coffee command, for piped-in compiles.

                                @@ -2195,7 +2255,7 @@

                                <%= releaseHeader('2010-02-08', '0.3.2', '0.3.0') %> @property is now a shorthand for this.property.
                                Switched the default JavaScript engine from Narwhal to Node.js. Pass - the --narwhal flag if you'd like to continue using it. + the --narwhal flag if you’d like to continue using it.

                                @@ -2224,7 +2284,7 @@

                                <%= releaseHeader('2010-01-13', '0.2.5', '0.2.4') %> - The conditions in switch statements can now take multiple values at once — + The conditions in switch statements can now take multiple values at once — If any of them are true, the case will run. Added the long arrow ==>, which defines and immediately binds a function to this. While loops can now be used as expressions, in the same way that comprehensions can. Splats @@ -2252,17 +2312,17 @@


                                Added :: as a shorthand for saying .prototype.
                                - The "splat" symbol has been changed from a prefix asterisk *, to + The “splat” symbol has been changed from a prefix asterisk *, to a postfix ellipsis ...
                                - Added JavaScript's in operator, + Added JavaScript’s in operator, empty return statements, and empty while loops.
                                Constructor functions that start with capital letters now include a safety check to make sure that the new instance of the object is returned.
                                The extends keyword now functions identically to goog.inherits - in Google's Closure Library. + in Google’s Closure Library.

                                @@ -2276,7 +2336,7 @@

                                conversion. Splats. Splice literals. Object comprehensions. Blocks. The existential operator. Many thanks to all the folks who posted issues, with special thanks to - Liam O'Connor-Davis for whitespace + Liam O’Connor-Davis for whitespace and expression help.

                                @@ -2328,7 +2388,7 @@

                                inheritance, with the re-addition of the extends keyword. Added experimental Narwhal support (as a Tusk package), contributed by - Tom Robinson, including + Tom Robinson, including bin/cs as a CoffeeScript REPL and interpreter. New --no-wrap option to suppress the safety function wrapper. diff --git a/lib/coffee-script/browser.js b/lib/coffee-script/browser.js index 711b19318a..6274b1012e 100644 --- a/lib/coffee-script/browser.js +++ b/lib/coffee-script/browser.js @@ -1,4 +1,4 @@ -// Generated by CoffeeScript 1.11.1 +// Generated by CoffeeScript 1.12.0 (function() { var CoffeeScript, compile, runScripts, indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; }; diff --git a/lib/coffee-script/cake.js b/lib/coffee-script/cake.js index 9e1f3869b5..1345ebe950 100644 --- a/lib/coffee-script/cake.js +++ b/lib/coffee-script/cake.js @@ -1,4 +1,4 @@ -// Generated by CoffeeScript 1.11.1 +// Generated by CoffeeScript 1.12.0 (function() { var CoffeeScript, cakefileDirectory, fatalError, fs, helpers, missingTask, oparse, options, optparse, path, printTasks, switches, tasks; diff --git a/lib/coffee-script/coffee-script.js b/lib/coffee-script/coffee-script.js index 4407864e8b..dec02ecf26 100644 --- a/lib/coffee-script/coffee-script.js +++ b/lib/coffee-script/coffee-script.js @@ -1,4 +1,4 @@ -// Generated by CoffeeScript 1.11.1 +// Generated by CoffeeScript 1.12.0 (function() { var Lexer, SourceMap, base64encode, compile, ext, fn1, formatSourcePosition, fs, getSourceMap, helpers, i, len, lexer, parser, path, ref, sourceMaps, vm, withPrettyErrors, hasProp = {}.hasOwnProperty; @@ -17,7 +17,7 @@ SourceMap = require('./sourcemap'); - exports.VERSION = '1.11.1'; + exports.VERSION = '1.12.0'; exports.FILE_EXTENSIONS = ['.coffee', '.litcoffee', '.coffee.md']; diff --git a/lib/coffee-script/command.js b/lib/coffee-script/command.js index c6b28f1f56..f06e7bb108 100644 --- a/lib/coffee-script/command.js +++ b/lib/coffee-script/command.js @@ -1,4 +1,4 @@ -// Generated by CoffeeScript 1.11.1 +// Generated by CoffeeScript 1.12.0 (function() { var BANNER, CoffeeScript, EventEmitter, SWITCHES, compileJoin, compileOptions, compilePath, compileScript, compileStdio, exec, findDirectoryIndex, forkNode, fs, helpers, hidden, joinTimeout, makePrelude, mkdirp, notSources, optionParser, optparse, opts, outputPath, parseOptions, path, printLine, printTokens, printWarn, ref, removeSource, removeSourceDir, silentUnlink, sourceCode, sources, spawn, timeLog, usage, useWinPathSep, version, wait, watch, watchDir, watchedDirs, writeJs, indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; }; diff --git a/lib/coffee-script/grammar.js b/lib/coffee-script/grammar.js index 2186d2e0ae..3357c6d0d6 100644 --- a/lib/coffee-script/grammar.js +++ b/lib/coffee-script/grammar.js @@ -1,4 +1,4 @@ -// Generated by CoffeeScript 1.11.1 +// Generated by CoffeeScript 1.12.0 (function() { var Parser, alt, alternatives, grammar, name, o, operators, token, tokens, unwrap; diff --git a/lib/coffee-script/helpers.js b/lib/coffee-script/helpers.js index 5bf524e5db..a91a956d53 100644 --- a/lib/coffee-script/helpers.js +++ b/lib/coffee-script/helpers.js @@ -1,4 +1,4 @@ -// Generated by CoffeeScript 1.11.1 +// Generated by CoffeeScript 1.12.0 (function() { var buildLocationData, extend, flatten, ref, repeat, syntaxErrorToString; diff --git a/lib/coffee-script/index.js b/lib/coffee-script/index.js index ce2c337a29..d2700b9782 100644 --- a/lib/coffee-script/index.js +++ b/lib/coffee-script/index.js @@ -1,4 +1,4 @@ -// Generated by CoffeeScript 1.11.1 +// Generated by CoffeeScript 1.12.0 (function() { var key, ref, val; diff --git a/lib/coffee-script/lexer.js b/lib/coffee-script/lexer.js index c6309bc0c9..45856052fc 100644 --- a/lib/coffee-script/lexer.js +++ b/lib/coffee-script/lexer.js @@ -1,4 +1,4 @@ -// Generated by CoffeeScript 1.11.1 +// Generated by CoffeeScript 1.12.0 (function() { var BOM, BOOL, CALLABLE, CODE, COFFEE_ALIASES, COFFEE_ALIAS_MAP, COFFEE_KEYWORDS, COMMENT, COMPARE, COMPOUND_ASSIGN, HERECOMMENT_ILLEGAL, HEREDOC_DOUBLE, HEREDOC_INDENT, HEREDOC_SINGLE, HEREGEX, HEREGEX_OMIT, HERE_JSTOKEN, IDENTIFIER, INDENTABLE_CLOSERS, INDEXABLE, INVALID_ESCAPE, INVERSES, JSTOKEN, JS_KEYWORDS, LEADING_BLANK_LINE, LINE_BREAK, LINE_CONTINUER, Lexer, MATH, MULTI_DENT, NOT_REGEX, NUMBER, OPERATOR, POSSIBLY_DIVISION, REGEX, REGEX_FLAGS, REGEX_ILLEGAL, RELATION, RESERVED, Rewriter, SHIFT, SIMPLE_STRING_OMIT, STRICT_PROSCRIBED, STRING_DOUBLE, STRING_OMIT, STRING_SINGLE, STRING_START, TRAILING_BLANK_LINE, TRAILING_SPACES, UNARY, UNARY_MATH, VALID_FLAGS, WHITESPACE, compact, count, invertLiterate, isUnassignable, key, locationDataToString, ref, ref1, repeat, starts, throwSyntaxError, indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; }, diff --git a/lib/coffee-script/nodes.js b/lib/coffee-script/nodes.js index 6d0f7488da..a192554741 100644 --- a/lib/coffee-script/nodes.js +++ b/lib/coffee-script/nodes.js @@ -1,4 +1,4 @@ -// Generated by CoffeeScript 1.11.1 +// Generated by CoffeeScript 1.12.0 (function() { var Access, Arr, Assign, Base, Block, BooleanLiteral, Call, Class, Code, CodeFragment, Comment, Existence, Expansion, ExportAllDeclaration, ExportDeclaration, ExportDefaultDeclaration, ExportNamedDeclaration, ExportSpecifier, ExportSpecifierList, Extends, For, IdentifierLiteral, If, ImportClause, ImportDeclaration, ImportDefaultSpecifier, ImportNamespaceSpecifier, ImportSpecifier, ImportSpecifierList, In, Index, InfinityLiteral, JS_FORBIDDEN, LEVEL_ACCESS, LEVEL_COND, LEVEL_LIST, LEVEL_OP, LEVEL_PAREN, LEVEL_TOP, Literal, ModuleDeclaration, ModuleSpecifier, ModuleSpecifierList, NEGATE, NO, NaNLiteral, NullLiteral, NumberLiteral, Obj, Op, Param, Parens, PassthroughLiteral, PropertyName, Range, RegexLiteral, RegexWithInterpolations, Return, SIMPLENUM, Scope, Slice, Splat, StatementLiteral, StringLiteral, StringWithInterpolations, SuperCall, Switch, TAB, THIS, TaggedTemplateCall, ThisLiteral, Throw, Try, UTILITIES, UndefinedLiteral, Value, While, YES, YieldReturn, addLocationDataFn, compact, del, ends, extend, flatten, fragmentsToText, isComplexOrAssignable, isLiteralArguments, isLiteralThis, isUnassignable, locationDataToString, merge, multident, ref1, ref2, some, starts, throwSyntaxError, unfoldSoak, utility, extend1 = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }, diff --git a/lib/coffee-script/optparse.js b/lib/coffee-script/optparse.js index 60436c3158..4dd154160a 100644 --- a/lib/coffee-script/optparse.js +++ b/lib/coffee-script/optparse.js @@ -1,4 +1,4 @@ -// Generated by CoffeeScript 1.11.1 +// Generated by CoffeeScript 1.12.0 (function() { var LONG_FLAG, MULTI_FLAG, OPTIONAL, OptionParser, SHORT_FLAG, buildRule, buildRules, normalizeArguments, repeat; diff --git a/lib/coffee-script/register.js b/lib/coffee-script/register.js index d1bc1d3446..447a8c79c8 100644 --- a/lib/coffee-script/register.js +++ b/lib/coffee-script/register.js @@ -1,4 +1,4 @@ -// Generated by CoffeeScript 1.11.1 +// Generated by CoffeeScript 1.12.0 (function() { var CoffeeScript, Module, binary, child_process, ext, findExtension, fork, helpers, i, len, loadFile, path, ref; diff --git a/lib/coffee-script/repl.js b/lib/coffee-script/repl.js index b51565d61c..27c4532cf8 100644 --- a/lib/coffee-script/repl.js +++ b/lib/coffee-script/repl.js @@ -1,4 +1,4 @@ -// Generated by CoffeeScript 1.11.1 +// Generated by CoffeeScript 1.12.0 (function() { var CoffeeScript, addHistory, addMultilineHandler, fs, getCommandId, merge, nodeREPL, path, ref, replDefaults, runInContext, updateSyntaxError, vm; diff --git a/lib/coffee-script/rewriter.js b/lib/coffee-script/rewriter.js index 804301dfd0..749a7a136c 100644 --- a/lib/coffee-script/rewriter.js +++ b/lib/coffee-script/rewriter.js @@ -1,4 +1,4 @@ -// Generated by CoffeeScript 1.11.1 +// Generated by CoffeeScript 1.12.0 (function() { var BALANCED_PAIRS, CALL_CLOSERS, EXPRESSION_CLOSE, EXPRESSION_END, EXPRESSION_START, IMPLICIT_CALL, IMPLICIT_END, IMPLICIT_FUNC, IMPLICIT_UNSPACED_CALL, INVERSES, LINEBREAKS, SINGLE_CLOSERS, SINGLE_LINERS, generate, k, left, len, ref, rite, indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; }, diff --git a/lib/coffee-script/scope.js b/lib/coffee-script/scope.js index 7e44465df5..22028adb84 100644 --- a/lib/coffee-script/scope.js +++ b/lib/coffee-script/scope.js @@ -1,4 +1,4 @@ -// Generated by CoffeeScript 1.11.1 +// Generated by CoffeeScript 1.12.0 (function() { var Scope, indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; }; diff --git a/lib/coffee-script/sourcemap.js b/lib/coffee-script/sourcemap.js index b7d3165bab..3e156551cb 100644 --- a/lib/coffee-script/sourcemap.js +++ b/lib/coffee-script/sourcemap.js @@ -1,4 +1,4 @@ -// Generated by CoffeeScript 1.11.1 +// Generated by CoffeeScript 1.12.0 (function() { var LineMap, SourceMap; diff --git a/package.json b/package.json index ceed2e11a3..cf6d5e9091 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,7 @@ "compiler" ], "author": "Jeremy Ashkenas", - "version": "1.11.1", + "version": "1.12.0", "license": "MIT", "engines": { "node": ">=0.8.0" diff --git a/src/coffee-script.coffee b/src/coffee-script.coffee index 4e6895bdef..197f5c5ef2 100644 --- a/src/coffee-script.coffee +++ b/src/coffee-script.coffee @@ -12,7 +12,7 @@ helpers = require './helpers' SourceMap = require './sourcemap' # The current CoffeeScript version number. -exports.VERSION = '1.11.1' +exports.VERSION = '1.12.0' exports.FILE_EXTENSIONS = ['.coffee', '.litcoffee', '.coffee.md'] @@ -24,7 +24,7 @@ base64encode = (src) -> switch when typeof Buffer is 'function' new Buffer(src).toString('base64') when typeof btoa is 'function' - # The contents of a