Fixing #700. Block comment for constructor now appears above the constructor declaration.

This commit is contained in:
Timothy Jones
2010-10-19 20:39:58 +13:00
parent df46fb8c68
commit 648d6432eb
4 changed files with 17 additions and 7 deletions

View File

@@ -906,7 +906,7 @@
applied = new Value(this.parent, [new Accessor(new Literal('apply'))]);
constructor = new Code([], new Expressions([new Call(applied, [new Literal('this'), new Literal('arguments')])]));
} else {
constructor = new Code;
constructor = new Code([], new Expressions([new Return(new Literal('this'))]));
}
for (_i = 0, _len = (_ref2 = this.properties).length; _i < _len; _i++) {
prop = _ref2[_i];
@@ -928,6 +928,9 @@
variable = new Value(variable);
variable.namespaced = 0 < className.indexOf('.');
constructor = func;
if (props.expressions[props.expressions.length - 1] instanceof Comment) {
constructor.comment = props.expressions.pop();
}
continue;
}
if (func instanceof Code && func.bound) {
@@ -1117,7 +1120,7 @@
__extends(Code, Base);
Code.prototype.children = ['params', 'body'];
Code.prototype.compileNode = function(o) {
var _i, _len, _len2, _ref2, _ref3, _result, close, code, empty, func, i, open, param, params, sharedScope, splat, top, value;
var _i, _len, _len2, _ref2, _ref3, _result, close, code, comm, empty, func, i, open, param, params, sharedScope, splat, top, value;
sharedScope = del(o, 'sharedScope');
top = del(o, 'top');
o.scope = sharedScope || new Scope(o.scope, this.body, this);
@@ -1169,11 +1172,12 @@
param = params[_i];
(o.scope.parameter(param));
}
comm = this.comment ? this.comment.compile(o) + '\n' : '';
if (this.className) {
o.indent = this.idt(2);
}
code = this.body.expressions.length ? ("\n" + (this.body.compileWithDeclarations(o)) + "\n") : '';
open = this.className ? ("(function() {\n" + (this.idt(1)) + "function " + (this.className) + "(") : "function(";
open = this.className ? ("(function() {\n" + comm + (this.idt(1)) + "function " + (this.className) + "(") : "function(";
close = this.className ? ("" + (code && this.idt(1)) + "};\n" + (this.idt(1)) + "return " + (this.className) + ";\n" + (this.tab) + "})()") : ("" + (code && this.tab) + "}");
func = ("" + open + (params.join(', ')) + ") {" + code + close);
o.scope.endLevel();