exports.VERSION = packageJson.version
-exports.FILE_EXTENSIONS = ['.coffee', '.litcoffee', '.coffee.md']
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 @@
exports.VERSION = packageJson.version
-exports.FILE_EXTENSIONS = ['.coffee', '.litcoffee', '.coffee.md']
filename
: (source)
+it’s not likely to be used. Save in form of filename
: [(source)
]
@@ -267,7 +267,7 @@ Also save source maps if generated, in form of filename
: (source map)
.
Also save source maps if generated, in form of (source)
: [(source map)
].
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 @@
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']
]
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 @@
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 @@If all of the source files are done being read, concatenate and compile them together.
@@ -498,11 +539,11 @@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 @@
Watch a directory of files for new additions.
@@ -609,11 +650,11 @@Remove a file from our source list, and source code cache. Optionally remove the compiled JS version as well.
@@ -638,11 +679,11 @@Get the corresponding output JavaScript path for a source file.
@@ -651,22 +692,22 @@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
.
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 @@
Convenience for cleaner setTimeouts.
@@ -741,11 +782,11 @@When watching scripts, it’s useful to log changes with the timestamp.
@@ -757,11 +798,11 @@Pretty-print a stream of tokens, sans location data.
@@ -777,11 +818,11 @@Use the OptionParser module to extract all options from
process.argv
that are specified in SWITCHES
.
The compile-time options to pass to the CoffeeScript compiler.
@@ -837,11 +878,11 @@Start up a new Node.js instance with the arguments in --nodejs
passed to
the node
binary, preserving the other options.
Print the --help
usage message and exit. Deprecated switches are not
shown.
Print the --version
message and exit.
SimpleAssignable: [
o 'Identifier', -> new Value $1
o 'Value Accessor', -> $1.add $2
+ o 'Code Accessor', -> new Value($1).add $2
o 'ThisProperty'
]
newlineToken: (offset) ->
- @tokens.pop() while @value() is ';'
+ @suppressSemicolons()
@token 'TERMINATOR', '\n', offset, 0 unless @tag() is 'TERMINATOR'
this
continue if value.length is 2
continue unless value[0].comments or value[1].comments
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.
Convert 'NEOSTRING'
into 'STRING'
.
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 @@
However, there is one case where we can optimize away a starting empty string.
@@ -1686,11 +1742,11 @@Create a 0-length “+” token.
@@ -1723,11 +1779,11 @@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 @@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
-
+
+ "#{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
-
+
- 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
-
+
- simple literals
foo
@@ -5691,11 +5736,11 @@ Param
- -
+
-
- at-params
@foo
@@ -5709,11 +5754,11 @@ Param
- -
+
-
- destructured parameter with default value
@@ -5727,11 +5772,11 @@ Param
- -
+
-
- assignments within destructured parameters
{foo:bar}
@@ -5744,11 +5789,11 @@ Param
- -
+
-
… possibly with a default value
@@ -5763,11 +5808,11 @@ Param
- -
+
-
- splats within destructured parameters
[xs...]
@@ -5783,11 +5828,11 @@ Param
- -
+
-
- destructured parameters within destructured parameters
[{a}]
@@ -5801,11 +5846,11 @@ Param
- -
+
-
- at-params within destructured parameters
{@foo}
@@ -5819,11 +5864,11 @@ Param
- -
+
-