Skip to content

Commit 352130c

Browse files
committed
start writing changelog
1 parent caa724d commit 352130c

File tree

1 file changed

+78
-0
lines changed

1 file changed

+78
-0
lines changed

CHANGELOG.md

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,82 @@
11

2+
# MoonScript v0.4.0 (2015-12-06)
3+
4+
## Changes to `super`
5+
6+
`super` now looks up the parent method via the class reference, instead of a
7+
(fixed) closure to the parent class.
8+
9+
Given the following code:
10+
11+
```moonscript
12+
class MyThing extends OtherThing
13+
the_method: =>
14+
super!
15+
```
16+
17+
In the past `super` would compile to something like this:
18+
19+
```lua
20+
_parent_0.the_method(self)
21+
```
22+
23+
Where `_parent_0` was an internal local variable that contains a reference to
24+
the parent class. Because the reference to parent is an internal local
25+
variable, you could never swap out the parent unless resorting to the debug
26+
library.
27+
28+
This version will compile to:
29+
30+
```lua
31+
_class_0.__parent.__base.the_method(self)
32+
```
33+
34+
Where `_class_0` is an internal local variable that contains the current class (`MyThing`).
35+
36+
Another difference is that the instance method is looked up on `__base` instead
37+
of the class. The old variation would trigger the metamethod for looking up on
38+
the instance, but a class method of the same name could conflict, take
39+
precedence, and be retuned instead. By referencing `__base` directly we avoid
40+
this issue.
41+
42+
### Super on class methods
43+
44+
`super` can now be used on class methods. It works exactly as you would expect.
45+
46+
```moonscript
47+
class MyThing extends OtherThing
48+
@static_method: =>
49+
print super!
50+
```
51+
52+
Calling `super` will compile to:
53+
54+
```moonscript
55+
_class_0.__parent.static_method(self)
56+
```
57+
58+
### Improved scoping for super
59+
60+
The scoping of super is more intelligent. You can warp your methods in other
61+
code and `super` will still generate correctly. For example, syntax like this
62+
will now work as expected:
63+
64+
```moonscript
65+
class Sub extends Base
66+
value: if debugging
67+
=> super! + 100
68+
else
69+
=> super! + 10
70+
71+
other_value: some_decorator {
72+
the_func: =>
73+
super!
74+
}
75+
```
76+
77+
`super` will refer to the lexically closest class declaration to find the name
78+
of the method it should call on the parent.
79+
280
# MoonScript v0.3.2 (2015-6-01)
381

482
## Bug Fixes

0 commit comments

Comments
 (0)