* bound method runtime check
* restore bound method tests
* bound method tests
* test bound method in prop-named class
* run check against parent class
* dummy commit
* remove comment
* rename to boundMethodCheck
* fixes from code review
* use ref to own class for check
* fixes from code review
* remove unneeded param
Bound methods are implemented as assignments to `this` in the
constructor. In derived classes, where `this` is unavailable until
after `super` has been called, the binding is applied and assigned after
the `super` call. This means that any references to 'bound' methods
reachable from the parent constructor will actually point to the unbound
prototype methods.
This can lead to very subtle bugs where a method that is thought to be
bound is handed off and later called with an incorrect context, and the
only defence is for users to be vigilant about referencing bound methods
in constructors.
* Compile all super calls to ES2015 super
This breaks using `super` in non-methods, meaning several tests are
failing. Self-compilation still works.
* Use bound functions for IIFEs containing `super`
`super` can only be called directly in a method, or in an arrow
function.
* Fix handling of `class @A extends A`
This behaviour worked 'for free' when the parent reference was being
cached by the executable class body wrapper. There now needs to be
special handling in place to check if the parent name matches the class
name, and if so to cache the parent reference.
* Fix tests broken by compiling ES2015 `super`
* Disallow bare super
This removes syntax support for 'bare' super calls, e.g.:
class B extends A
constructor: -> super
`super` must now always be followed with arguments like a regular
function call. This also removes the capability of implicitly forwarding
arguments. The above can be equivalently be written as:
class B extends A
constructor: -> super arguments...
* Support super with accessors
`super` with following accessor(s) is now compiled to ES2015
equivalents. In particular, expressions such as `super.name`,
`super[name]`, and also `super.name.prop` are all now valid, and can be
used as expected as calls (i.e. `super.name()`) or in expressions (i.e.
`if super.name? ...`).
`super` without accessors is compiled to a constructor super call in a
constructor, and otherwise, as before, to a super call to the method of
the same name, i.e.
speak: -> super()
...is equivalent to
speak: -> super.speak()
A neat side-effect of the changes is that existential calls now work
properly with super, meaning `super?()` will only call if the super
property exists (and is a function). This is not valid for super in
constructors.
* Prevent calling `super` methods with `new`
This fixes a bug in the previous super handling whereby using the `new`
operator with a `super` call would silently drop the `new`. This is now
an explicit compiler error, as it is invalid JS at runtime.
* Clean up some old super handling code
This was mostly code for tracking the source classes and variables for
methods, which were needed to build the old lookups on `__super__`.
* Add TODO to improve bare super parse error
* Add some TODOs to improve some of the class tests
* Added support for for-from loop, see #3832
* for-from: remove extra newline and add support for ranges
* for-from: tidy up the lexer
* for-from: add support for patterns
* for-from: fix bad alignment
* for-from: add two more tests
* for-from: fix test "for-from loops over generators"
See explanation here: https://github.com/jashkenas/coffeescript/pull/4306#issuecomment-257066877
* for-from: delete leftover console.log
* Refactor the big `if` block in the lexer to be as minimal a change from `master` as we can get away with
* Cleanup to make more idiomatic, remove trailing whitespace, minor performance improvements
* for-from: move code from one file to another
* for-from: clean up whitespace
* for-from: lexer bikeshedding
* Move "own is not supported in for-from loops" test into error_messages.coffee; improve error message so that "own" is underlined
* Revert unnecessary changes, to minimize the lines of code modified by this PR
Let me know if there's something I should be doing differently as this is my first contribution to coffeescript.
I fixed the reported issue where a generated variable could clash with a user-defined one in a try/catch block.
I added a test for a few scenarios with different variable names for a try/catch, to confirm the fix and avoid regressions.
case to show it's required.
What's going on: inside of Coffee-generated closures, calling `super()`
is implicitly making use of `this` (or explicitly doing so if you look
at the output code), so we have to pass `this` through closures as if
`@` is being accessed within the closure. So, just add one more
condition to the list in `Closure::literalThis`