From df9d4a23432c05a004fa7d06a62917e7daa765f9 Mon Sep 17 00:00:00 2001 From: Geoffrey Booth Date: Sat, 2 Sep 2017 12:48:38 -0700 Subject: [PATCH] [CS2] 2.0.0-beta5 (#4682) * Upgrade docs to Bootstrap 4 beta, including refactoring styles; upgrade docs jQuery and CodeMirror * Better style the docs for mobile, including Try CoffeeScript * Fix #4642, erroneous statement about named functions * Update packages * 2.0.0-beta5 --- docs/v2/annotated-source/coffeescript.html | 98 ++- docs/v2/annotated-source/command.html | 213 +++-- docs/v2/annotated-source/grammar.html | 1 + docs/v2/annotated-source/lexer.html | 293 ++++--- docs/v2/annotated-source/nodes.html | 612 +++++++------- .../public/fonts/roboto-black.eot | Bin .../public/fonts/roboto-black.ttf | Bin .../public/fonts/roboto-black.woff | Bin docs/v2/annotated-source/repl.html | 6 +- docs/v2/annotated-source/rewriter.html | 110 ++- docs/v2/annotated-source/sourcemap.html | 11 +- docs/v2/browser-compiler/coffeescript.js | 4 +- docs/v2/index.html | 636 ++++++-------- docs/v2/test.html | 662 +++++++++++++-- documentation/examples/chaining.coffee | 2 +- documentation/sections/changelog.md | 16 + documentation/sections/overview.md | 2 +- .../sections/unsupported_named_functions.md | 2 +- documentation/v2/body.html | 4 +- documentation/v2/code.html | 2 +- documentation/v2/docs.coffee | 21 +- documentation/v2/docs.css | 162 ++-- documentation/v2/navbar.html | 26 +- documentation/v2/scripts.html | 8 +- documentation/v2/sidebar.html | 276 ++----- documentation/v2/styles.html | 2 +- documentation/v2/try.html | 2 +- lib/coffeescript/browser.js | 2 +- lib/coffeescript/cake.js | 2 +- lib/coffeescript/coffeescript.js | 2 +- lib/coffeescript/command.js | 2 +- lib/coffeescript/grammar.js | 2 +- lib/coffeescript/helpers.js | 2 +- lib/coffeescript/index.js | 2 +- lib/coffeescript/lexer.js | 2 +- lib/coffeescript/nodes.js | 2 +- lib/coffeescript/optparse.js | 2 +- lib/coffeescript/parser.js | 0 lib/coffeescript/register.js | 2 +- lib/coffeescript/repl.js | 2 +- lib/coffeescript/rewriter.js | 2 +- lib/coffeescript/scope.js | 2 +- lib/coffeescript/sourcemap.js | 2 +- package-lock.json | 779 +++++++++++++----- package.json | 8 +- 45 files changed, 2421 insertions(+), 1567 deletions(-) mode change 100755 => 100644 docs/v2/annotated-source/public/fonts/roboto-black.eot mode change 100755 => 100644 docs/v2/annotated-source/public/fonts/roboto-black.ttf mode change 100755 => 100644 docs/v2/annotated-source/public/fonts/roboto-black.woff mode change 100755 => 100644 lib/coffeescript/parser.js diff --git a/docs/v2/annotated-source/coffeescript.html b/docs/v2/annotated-source/coffeescript.html index f406c8cb09..1df618c364 100644 --- a/docs/v2/annotated-source/coffeescript.html +++ b/docs/v2/annotated-source/coffeescript.html @@ -159,7 +159,7 @@

coffeescript.coffee

exports.VERSION = packageJson.version
 
-exports.FILE_EXTENSIONS = ['.coffee', '.litcoffee', '.coffee.md']
+exports.FILE_EXTENSIONS = FILE_EXTENSIONS = ['.coffee', '.litcoffee', '.coffee.md'] @@ -252,7 +252,7 @@

coffeescript.coffee

a stack trace. Assuming that most of the time, code isn’t throwing exceptions, it’s probably more efficient to compile twice only when we need a stack trace, rather than always generating a source map even when -it’s not likely to be used. Save in form of filename: (source)

+it’s not likely to be used. Save in form of filename: [(source)]

@@ -267,7 +267,7 @@

coffeescript.coffee

-

Also save source maps if generated, in form of filename: (source map).

+

Also save source maps if generated, in form of (source): [(source map)].

@@ -317,7 +317,8 @@

coffeescript.coffee

checkShebangLine filename, code - sources[filename] = code + sources[filename] ?= [] + sources[filename].push code map = new SourceMap if generateSourceMap tokens = lexer.tokenize code, options @@ -428,8 +429,9 @@

coffeescript.coffee

js = "// #{header}\n#{js}" if generateSourceMap - v3SourceMap = map.generate(options, code) - sourceMaps[filename] = map + v3SourceMap = map.generate options, code + sourceMaps[filename] ?= [] + sourceMaps[filename].push map if options.inlineMap encoded = base64encode JSON.stringify v3SourceMap @@ -701,9 +703,7 @@

coffeescript.coffee

else fileLocation -getSourceMap = (filename) -> - if sourceMaps[filename]? - sourceMaps[filename] +getSourceMap = (filename, line, column) -> @@ -714,16 +714,76 @@

coffeescript.coffee

-

CoffeeScript compiled in a browser may get compiled with options.filename -of <anonymous>, but the browser may request the stack trace with the -filename of the script file.

+

Skip files that we didn’t compile, like Node system files that appear in +the stack trace, as they never have source maps.

-
  else if sourceMaps['<anonymous>']?
-    sourceMaps['<anonymous>']
-  else if sources[filename]?
-    answer = compile sources[filename],
+            
  return null unless filename is '<anonymous>' or filename.slice(filename.lastIndexOf('.')) in FILE_EXTENSIONS
+
+  if filename isnt '<anonymous>' and sourceMaps[filename]?
+    return sourceMaps[filename][sourceMaps[filename].length - 1]
+ + + + +
  • +
    + +
    + +
    +

    CoffeeScript compiled in a browser or via CoffeeScript.compile or .run +may get compiled with options.filename that’s missing, which becomes +<anonymous>; but the runtime might request the stack trace with the +filename of the script file. See if we have a source map cached under +<anonymous> that matches the error.

    + +
    + +
      else if sourceMaps['<anonymous>']?
    + +
  • + + +
  • +
    + +
    + +
    +

    Work backwards from the most recent anonymous source maps, until we find +one that works. This isn’t foolproof; there is a chance that multiple +source maps will have line/column pairs that match. But we have no other +way to match them. frame.getFunction().toString() doesn’t always work, +and it’s not foolproof either.

    + +
    + +
        for map in sourceMaps['<anonymous>'] by -1
    +      sourceLocation = map.sourceLocation [line - 1, column - 1]
    +      return map if sourceLocation?[0]? and sourceLocation[1]?
    + +
  • + + +
  • +
    + +
    + +
    +

    If all else fails, recompile this source to get a source map. We need the +previous section (for <anonymous>) despite this option, because after it +gets compiled we will still need to look it up from +sourceMaps['<anonymous>'] in order to find and return it. That’s why we +start searching from the end in the previous block, because most of the +time the source map we want is the last one.

    + +
    + +
      if sources[filename]?
    +    answer = compile sources[filename][sources[filename].length - 1],
           filename: filename
           sourceMap: yes
           literate: helpers.isLiterate filename
    @@ -734,11 +794,11 @@ 

    coffeescript.coffee

  • -
  • +
  • - +

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

    coffeescript.coffee

    Error.prepareStackTrace = (err, stack) ->
       getSourceMapping = (filename, line, column) ->
    -    sourceMap = getSourceMap filename
    +    sourceMap = getSourceMap filename, line, column
         answer = sourceMap.sourceLocation [line - 1, column - 1] if sourceMap?
         if answer? then [answer[0] + 1, answer[1] + 1] else null
     
    diff --git a/docs/v2/annotated-source/command.html b/docs/v2/annotated-source/command.html
    index 2d047c485b..6e0c69be05 100644
    --- a/docs/v2/annotated-source/command.html
    +++ b/docs/v2/annotated-source/command.html
    @@ -199,25 +199,25 @@ 

    command.coffee

    SWITCHES = [
    -  ['-b', '--bare',            'compile without a top-level function wrapper']
    -  ['-c', '--compile',         'compile to JavaScript and save as .js files']
    -  ['-e', '--eval',            'pass a string from the command line as input']
    -  ['-h', '--help',            'display this help message']
    -  ['-i', '--interactive',     'run an interactive CoffeeScript REPL']
    -  ['-j', '--join [FILE]',     'concatenate the source CoffeeScript before compiling']
    -  ['-m', '--map',             'generate source map and save as .js.map files']
    -  ['-M', '--inline-map',      'generate source map and include it directly in output']
    -  ['-n', '--nodes',           'print out the parse tree that the parser produces']
    -  [      '--nodejs [ARGS]',   'pass options directly to the "node" binary']
    -  [      '--no-header',       'suppress the "Generated by" header']
    -  ['-o', '--output [DIR]',    'set the output directory for compiled JavaScript']
    -  ['-p', '--print',           'print out the compiled JavaScript']
    +  ['-b', '--bare',              'compile without a top-level function wrapper']
    +  ['-c', '--compile',           'compile to JavaScript and save as .js files']
    +  ['-e', '--eval',              'pass a string from the command line as input']
    +  ['-h', '--help',              'display this help message']
    +  ['-i', '--interactive',       'run an interactive CoffeeScript REPL']
    +  ['-j', '--join [FILE]',       'concatenate the source CoffeeScript before compiling']
    +  ['-m', '--map',               'generate source map and save as .js.map files']
    +  ['-M', '--inline-map',        'generate source map and include it directly in output']
    +  ['-n', '--nodes',             'print out the parse tree that the parser produces']
    +  [      '--nodejs [ARGS]',     'pass options directly to the "node" binary']
    +  [      '--no-header',         'suppress the "Generated by" header']
    +  ['-o', '--output [PATH]',     'set the output path or path/filename for compiled JavaScript']
    +  ['-p', '--print',             'print out the compiled JavaScript']
       ['-r', '--require [MODULE*]', 'require the given module before eval or REPL']
    -  ['-s', '--stdio',           'listen for and compile scripts over stdio']
    -  ['-l', '--literate',        'treat stdio as literate style coffeescript']
    -  ['-t', '--tokens',          'print out the tokens that the lexer/rewriter produce']
    -  ['-v', '--version',         'display the version number']
    -  ['-w', '--watch',           'watch scripts for changes and rerun commands']
    +  ['-s', '--stdio',             'listen for and compile scripts over stdio']
    +  ['-l', '--literate',          'treat stdio as literate style coffeescript']
    +  ['-t', '--tokens',            'print out the tokens that the lexer/rewriter produce']
    +  ['-v', '--version',           'display the version number']
    +  ['-w', '--watch',             'watch scripts for changes and rerun commands']
     ]
  • @@ -305,7 +305,45 @@

    command.coffee

    process.argv = process.argv[0..1].concat literals process.argv[0] = 'coffee' - opts.output = path.resolve opts.output if opts.output + if opts.output + outputBasename = path.basename opts.output + if '.' in outputBasename and + outputBasename not in ['.', '..'] and + not helpers.ends(opts.output, path.sep)
    + + + + +
  • +
    + +
    + +
    +

    An output filename was specified, e.g. /dist/scripts.js.

    + +
    + +
          opts.outputFilename = outputBasename
    +      opts.outputPath = path.resolve path.dirname opts.output
    +    else
    + +
  • + + +
  • +
    + +
    + +
    +

    An output path was specified, e.g. /dist.

    + +
    + +
          opts.outputFilename = null
    +      opts.outputPath = path.resolve opts.output
    +
       if opts.join
         opts.join = path.resolve opts.join
         console.error '''
    @@ -328,19 +366,19 @@ 

    command.coffee

    makePrelude = (requires) -> requires.map (module) -> - [_, name, module] = match if match = module.match(/^(.*)=(.*)$/) - name ||= helpers.baseFileName module, yes, useWinPathSep - "#{name} = require('#{module}')" + [full, name, module] = match if match = module.match(/^(.*)=(.*)$/) + name or= helpers.baseFileName module, yes, useWinPathSep + "global['#{name}'] = require('#{module}')" .join ';'
  • -
  • +
  • - +

    Compile a path, which could be a script or a directory. If a directory is passed, recursively compile all ‘.coffee’, ‘.litcoffee’, and ‘.coffee.md’ @@ -382,7 +420,7 @@

    command.coffee

    code = fs.readFileSync source catch err if err.code is 'ENOENT' then return else throw err - compileScript(source, code.toString(), base) + compileScript source, code.toString(), base else notSources[source] = yes @@ -399,53 +437,56 @@

    command.coffee

  • -
  • +
  • - +

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

    compileScript = (file, input, base = null) ->
    -  o = opts
       options = compileOptions file, base
       try
    -    t = task = {file, input, options}
    +    task = {file, input, options}
         CoffeeScript.emit 'compile', task
    -    if o.tokens
    -      printTokens CoffeeScript.tokens t.input, t.options
    -    else if o.nodes
    -      printLine CoffeeScript.nodes(t.input, t.options).toString().trim()
    -    else if o.run
    +    if opts.tokens
    +      printTokens CoffeeScript.tokens task.input, task.options
    +    else if opts.nodes
    +      printLine CoffeeScript.nodes(task.input, task.options).toString().trim()
    +    else if opts.run
           CoffeeScript.register()
    -      CoffeeScript.eval opts.prelude, t.options if opts.prelude
    -      CoffeeScript.run t.input, t.options
    -    else if o.join and t.file isnt o.join
    -      t.input = helpers.invertLiterate t.input if helpers.isLiterate file
    -      sourceCode[sources.indexOf(t.file)] = t.input
    +      CoffeeScript.eval opts.prelude, task.options if opts.prelude
    +      CoffeeScript.run task.input, task.options
    +    else if opts.join and task.file isnt opts.join
    +      task.input = helpers.invertLiterate task.input if helpers.isLiterate file
    +      sourceCode[sources.indexOf(task.file)] = task.input
           compileJoin()
         else
    -      compiled = CoffeeScript.compile t.input, t.options
    -      t.output = compiled
    -      if o.map
    -        t.output = compiled.js
    -        t.sourceMap = compiled.v3SourceMap
    +      compiled = CoffeeScript.compile task.input, task.options
    +      task.output = compiled
    +      if opts.map
    +        task.output = compiled.js
    +        task.sourceMap = compiled.v3SourceMap
     
           CoffeeScript.emit 'success', task
    -      if o.print
    -        printLine t.output.trim()
    -      else if o.compile or o.map
    -        writeJs base, t.file, t.output, options.jsPath, t.sourceMap
    +      if opts.print
    +        printLine task.output.trim()
    +      else if opts.compile or opts.map
    +        saveTo = if opts.outputFilename and sources.length is 1
    +          path.join opts.outputPath, opts.outputFilename
    +        else
    +          options.jsPath
    +        writeJs base, task.file, task.output, saveTo, task.sourceMap
       catch err
         CoffeeScript.emit 'failure', err, task
         return if CoffeeScript.listeners('failure').length
         message = err?.stack or "#{err}"
    -    if o.watch
    +    if opts.watch
           printLine message + '\x07'
         else
           printWarn message
    @@ -454,11 +495,11 @@ 

    command.coffee

  • -
  • +
  • - +

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

    @@ -476,11 +517,11 @@

    command.coffee

  • -
  • +
  • - +

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

    @@ -498,11 +539,11 @@

    command.coffee

  • -
  • +
  • - +

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

    command.coffee

  • -
  • +
  • - +

    Watch a directory of files for new additions.

    @@ -609,11 +650,11 @@

    command.coffee

  • -
  • +
  • - +

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

    @@ -638,11 +679,11 @@

    command.coffee

  • -
  • +
  • - +

    Get the corresponding output JavaScript path for a source file.

    @@ -651,22 +692,22 @@

    command.coffee

    outputPath = (source, base, extension=".js") ->
       basename  = helpers.baseFileName source, yes, useWinPathSep
       srcDir    = path.dirname source
    -  if not opts.output
    -    dir = srcDir
    +  dir = unless opts.outputPath
    +    srcDir
       else if source is base
    -    dir = opts.output
    +    opts.outputPath
       else
    -    dir = path.join opts.output, path.relative base, srcDir
    +    path.join opts.outputPath, path.relative base, srcDir
       path.join dir, basename + extension
  • -
  • +
  • - +

    Recursively mkdir, like mkdir -p.

    @@ -688,11 +729,11 @@

    command.coffee

  • -
  • +
  • - +

    Write out a JavaScript source file with the compiled code. By default, files are written out in cwd as .js files with the same name, but the output @@ -726,11 +767,11 @@

    command.coffee

  • -
  • +
  • - +

    Convenience for cleaner setTimeouts.

    @@ -741,11 +782,11 @@

    command.coffee

  • -
  • +
  • - +

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

    @@ -757,11 +798,11 @@

    command.coffee

  • -
  • +
  • - +

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

    @@ -777,11 +818,11 @@

    command.coffee

  • -
  • +
  • - +

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

    @@ -797,11 +838,11 @@

    command.coffee

  • -
  • +
  • - +

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

    @@ -837,11 +878,11 @@

    command.coffee

  • -
  • +
  • - +

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

    @@ -864,11 +905,11 @@

    command.coffee

  • -
  • +
  • - +

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

    @@ -881,11 +922,11 @@

    command.coffee

  • -
  • +
  • - +

    Print the --version message and exit.

    diff --git a/docs/v2/annotated-source/grammar.html b/docs/v2/annotated-source/grammar.html index 8867d22e82..7d0bafd0be 100644 --- a/docs/v2/annotated-source/grammar.html +++ b/docs/v2/annotated-source/grammar.html @@ -788,6 +788,7 @@

    Grammatical Rules

      SimpleAssignable: [
         o 'Identifier',                             -> new Value $1
         o 'Value Accessor',                         -> $1.add $2
    +    o 'Code Accessor',                          -> new Value($1).add $2
         o 'ThisProperty'
       ]
    diff --git a/docs/v2/annotated-source/lexer.html b/docs/v2/annotated-source/lexer.html index 2fe6eb2bde..9d83c6db84 100644 --- a/docs/v2/annotated-source/lexer.html +++ b/docs/v2/annotated-source/lexer.html @@ -395,7 +395,7 @@

    Tokenizers

    return id.length if id is 'do' and regExSuper = /^(\s*super)(?!\(\))/.exec @chunk[3...] @token 'SUPER', 'super' - @token 'CALL_START', '(' + @token 'CALL_START', '(' @token 'CALL_END', ')' [input, sup] = regExSuper return sup.length + 3 @@ -1000,7 +1000,7 @@

    Tokenizers

    @token 'OUTDENT', moveOut, 0, outdentLength moveOut -= dent @outdebt -= moveOut if dent - @tokens.pop() while @value() is ';' + @suppressSemicolons() @token 'TERMINATOR', '\n', outdentLength, 0 unless @tag() is 'TERMINATOR' or noNewlines @indent = decreasedIndent @@ -1042,7 +1042,7 @@

    Tokenizers

      newlineToken: (offset) ->
    -    @tokens.pop() while @value() is ';'
    +    @suppressSemicolons()
         @token 'TERMINATOR', '\n', offset, 0 unless @tag() is 'TERMINATOR'
         this
    @@ -1278,9 +1278,10 @@

    Tokenizers

    @exportSpecifierList = no if value is ';' + @error 'unexpected ;' if prev?[0] in ['=', UNFINISHED...] @seenFor = @seenImport = @seenExport = no tag = 'TERMINATOR' - else if value is '*' and prev[0] is 'EXPORT' + else if value is '*' and prev?[0] is 'EXPORT' tag = 'EXPORT_ALL' else if value in MATH then tag = 'MATH' else if value in COMPARE then tag = 'COMPARE' @@ -1289,11 +1290,12 @@

    Tokenizers

    else if value in UNARY_MATH then tag = 'UNARY_MATH' else if value in SHIFT then tag = 'SHIFT' 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 + else if prev + if value is '(' and not prev.spaced and prev[0] in CALLABLE prev[0] = 'FUNC_EXIST' if prev[0] is '?' tag = 'CALL_START' - else if value is '[' and prev[0] in INDEXABLE + else if value is '[' and ((prev[0] in INDEXABLE and not prev.spaced) or + (prev[0] is '::')) # `.prototype` can’t be a method you can call. tag = 'INDEX_START' switch prev[0] when '?' then prev[0] = 'INDEX_SOAK' @@ -1590,7 +1592,8 @@

    Token Manipulators

    for token, i in tokens [tag, value] = token switch tag - when 'TOKENS' + when 'TOKENS' + if value.length is 2
  • @@ -1605,7 +1608,7 @@

    Token Manipulators

    -
              continue if value.length is 2
    +
                continue unless value[0].comments or value[1].comments
    @@ -1616,6 +1619,59 @@

    Token Manipulators

    +

    There are comments (and nothing else) in this interpolation.

    + + + +
                if @csxDepth is 0
    + + + + +
  • +
    + +
    + +
    +

    This is an interpolated string, not a CSX tag; and for whatever +reason `a${/*test*/}b` is invalid JS. So compile to +`a${/*test*/''}b` instead.

    + +
    + +
                  placeholderToken = @makeToken 'STRING', "''"
    +            else
    +              placeholderToken = @makeToken 'JS', ''
    + +
  • + + +
  • +
    + +
    + +
    +

    Use the same location data as the first parenthesis.

    + +
    + +
                placeholderToken[2] = value[0][2]
    +            for val in value when val.comments
    +              placeholderToken.comments ?= []
    +              placeholderToken.comments.push val.comments...
    +            value.splice 1, 0, placeholderToken
    + +
  • + + +
  • +
    + +
    + +

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

    @@ -1628,11 +1684,11 @@

    Token Manipulators

  • -
  • +
  • - +

    Convert 'NEOSTRING' into 'STRING'.

    @@ -1643,11 +1699,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 @@ -1664,11 +1720,11 @@

    Token Manipulators

  • -
  • +
  • - +

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

    @@ -1686,11 +1742,11 @@

    Token Manipulators

  • -
  • +
  • - +

    Create a 0-length “+” token.

    @@ -1723,11 +1779,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.

    @@ -1742,11 +1798,11 @@

    Token Manipulators

  • -
  • +
  • - +

    Auto-close INDENT to support syntax like this:

    el.click((event) ->
    @@ -1762,11 +1818,11 @@ 

    Token Manipulators

  • -
  • +
  • - +

    Helpers

    @@ -1775,11 +1831,11 @@

    Helpers

  • -
  • +
  • - +
    @@ -1787,11 +1843,11 @@

    Helpers

  • -
  • +
  • - +

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

    offset is a number of characters into @chunk.

    @@ -1821,11 +1877,11 @@

    Helpers

  • -
  • +
  • - +

    Same as token, except this just returns the token without adding it to the results.

    @@ -1840,11 +1896,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.

    @@ -1862,11 +1918,11 @@

    Helpers

  • -
  • +
  • - +

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

    Helpers

  • -
  • +
  • - +

    Peek at the last tag in the token stream.

    @@ -1902,11 +1958,11 @@

    Helpers

  • -
  • +
  • - +

    Peek at the last value in the token stream.

    @@ -1919,11 +1975,11 @@

    Helpers

  • -
  • +
  • - +

    Get the previous token in the token stream.

    @@ -1935,11 +1991,11 @@

    Helpers

  • -
  • +
  • - +

    Are we in the midst of an unfinished expression?

    @@ -1967,11 +2023,11 @@

    Helpers

  • -
  • +
  • - +

    surrogate pair

    @@ -1984,11 +2040,11 @@

    Helpers

  • -
  • +
  • - +

    Replace \u{...} with \uxxxx[\uxxxx] in regexes without u flag

    @@ -2011,11 +2067,11 @@

    Helpers

  • -
  • +
  • - +

    Validates escapes in strings and regexes.

    @@ -2043,11 +2099,11 @@

    Helpers

  • -
  • +
  • - +

    Constructs a string or regex by escaping certain characters.

    @@ -2067,11 +2123,11 @@

    Helpers

  • -
  • +
  • - +

    Ignore escaped backslashes.

    @@ -2085,16 +2141,21 @@

    Helpers

    when ls then '\\u2028' when ps then '\\u2029' when other then (if options.double then "\\#{other}" else other) - "#{options.delimiter}#{body}#{options.delimiter}"
    + "#{options.delimiter}#{body}#{options.delimiter}" + + suppressSemicolons: -> + while @value() is ';' + @tokens.pop() + @error 'unexpected ;' if @prev()?[0] in ['=', UNFINISHED...]
  • -
  • +
  • - +

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

    @@ -2113,11 +2174,11 @@

    Helpers

  • -
  • +
  • - +

    Helper functions

    @@ -2126,11 +2187,11 @@

    Helper functions

  • -
  • +
  • - +
    @@ -2151,11 +2212,11 @@

    Helper functions

  • -
  • +
  • - +

    from isn’t a CoffeeScript keyword, but it behaves like one in import and export statements (handled above) and in the declaration line of a for @@ -2170,11 +2231,11 @@

    Helper functions

  • -
  • +
  • - +

    for i from from, for from from iterable

    @@ -2187,11 +2248,11 @@

    Helper functions

  • -
  • +
  • - +

    for i from iterable

    @@ -2202,11 +2263,11 @@

    Helper functions

  • -
  • +
  • - +

    for from…

    @@ -2218,11 +2279,11 @@

    Helper functions

  • -
  • +
  • - +

    for {from}…, for [from]…, for {a, from}…, for {a: from}…

    @@ -2236,11 +2297,11 @@

    Helper functions

  • -
  • +
  • - +

    Constants

    @@ -2249,11 +2310,11 @@

    Constants

  • -
  • +
  • - +
    @@ -2261,11 +2322,11 @@

    Constants

  • -
  • +
  • - +

    Keywords that CoffeeScript shares in common with JavaScript.

    @@ -2283,11 +2344,11 @@

    Constants

  • -
  • +
  • - +

    CoffeeScript-only keywords.

    @@ -2315,11 +2376,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, @@ -2338,11 +2399,11 @@

    Constants

  • -
  • +
  • - +

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

    @@ -2354,11 +2415,11 @@

    Constants

  • -
  • +
  • - +

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

    @@ -2369,11 +2430,11 @@

    Constants

  • -
  • +
  • - +

    Token matching regexes.

    @@ -2427,11 +2488,11 @@

    Constants

  • -
  • +
  • - +

    String-matching-regexes.

    @@ -2465,11 +2526,11 @@

    Constants

  • -
  • +
  • - +

    Regex-matching-regexes.

    @@ -2503,11 +2564,11 @@

    Constants

  • -
  • +
  • - +

    Other regexes.

    @@ -2550,11 +2611,11 @@

    Constants

  • -
  • +
  • - +

    Compound assignment tokens.

    @@ -2568,11 +2629,11 @@

    Constants

  • -
  • +
  • - +

    Unary tokens.

    @@ -2585,11 +2646,11 @@

    Constants

  • -
  • +
  • - +

    Bit-shifting tokens.

    @@ -2600,11 +2661,11 @@

    Constants

  • -
  • +
  • - +

    Comparison tokens.

    @@ -2615,11 +2676,11 @@

    Constants

  • -
  • +
  • - +

    Mathematical tokens.

    @@ -2630,11 +2691,11 @@

    Constants

  • -
  • +
  • - +

    Relational tokens that are negatable with not prefix.

    @@ -2645,11 +2706,11 @@

    Constants

  • -
  • +
  • - +

    Boolean tokens.

    @@ -2660,11 +2721,11 @@

    Constants

  • -
  • +
  • - +

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

    Constants

  • -
  • +
  • - +

    Tokens which can be the left-hand side of a less-than comparison, i.e. a<b.

    @@ -2696,11 +2757,11 @@

    Constants

  • -
  • +
  • - +

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

    @@ -2713,11 +2774,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 @@ -2730,11 +2791,11 @@

    Constants

  • -
  • +
  • - +

    Additional indent in front of these is ignored.

    @@ -2745,11 +2806,11 @@

    Constants

  • -
  • +
  • - +

    Tokens that, when appearing at the end of a line, suppress a following TERMINATOR/INDENT token

    diff --git a/docs/v2/annotated-source/nodes.html b/docs/v2/annotated-source/nodes.html index 41d7f4fb89..a05718769f 100644 --- a/docs/v2/annotated-source/nodes.html +++ b/docs/v2/annotated-source/nodes.html @@ -356,7 +356,10 @@

    Base

    else node.compileClosure o @compileCommentFragments o, node, fragments - fragments
    + fragments + + compileToFragmentsWithoutComments: (o, lvl) -> + @compileWithoutComments o, lvl, 'compileToFragments'
  • @@ -1715,15 +1718,13 @@

    Literal

    exports.StringLiteral = class StringLiteral extends Literal compileNode: (o) -> - res = if @csx then [@makeCode @unquote yes] else super() + res = if @csx then [@makeCode @unquote(yes, yes)] else super() - unquote: (literal) -> + unquote: (doubleQuote = no, newLine = no) -> unquoted = @value[1...-1] - if literal - unquoted.replace /\\n/g, '\n' - .replace /\\"/g, '"' - else - unquoted + unquoted = unquoted.replace /\\"/g, '"' if doubleQuote + unquoted = unquoted.replace /\\n/g, '\n' if newLine + unquoted exports.RegexLiteral = class RegexLiteral extends Literal @@ -3288,7 +3289,8 @@

    Obj

    propSlices.push prop addSlice() slices.unshift new Obj unless slices[0] instanceof Obj - (new Call new Literal('Object.assign'), slices).compileToFragments o + _extends = new Value new Literal utility '_extends', o + (new Call _extends, slices).compileToFragments o compileCSXAttributes: (o) -> props = @properties @@ -4209,8 +4211,9 @@

    Assign

    -
            return @compileObjectDestruct(o) if @variable.isObject() and @variable.contains (node) ->
    +            
            objDestructAnswer = @compileObjectDestruct(o) if @variable.isObject() and @variable.contains (node) ->
               node instanceof Obj and node.hasSplat()
    +        return objDestructAnswer if objDestructAnswer
     
           return @compileSplice       o if @variable.isSplice()
           return @compileConditional  o if @context in ['||=', '&&=', '?=']
    @@ -4389,8 +4392,10 @@ 

    Assign

        traverseRest = (properties, source) =>
           restElements = []
           restIndex = undefined
    +      source = new Value source unless source.properties?
     
           for prop, index in properties
    +        nestedSourceDefault = nestedSource = nestedProperties = null
             setScopeVar prop.unwrap()
             if prop instanceof Assign
    @@ -4418,6 +4423,21 @@

    Assign

    +

    prop is k = {...}

    + +
    + +
                continue unless prop.context is 'object'
    + + + + +
  • +
    + +
    + +

    prop is k: {...}

    @@ -4428,11 +4448,11 @@

    Assign

  • -
  • +
  • - +

    prop is k: {...} = default

    @@ -4458,11 +4478,11 @@

    Assign

  • -
  • +
  • - +

    Remove rest element from the properties after iteration

    @@ -4475,34 +4495,40 @@

    Assign

  • -
  • +
  • - +
    -

    Cache the value for reuse with rest elements

    +

    Cache the value for reuse with rest elements.

    -
        [@value, valueRef] = @value.cache o
    +
        if @value.shouldCache()
    +      valueRefTemp = new IdentifierLiteral o.scope.freeVariable 'ref', reserve: false
    +    else
    +      valueRefTemp = @value.base
  • -
  • +
  • - +

    Find all rest elements.

    -
        restElements = traverseRest @variable.base.properties, valueRef
    +            
        restElements = traverseRest @variable.base.properties, valueRefTemp
    +    return no unless restElements and restElements.length > 0
     
    +    [@value, valueRef] = @value.cache o
         result = new Block [@]
    +
         for restElement in restElements
           value = new Call new Value(new Literal utility 'objectWithoutKeys', o), [restElement.source, restElement.excludeProps]
           result.push new Assign restElement.name, value
    @@ -4513,11 +4539,11 @@ 

    Assign

  • -
  • +
  • - +

    Remove leading tab and trailing semicolon

    @@ -4531,11 +4557,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.

    @@ -4551,11 +4577,11 @@

    Assign

  • -
  • +
  • - +

    Special-case for {} = a and [] = a (empty patterns). Compile to simply a.

    @@ -4570,11 +4596,11 @@

    Assign

  • -
  • +
  • - +

    Disallow [...] = a for some reason. (Could be equivalent to [] = a?)

    @@ -4588,11 +4614,11 @@

    Assign

  • -
  • +
  • - +

    Special case for when there’s only one thing destructured off of something. {a} = b, [a] = b, {a: b} = c

    @@ -4604,11 +4630,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).

    @@ -4621,11 +4647,11 @@

    Assign

  • -
  • +
  • - +

    A regular object pattern-match.

    @@ -4644,11 +4670,11 @@

    Assign

  • -
  • +
  • - +

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

    @@ -4663,11 +4689,11 @@

    Assign

  • -
  • +
  • - +

    A regular array pattern-match.

    @@ -4692,11 +4718,11 @@

    Assign

  • -
  • +
  • - +

    At this point, there are several things to destructure. So the fn() in {a, b} = fn() must be cached, for example. Make vvar into a simple @@ -4713,11 +4739,11 @@

    Assign

  • -
  • +
  • - +

    And here comes the big loop that handles all of these cases: [a, b] = c @@ -4766,11 +4792,11 @@

    Assign

  • -
  • +
  • - +

    A regular object pattern-match.

    @@ -4789,11 +4815,11 @@

    Assign

  • -
  • +
  • - +

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

    @@ -4808,11 +4834,11 @@

    Assign

  • -
  • +
  • - +

    A regular array pattern-match.

    @@ -4837,11 +4863,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 @@ -4855,11 +4881,11 @@

    Assign

  • -
  • +
  • - +

    Disallow conditional assignment of undefined variables.

    @@ -4878,11 +4904,11 @@

    Assign

  • -
  • +
  • - +

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

    @@ -4896,11 +4922,11 @@

    Assign

  • -
  • +
  • - +

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

    @@ -4937,11 +4963,11 @@

    Assign

  • -
  • +
  • - +

    FuncGlyph

    @@ -4955,11 +4981,11 @@

    FuncGlyph

  • -
  • +
  • - +

    Code

    @@ -4968,11 +4994,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 @@ -5010,11 +5036,11 @@

    Code

  • -
  • +
  • - +

    Compilation creates a new scope unless explicitly asked to share with the outer scope. Handles splat parameters in the parameter list by setting @@ -5049,11 +5075,11 @@

    Code

  • -
  • +
  • - +

    Check for duplicate parameters and separate this assignments.

    @@ -5073,11 +5099,11 @@

    Code

  • -
  • +
  • - +

    Parse the parameters, adding them to the list of parameters to put in the function definition; and dealing with splats or expansions, including @@ -5095,11 +5121,11 @@

    Code

  • -
  • +
  • - +

    Was ... used with this parameter? (Only one such parameter is allowed per function.) Splat/expansion parameters cannot have default values, @@ -5119,11 +5145,11 @@

    Code

  • -
  • +
  • - +

    Splat arrays are treated oddly by ES; deal with them the legacy way in the function body. TODO: Should this be handled in the @@ -5148,11 +5174,11 @@

    Code

  • -
  • +
  • - +

    Parse all other parameters; if a splat paramater has not yet been encountered, add these other parameters to the list to be output in @@ -5168,11 +5194,11 @@

    Code

  • -
  • +
  • - +

    This parameter cannot be declared or assigned in the parameter list. So put a reference in the parameter list and add a statement @@ -5191,11 +5217,11 @@

    Code

  • -
  • +
  • - +

    If this parameter comes before the splat or expansion, it will go in the function definition parameter list.

    @@ -5207,11 +5233,11 @@

    Code

  • -
  • +
  • - +

    If this parameter has a default value, and it hasn’t already been set by the shouldCache() block above, define it as a statement in @@ -5231,11 +5257,11 @@

    Code

  • -
  • +
  • - +

    Add this parameter’s reference(s) to the function scope.

    @@ -5246,11 +5272,11 @@

    Code

  • -
  • +
  • - +

    This parameter is destructured.

    @@ -5263,11 +5289,11 @@

    Code

  • -
  • +
  • - +

    Compile foo({a, b...}) -> to foo(arg) -> {a, b...} = arg. Can be removed once ES proposal hits Stage 4.

    @@ -5283,11 +5309,11 @@

    Code

  • -
  • +
  • - +

    Compile foo({a, b...} = {}) -> to foo(arg = {}) -> {a, b...} = arg.

    @@ -5300,11 +5326,11 @@

    Code

  • -
  • +
  • - +

    This compilation of the parameter is only to get its name to add to the scope name tracking; since the compilation output here @@ -5315,11 +5341,7 @@

    Code

                paramToAddToScope = if param.value? then param else ref
    -            if paramToAddToScope.name?.comments
    -              salvagedComments = paramToAddToScope.name.comments
    -              delete paramToAddToScope.name.comments
    -            o.scope.parameter fragmentsToText paramToAddToScope.compileToFragments o
    -            paramToAddToScope.name.comments = salvagedComments if salvagedComments
    +            o.scope.parameter fragmentsToText paramToAddToScope.compileToFragmentsWithoutComments o
               params.push ref
             else
               paramsAfterSplat.push param
    @@ -5327,11 +5349,11 @@

    Code

  • -
  • +
  • - +

    If this parameter had a default value, since it’s no longer in the function parameter list we need to assign its default value @@ -5347,11 +5369,11 @@

    Code

  • -
  • +
  • - +

    Add this parameter to the scope, since it wouldn’t have been added yet since it was skipped earlier.

    @@ -5363,11 +5385,11 @@

    Code

  • -
  • +
  • - +

    If there were parameters after the splat or expansion parameter, those parameters need to be assigned in the body of the function.

    @@ -5379,11 +5401,11 @@

    Code

  • -
  • +
  • - +

    Create a destructured assignment, e.g. [a, b, c] = [args..., b, c]

    @@ -5396,11 +5418,11 @@

    Code

  • -
  • +
  • - +

    Add new expressions to the function body

    @@ -5417,11 +5439,11 @@

    Code

  • -
  • +
  • - +

    Assemble the output

    @@ -5438,18 +5460,38 @@

    Code

    signature = [@makeCode '('] for param, i in params signature.push @makeCode ', ' if i isnt 0 - signature.push @makeCode '...' if haveSplatParam and i is params.length - 1 + signature.push @makeCode '...' if haveSplatParam and i is params.length - 1
  • + + + + +
  • +
    + +
    + +
    +

    Compile this parameter, but if any generated variables get created +(e.g. ref), shift those into the parent scope since we can’t put a +var line inside a function parameter list.

    + +
    + +
          scopeVariablesCount = o.scope.variables.length
           signature.push param.compileToFragments(o)...
    +      if scopeVariablesCount isnt o.scope.variables.length
    +        generatedVariables = o.scope.variables.splice scopeVariablesCount
    +        o.scope.parent.variables.push generatedVariables...
         signature.push @makeCode ')'
  • -
  • +
  • - +

    Block comments between ) and ->/=> get output between ) and {.

    @@ -5464,11 +5506,11 @@

    Code

  • -
  • +
  • - +

    We need to compile the body before method names to ensure super references are handled.

    @@ -5499,11 +5541,11 @@

    Code

  • -
  • +
  • - +

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

    @@ -5516,11 +5558,11 @@

    Code

  • -
  • +
  • - +

    Short-circuit replaceInContext method to prevent it from crossing context boundaries. Bound functions have the same context.

    @@ -5553,11 +5595,11 @@

    Code

  • -
  • +
  • - +

    Find all super calls in the given context node Returns true if iterator is called

    @@ -5577,11 +5619,11 @@

    Code

  • -
  • +
  • - +

    super has the same target in bound (arrow) functions, so check them too

    @@ -5594,11 +5636,11 @@

    Code

  • -
  • +
  • - +

    Param

    @@ -5607,11 +5649,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, @@ -5634,6 +5676,9 @@

    Param

    compileToFragments: (o) -> @name.compileToFragments o, LEVEL_LIST + compileToFragmentsWithoutComments: (o) -> + @name.compileToFragmentsWithoutComments o, LEVEL_LIST + asReference: (o) -> return @reference if @reference node = @name @@ -5653,11 +5698,11 @@

    Param

  • -
  • +
  • - +

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

    Param

  • -
  • +
  • - +