mirror of
https://github.com/jashkenas/coffeescript.git
synced 2026-02-18 19:34:27 -05:00
got extends back in the language -- use it together with super
This commit is contained in:
@@ -229,7 +229,7 @@
|
||||
</dict>
|
||||
<dict>
|
||||
<key>match</key>
|
||||
<string>\b(super|this)\b</string>
|
||||
<string>\b(super|this|extends)\b</string>
|
||||
<key>name</key>
|
||||
<string>variable.language.cs</string>
|
||||
</dict>
|
||||
|
||||
@@ -11,7 +11,7 @@ token BREAK CONTINUE
|
||||
token FOR IN WHILE
|
||||
token SWITCH WHEN
|
||||
token DELETE INSTANCEOF TYPEOF
|
||||
token SUPER
|
||||
token SUPER EXTENDS
|
||||
token NEWLINE
|
||||
token COMMENT
|
||||
token JS
|
||||
@@ -29,8 +29,8 @@ prechigh
|
||||
right '-=' '+=' '/=' '*='
|
||||
right DELETE INSTANCEOF TYPEOF
|
||||
left "."
|
||||
right THROW FOR IN WHILE NEW
|
||||
left UNLESS IF ELSE
|
||||
right THROW FOR IN WHILE NEW SUPER
|
||||
left UNLESS IF ELSE EXTENDS
|
||||
left ":" '||:' '&&:'
|
||||
right RETURN
|
||||
preclow
|
||||
@@ -81,6 +81,7 @@ rule
|
||||
| While
|
||||
| For
|
||||
| Switch
|
||||
| Extends
|
||||
| Comment
|
||||
;
|
||||
|
||||
@@ -254,6 +255,11 @@ rule
|
||||
| Super { result = val[0] }
|
||||
;
|
||||
|
||||
# Extending an object's prototype.
|
||||
Extends:
|
||||
Value EXTENDS Expression { result = ExtendsNode.new(val[0], val[2]) }
|
||||
;
|
||||
|
||||
# A generic function invocation.
|
||||
Invocation:
|
||||
Value "(" ArgList ")" { result = CallNode.new(val[0], val[2]) }
|
||||
|
||||
@@ -14,7 +14,7 @@ module CoffeeScript
|
||||
"break", "continue",
|
||||
"for", "in", "while",
|
||||
"switch", "when",
|
||||
"super",
|
||||
"super", "extends",
|
||||
"delete", "instanceof", "typeof"]
|
||||
|
||||
# Token matching regexes.
|
||||
|
||||
@@ -215,6 +215,20 @@ module CoffeeScript
|
||||
end
|
||||
end
|
||||
|
||||
# Node to extend an object's prototype with an ancestor object.
|
||||
class ExtendsNode < Node
|
||||
attr_reader :sub_object, :super_object
|
||||
|
||||
def initialize(sub_object, super_object)
|
||||
@sub_object, @super_object = sub_object, super_object
|
||||
end
|
||||
|
||||
def compile(o={})
|
||||
"#{@sub_object.compile(o)}.prototype.__proto__ = #{@super_object.compile(o)}"
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
# A value, indexed or dotted into, or vanilla.
|
||||
class ValueNode < Node
|
||||
attr_reader :literal, :properties, :last
|
||||
|
||||
Reference in New Issue
Block a user