mirror of
https://github.com/jashkenas/coffeescript.git
synced 2026-04-11 03:00:13 -04:00
FIXES #390: super() calls in constructor of classes that are defined as object properties
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
(function(){
|
(function(){
|
||||||
var AccessorNode, ArrayNode, AssignNode, BaseNode, CallNode, ClassNode, ClosureNode, CodeNode, CommentNode, CurryNode, ExistenceNode, Expressions, ExtendsNode, ForNode, IDENTIFIER, IS_STRING, IfNode, IndexNode, LiteralNode, ObjectNode, OpNode, ParentheticalNode, PushNode, RangeNode, ReturnNode, Scope, SliceNode, SplatNode, TAB, TRAILING_WHITESPACE, ThrowNode, TryNode, UTILITIES, ValueNode, WhileNode, _a, compact, del, flatten, helpers, index_of, literal, merge, utility;
|
var AccessorNode, ArrayNode, AssignNode, BaseNode, CallNode, ClassNode, ClosureNode, CodeNode, CommentNode, CurryNode, ExistenceNode, Expressions, ExtendsNode, ForNode, IDENTIFIER, IS_STRING, IfNode, IndexNode, LiteralNode, ObjectNode, OpNode, ParentheticalNode, PushNode, RangeNode, ReturnNode, Scope, SliceNode, SplatNode, TAB, TRAILING_WHITESPACE, ThrowNode, TryNode, UTILITIES, ValueNode, WhileNode, _a, compact, del, flatten, helpers, include, index_of, literal, merge, utility;
|
||||||
var __extends = function(child, parent) {
|
var __extends = function(child, parent) {
|
||||||
var ctor = function(){ };
|
var ctor = function(){ };
|
||||||
ctor.prototype = parent.prototype;
|
ctor.prototype = parent.prototype;
|
||||||
@@ -31,6 +31,7 @@
|
|||||||
flatten = _a.flatten;
|
flatten = _a.flatten;
|
||||||
merge = _a.merge;
|
merge = _a.merge;
|
||||||
del = _a.del;
|
del = _a.del;
|
||||||
|
include = _a.include;
|
||||||
index_of = _a.index_of;
|
index_of = _a.index_of;
|
||||||
//### BaseNode
|
//### BaseNode
|
||||||
// The **BaseNode** is the abstract base class for all nodes in the syntax tree.
|
// The **BaseNode** is the abstract base class for all nodes in the syntax tree.
|
||||||
@@ -962,7 +963,10 @@
|
|||||||
pvar = _e[0];
|
pvar = _e[0];
|
||||||
func = _e[1];
|
func = _e[1];
|
||||||
if (pvar && pvar.base.value === 'constructor' && func instanceof CodeNode) {
|
if (pvar && pvar.base.value === 'constructor' && func instanceof CodeNode) {
|
||||||
|
func.name = this.variable.compile(o);
|
||||||
func.body.push(new ReturnNode(literal('this')));
|
func.body.push(new ReturnNode(literal('this')));
|
||||||
|
this.variable = new ValueNode(this.variable);
|
||||||
|
this.variable.namespaced = include(func.name, '.');
|
||||||
constructor = new AssignNode(this.variable, func);
|
constructor = new AssignNode(this.variable, func);
|
||||||
} else {
|
} else {
|
||||||
if (pvar) {
|
if (pvar) {
|
||||||
@@ -1049,7 +1053,7 @@
|
|||||||
if (this.context === 'object') {
|
if (this.context === 'object') {
|
||||||
return ("" + name + ": " + val);
|
return ("" + name + ": " + val);
|
||||||
}
|
}
|
||||||
if (!(this.is_value() && this.variable.has_properties())) {
|
if (!(this.is_value() && (this.variable.has_properties() || this.variable.namespaced))) {
|
||||||
o.scope.find(name);
|
o.scope.find(name);
|
||||||
}
|
}
|
||||||
val = ("" + name + " = " + val);
|
val = ("" + name + " = " + val);
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ else
|
|||||||
Scope: this.Scope
|
Scope: this.Scope
|
||||||
|
|
||||||
# Import the helpers we plan to use.
|
# Import the helpers we plan to use.
|
||||||
{compact, flatten, merge, del, index_of}: helpers
|
{compact, flatten, merge, del, include, index_of}: helpers
|
||||||
|
|
||||||
#### BaseNode
|
#### BaseNode
|
||||||
|
|
||||||
@@ -649,7 +649,10 @@ exports.ClassNode: class ClassNode extends BaseNode
|
|||||||
for prop in @properties
|
for prop in @properties
|
||||||
[pvar, func]: [prop.variable, prop.value]
|
[pvar, func]: [prop.variable, prop.value]
|
||||||
if pvar and pvar.base.value is 'constructor' and func instanceof CodeNode
|
if pvar and pvar.base.value is 'constructor' and func instanceof CodeNode
|
||||||
|
func.name: @variable.compile(o)
|
||||||
func.body.push(new ReturnNode(literal('this')))
|
func.body.push(new ReturnNode(literal('this')))
|
||||||
|
@variable: new ValueNode @variable
|
||||||
|
@variable.namespaced: include func.name, '.'
|
||||||
constructor: new AssignNode(@variable, func)
|
constructor: new AssignNode(@variable, func)
|
||||||
else
|
else
|
||||||
if pvar
|
if pvar
|
||||||
@@ -719,7 +722,7 @@ exports.AssignNode: class AssignNode extends BaseNode
|
|||||||
@value.proto: proto if proto
|
@value.proto: proto if proto
|
||||||
val: @value.compile o
|
val: @value.compile o
|
||||||
return "$name: $val" if @context is 'object'
|
return "$name: $val" if @context is 'object'
|
||||||
o.scope.find name unless @is_value() and @variable.has_properties()
|
o.scope.find name unless @is_value() and (@variable.has_properties() or @variable.namespaced)
|
||||||
val: "$name = $val"
|
val: "$name = $val"
|
||||||
return "$@tab$val;" if stmt
|
return "$@tab$val;" if stmt
|
||||||
if top then val else "($val)"
|
if top then val else "($val)"
|
||||||
|
|||||||
@@ -1,17 +1,28 @@
|
|||||||
# Issue #380: problem with @ and instanceof
|
# Issue #380: problem with @ and instanceof
|
||||||
class ClassName
|
class ClassName
|
||||||
am_i: ->
|
am_i: ->
|
||||||
@ instanceof ClassName
|
@ instanceof ClassName
|
||||||
|
|
||||||
obj: new ClassName()
|
obj: new ClassName()
|
||||||
ok obj.am_i()
|
ok obj.am_i()
|
||||||
|
|
||||||
|
|
||||||
# Issue #383: Numbers that start with . not recognized
|
# Issue #383: Numbers that start with . not recognized
|
||||||
value: .25 + .75
|
value: .25 + .75
|
||||||
ok value is 1
|
ok value is 1
|
||||||
value: 0.0 + -.25 - -.75 + 0.0
|
value: 0.0 + -.25 - -.75 + 0.0
|
||||||
ok value is 0.5
|
ok value is 0.5
|
||||||
|
|
||||||
deepEqual [0..10], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
|
deepEqual [0..10], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
|
||||||
deepEqual [0...10], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
|
deepEqual [0...10], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
|
||||||
|
|
||||||
|
|
||||||
|
# Issue #390: super() calls in constructor of classes that are defined as object properties
|
||||||
|
class Hive
|
||||||
|
constructor: (name) -> @name: name
|
||||||
|
|
||||||
|
class Hive.Bee extends Hive
|
||||||
|
constructor: (name) -> super name
|
||||||
|
|
||||||
|
maya: new Hive.Bee('Maya')
|
||||||
|
ok maya.name is 'Maya'
|
||||||
|
|||||||
Reference in New Issue
Block a user