Commit Graph

15 Commits

Author SHA1 Message Date
Simon Lydell 4c2c472e07 Fix #3502: Define param variables when expansion 2015-01-13 21:26:11 +01:00
Simon Lydell 8ab15d7372 Fix #1500, #1574, #3318: Name generated vars uniquely
Any variables generated by CoffeeScript are now made sure to be named to
something not present in the source code being compiled. This way you can no
longer interfere with them, either on purpose or by mistake. (#1500, #1574)

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

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

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

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

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

Duplicate this-parameters with a reserved word, such as `(@case, @case) ->`,
used to compile but now throws, just like regular duplicate parameters.
2015-01-10 23:25:01 +01:00
Joshua Peek 23a691ae87 Add test for reserved keywords as parameters 2015-01-10 23:23:26 +01:00
Adam Roben 8980647f32 Add tests for the optimization of trailing return statements
This documents current behavior. When #1038 was fixed, we also optimized
away trailing "undefined" and "return undefined", but that is no longer
the case.
2014-02-06 09:21:35 -05:00
xixixao 369e0545c0 Added expansion to destructuring 2014-01-24 16:00:34 +00:00
Troels Nielsen a320e1e535 Fix #1435 by amending away sign reversal. 2013-02-24 20:33:58 +01:00
Jeremy Ashkenas cc6f0451e7 Fixes #2621 -- buggy function parameter name detection with complex destructuring in param list. 2013-01-05 18:32:57 -10:00
Jeremy Ashkenas 87257ea6b3 Fixes #2258 -- allow parameter lists in the vertical style. 2012-04-24 16:56:39 -04:00
Gerald Lewis 99394e1011 Fixes issue where destructured assignment params were incorrectly identified as duplicates. 2012-04-23 20:41:56 -04:00
Gerald Lewis 7521068ba3 Issue #1547 'use strict' duplicate formal parameter are prohibited
updated error message (thanks @davidchambers)

code style fixes
2012-01-16 17:19:14 -05:00
Michael Ficarra 46b34d4b43 whitespace cleanup 2011-12-24 07:04:34 -05:00
Jeremy Ashkenas a0aa090f2c Fixes #1859 -- postfix if preceding an unparenthesized single-line function body 2011-12-18 12:55:21 -05:00
Michael Ficarra 6d6a5f609a fixes #1844: bound functions in nested comprehensions
causing empty var statements
2011-11-10 03:08:38 -05:00
Jeremy Ashkenas 981db17b8f Adopting coco-style efficient bound functions for the common case ... but not for class/prototypes. 2011-09-25 21:44:23 -04:00
Jeremy Ashkenas 19849e66d4 renaming wordy test titles. 2011-04-23 13:35:15 -04:00