making inner comments work within class definitions

This commit is contained in:
Jeremy Ashkenas
2010-02-27 19:03:23 -05:00
parent 1c7e4c4203
commit 4ec7514d10
3 changed files with 11 additions and 6 deletions

View File

@@ -675,13 +675,15 @@
_a = this.properties; _a = this.properties;
for (_b = 0, _c = _a.length; _b < _c; _b++) { for (_b = 0, _c = _a.length; _b < _c; _b++) {
prop = _a[_b]; prop = _a[_b];
if (prop.variable.base.value === 'constructor') { if (prop.variable && prop.variable.base.value === 'constructor') {
func = prop.value; func = prop.value;
func.body.push(new ReturnNode(new LiteralNode('this'))); func.body.push(new ReturnNode(new LiteralNode('this')));
constructor = new AssignNode(this.variable, func); constructor = new AssignNode(this.variable, func);
} else { } else {
val = new ValueNode(this.variable, [new AccessorNode(prop.variable, 'prototype')]); if (prop.variable) {
prop = new AssignNode(val, prop.value); val = new ValueNode(this.variable, [new AccessorNode(prop.variable, 'prototype')]);
prop = new AssignNode(val, prop.value);
}
props.push(prop); props.push(prop);
} }
} }

View File

@@ -538,13 +538,14 @@ ClassNode: exports.ClassNode: inherit BaseNode, {
ret: del o, 'returns' ret: del o, 'returns'
for prop in @properties for prop in @properties
if prop.variable.base.value is 'constructor' if prop.variable and prop.variable.base.value is 'constructor'
func: prop.value func: prop.value
func.body.push(new ReturnNode(new LiteralNode('this'))) func.body.push(new ReturnNode(new LiteralNode('this')))
constructor: new AssignNode(@variable, func) constructor: new AssignNode(@variable, func)
else else
val: new ValueNode(@variable, [new AccessorNode(prop.variable, 'prototype')]) if prop.variable
prop: new AssignNode(val, prop.value) val: new ValueNode(@variable, [new AccessorNode(prop.variable, 'prototype')])
prop: new AssignNode(val, prop.value)
props.push prop props.push prop
constructor: new AssignNode(@variable, new CodeNode()) unless constructor constructor: new AssignNode(@variable, new CodeNode()) unless constructor

View File

@@ -13,6 +13,8 @@ class SecondChild extends FirstChild
class ThirdChild extends SecondChild class ThirdChild extends SecondChild
constructor: -> constructor: ->
@array: [1, 2, 3] @array: [1, 2, 3]
# Gratuitous comment for testing.
func: (string) -> func: (string) ->
super('three/') + string super('three/') + string