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

@ -4,7 +4,9 @@
_ref = require('./helpers'), include = _ref.include, count = _ref.count, starts = _ref.starts, compact = _ref.compact, last = _ref.last; _ref = require('./helpers'), include = _ref.include, count = _ref.count, starts = _ref.starts, compact = _ref.compact, last = _ref.last;
exports.Lexer = (function() { exports.Lexer = (function() {
Lexer = (function() { Lexer = (function() {
function Lexer() {}; function Lexer() {
return this;
};
return Lexer; return Lexer;
})(); })();
Lexer.prototype.tokenize = function(code, options) { Lexer.prototype.tokenize = function(code, options) {

View File

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

View File

@ -2,7 +2,9 @@
var BALANCED_PAIRS, EXPRESSION_CLOSE, EXPRESSION_END, EXPRESSION_START, IMPLICIT_BLOCK, IMPLICIT_CALL, IMPLICIT_END, IMPLICIT_FUNC, INVERSES, LINEBREAKS, SINGLE_CLOSERS, SINGLE_LINERS, _i, _len, _ref, include, left, rite; var BALANCED_PAIRS, EXPRESSION_CLOSE, EXPRESSION_END, EXPRESSION_START, IMPLICIT_BLOCK, IMPLICIT_CALL, IMPLICIT_END, IMPLICIT_FUNC, INVERSES, LINEBREAKS, SINGLE_CLOSERS, SINGLE_LINERS, _i, _len, _ref, include, left, rite;
include = require('./helpers').include; include = require('./helpers').include;
exports.Rewriter = (function() { exports.Rewriter = (function() {
function Rewriter() {}; function Rewriter() {
return this;
};
return Rewriter; return Rewriter;
})(); })();
exports.Rewriter.prototype.rewrite = function(_arg) { exports.Rewriter.prototype.rewrite = function(_arg) {

View File

@ -787,7 +787,7 @@ exports.Class = class Class extends Base
new Call applied, [new Literal('this'), new Literal('arguments')] new Call applied, [new Literal('this'), new Literal('arguments')]
])) ]))
else else
constructor = new Code constructor = new Code [], new Expressions [new Return new Literal 'this']
for prop in @properties for prop in @properties
[pvar, func] = [prop.variable, prop.value] [pvar, func] = [prop.variable, prop.value]
@ -803,6 +803,7 @@ exports.Class = class Class extends Base
variable = new Value variable variable = new Value variable
variable.namespaced = 0 < className.indexOf '.' variable.namespaced = 0 < className.indexOf '.'
constructor = func constructor = func
constructor.comment = props.expressions.pop() if props.expressions[props.expressions.length - 1] instanceof Comment
continue continue
if func instanceof Code and func.bound if func instanceof Code and func.bound
if prop.context is 'this' if prop.context is 'this'
@ -994,9 +995,10 @@ exports.Code = class Code extends Base
params = (param.compile(o) for param in params) params = (param.compile(o) for param in params)
@body.makeReturn() unless empty @body.makeReturn() unless empty
(o.scope.parameter(param)) for param in params (o.scope.parameter(param)) for param in params
comm = if @comment then @comment.compile(o) + '\n' else ''
o.indent = @idt 2 if @className o.indent = @idt 2 if @className
code = if @body.expressions.length then "\n#{ @body.compileWithDeclarations(o) }\n" else '' code = if @body.expressions.length then "\n#{ @body.compileWithDeclarations(o) }\n" else ''
open = if @className then "(function() {\n#{@idt(1)}function #{@className}(" else "function(" open = if @className then "(function() {\n#{comm}#{@idt(1)}function #{@className}(" else "function("
close = if @className then "#{code and @idt(1)}};\n#{@idt(1)}return #{@className};\n#{@tab}})()" else "#{code and @tab}}" close = if @className then "#{code and @idt(1)}};\n#{@idt(1)}return #{@className};\n#{@tab}})()" else "#{code and @tab}}"
func = "#{open}#{ params.join(', ') }) {#{code}#{close}" func = "#{open}#{ params.join(', ') }) {#{code}#{close}"
o.scope.endLevel() o.scope.endLevel()