Fixing #700. Block comment for constructor now appears above the constructor declaration.
This commit is contained in:
parent
df46fb8c68
commit
648d6432eb
|
@ -4,7 +4,9 @@
|
|||
_ref = require('./helpers'), include = _ref.include, count = _ref.count, starts = _ref.starts, compact = _ref.compact, last = _ref.last;
|
||||
exports.Lexer = (function() {
|
||||
Lexer = (function() {
|
||||
function Lexer() {};
|
||||
function Lexer() {
|
||||
return this;
|
||||
};
|
||||
return Lexer;
|
||||
})();
|
||||
Lexer.prototype.tokenize = function(code, options) {
|
||||
|
|
10
lib/nodes.js
10
lib/nodes.js
|
@ -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();
|
||||
|
|
|
@ -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;
|
||||
include = require('./helpers').include;
|
||||
exports.Rewriter = (function() {
|
||||
function Rewriter() {};
|
||||
function Rewriter() {
|
||||
return this;
|
||||
};
|
||||
return Rewriter;
|
||||
})();
|
||||
exports.Rewriter.prototype.rewrite = function(_arg) {
|
||||
|
|
|
@ -787,7 +787,7 @@ exports.Class = class Class extends Base
|
|||
new Call applied, [new Literal('this'), new Literal('arguments')]
|
||||
]))
|
||||
else
|
||||
constructor = new Code
|
||||
constructor = new Code [], new Expressions [new Return new Literal 'this']
|
||||
|
||||
for prop in @properties
|
||||
[pvar, func] = [prop.variable, prop.value]
|
||||
|
@ -803,6 +803,7 @@ exports.Class = class Class extends Base
|
|||
variable = new Value variable
|
||||
variable.namespaced = 0 < className.indexOf '.'
|
||||
constructor = func
|
||||
constructor.comment = props.expressions.pop() if props.expressions[props.expressions.length - 1] instanceof Comment
|
||||
continue
|
||||
if func instanceof Code and func.bound
|
||||
if prop.context is 'this'
|
||||
|
@ -994,9 +995,10 @@ exports.Code = class Code extends Base
|
|||
params = (param.compile(o) for param in params)
|
||||
@body.makeReturn() unless empty
|
||||
(o.scope.parameter(param)) for param in params
|
||||
comm = if @comment then @comment.compile(o) + '\n' else ''
|
||||
o.indent = @idt 2 if @className
|
||||
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}}"
|
||||
func = "#{open}#{ params.join(', ') }) {#{code}#{close}"
|
||||
o.scope.endLevel()
|
||||
|
|
Loading…
Reference in New Issue