Core Compiler is JSLint-free again, after removing a couple extra semicolons that snuck in when if statements compiled at the top level.
This commit is contained in:
parent
ead9b1041c
commit
ca18f1fad6
|
@ -10,7 +10,7 @@
|
||||||
require.registerExtension('.coffee', function(content) {
|
require.registerExtension('.coffee', function(content) {
|
||||||
return compile(content);
|
return compile(content);
|
||||||
});
|
});
|
||||||
};
|
}
|
||||||
} else {
|
} else {
|
||||||
this.exports = (this.CoffeeScript = {});
|
this.exports = (this.CoffeeScript = {});
|
||||||
Lexer = this.Lexer;
|
Lexer = this.Lexer;
|
||||||
|
@ -67,7 +67,7 @@
|
||||||
tag = _c[_b];
|
tag = _c[_b];
|
||||||
if (tag.type === 'text/coffeescript') {
|
if (tag.type === 'text/coffeescript') {
|
||||||
_a.push(eval(exports.compile(tag.innerHTML)));
|
_a.push(eval(exports.compile(tag.innerHTML)));
|
||||||
};
|
}
|
||||||
}
|
}
|
||||||
return _a;
|
return _a;
|
||||||
};
|
};
|
||||||
|
|
|
@ -36,7 +36,7 @@
|
||||||
item = _c[_b];
|
item = _c[_b];
|
||||||
if (item) {
|
if (item) {
|
||||||
_a.push(item);
|
_a.push(item);
|
||||||
};
|
}
|
||||||
}
|
}
|
||||||
return _a;
|
return _a;
|
||||||
});
|
});
|
||||||
|
@ -86,7 +86,7 @@
|
||||||
memo = memo.concat(item);
|
memo = memo.concat(item);
|
||||||
} else {
|
} else {
|
||||||
memo.push(item);
|
memo.push(item);
|
||||||
};
|
}
|
||||||
}
|
}
|
||||||
return memo;
|
return memo;
|
||||||
});
|
});
|
||||||
|
|
|
@ -508,7 +508,7 @@
|
||||||
tok = _e[idx];
|
tok = _e[idx];
|
||||||
if (tok[0] === 'CALL_END') {
|
if (tok[0] === 'CALL_END') {
|
||||||
(tok[0] = ')');
|
(tok[0] = ')');
|
||||||
};
|
}
|
||||||
}
|
}
|
||||||
nested.pop();
|
nested.pop();
|
||||||
tokens.push(['TOKENS', nested]);
|
tokens.push(['TOKENS', nested]);
|
||||||
|
|
42
lib/nodes.js
42
lib/nodes.js
|
@ -38,7 +38,7 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
top = this.topSensitive() ? this.options.top : del(this.options, 'top');
|
top = this.topSensitive() ? this.options.top : del(this.options, 'top');
|
||||||
closure = this.isStatement() && !this.isPureStatement() && !top && !this.options.asStatement && !(this instanceof CommentNode) && !this.containsPureStatement();
|
closure = this.isStatement(o) && !this.isPureStatement() && !top && !this.options.asStatement && !(this instanceof CommentNode) && !this.containsPureStatement();
|
||||||
return closure ? this.compileClosure(this.options) : this.compileNode(this.options);
|
return closure ? this.compileClosure(this.options) : this.compileNode(this.options);
|
||||||
};
|
};
|
||||||
BaseNode.prototype.compileClosure = function(o) {
|
BaseNode.prototype.compileClosure = function(o) {
|
||||||
|
@ -246,7 +246,7 @@
|
||||||
compiledNode = node.compile(merge(o, {
|
compiledNode = node.compile(merge(o, {
|
||||||
top: true
|
top: true
|
||||||
}));
|
}));
|
||||||
return node.isStatement() ? compiledNode : ("" + (this.idt()) + (compiledNode) + ";");
|
return node.isStatement(o) ? compiledNode : ("" + (this.idt()) + (compiledNode) + ";");
|
||||||
};
|
};
|
||||||
return Expressions;
|
return Expressions;
|
||||||
})();
|
})();
|
||||||
|
@ -272,8 +272,8 @@
|
||||||
LiteralNode.prototype.isPureStatement = LiteralNode.prototype.isStatement;
|
LiteralNode.prototype.isPureStatement = LiteralNode.prototype.isStatement;
|
||||||
LiteralNode.prototype.compileNode = function(o) {
|
LiteralNode.prototype.compileNode = function(o) {
|
||||||
var end, idt;
|
var end, idt;
|
||||||
idt = this.isStatement() ? this.idt() : '';
|
idt = this.isStatement(o) ? this.idt() : '';
|
||||||
end = this.isStatement() ? ';' : '';
|
end = this.isStatement(o) ? ';' : '';
|
||||||
return idt + this.value + end;
|
return idt + this.value + end;
|
||||||
};
|
};
|
||||||
LiteralNode.prototype.toString = function(idt) {
|
LiteralNode.prototype.toString = function(idt) {
|
||||||
|
@ -307,7 +307,7 @@
|
||||||
return ReturnNode.__superClass__.compile.call(this, o);
|
return ReturnNode.__superClass__.compile.call(this, o);
|
||||||
};
|
};
|
||||||
ReturnNode.prototype.compileNode = function(o) {
|
ReturnNode.prototype.compileNode = function(o) {
|
||||||
if (this.expression.isStatement()) {
|
if (this.expression.isStatement(o)) {
|
||||||
o.asStatement = true;
|
o.asStatement = true;
|
||||||
}
|
}
|
||||||
return "" + (this.tab) + "return " + (this.expression.compile(o)) + ";";
|
return "" + (this.tab) + "return " + (this.expression.compile(o)) + ";";
|
||||||
|
@ -346,8 +346,8 @@
|
||||||
ValueNode.prototype.unwrap = function() {
|
ValueNode.prototype.unwrap = function() {
|
||||||
return this.properties.length ? this : this.base;
|
return this.properties.length ? this : this.base;
|
||||||
};
|
};
|
||||||
ValueNode.prototype.isStatement = function() {
|
ValueNode.prototype.isStatement = function(o) {
|
||||||
return this.base.isStatement && this.base.isStatement() && !this.hasProperties();
|
return this.base.isStatement && this.base.isStatement(o) && !this.hasProperties();
|
||||||
};
|
};
|
||||||
ValueNode.prototype.isNumber = function() {
|
ValueNode.prototype.isNumber = function() {
|
||||||
return this.base instanceof LiteralNode && this.base.value.match(NUMBER);
|
return this.base instanceof LiteralNode && this.base.value.match(NUMBER);
|
||||||
|
@ -481,7 +481,7 @@
|
||||||
arg = _c[_b];
|
arg = _c[_b];
|
||||||
if (arg instanceof SplatNode) {
|
if (arg instanceof SplatNode) {
|
||||||
compilation = this.compileSplat(o);
|
compilation = this.compileSplat(o);
|
||||||
};
|
}
|
||||||
}
|
}
|
||||||
if (!(compilation)) {
|
if (!(compilation)) {
|
||||||
args = (function() {
|
args = (function() {
|
||||||
|
@ -704,7 +704,7 @@
|
||||||
prop = _d[_c];
|
prop = _d[_c];
|
||||||
if (!(prop instanceof CommentNode)) {
|
if (!(prop instanceof CommentNode)) {
|
||||||
_b.push(prop);
|
_b.push(prop);
|
||||||
};
|
}
|
||||||
}
|
}
|
||||||
return _b;
|
return _b;
|
||||||
}).call(this);
|
}).call(this);
|
||||||
|
@ -885,7 +885,7 @@
|
||||||
AssignNode.prototype.compileNode = function(o) {
|
AssignNode.prototype.compileNode = function(o) {
|
||||||
var last, match, name, proto, stmt, top, val;
|
var last, match, name, proto, stmt, top, val;
|
||||||
top = del(o, 'top');
|
top = del(o, 'top');
|
||||||
if (this.isStatement()) {
|
if (this.isStatement(o)) {
|
||||||
return this.compilePatternMatch(o);
|
return this.compilePatternMatch(o);
|
||||||
}
|
}
|
||||||
if (this.isValue() && this.variable.isSplice()) {
|
if (this.isValue() && this.variable.isSplice()) {
|
||||||
|
@ -920,7 +920,7 @@
|
||||||
AssignNode.prototype.compilePatternMatch = function(o) {
|
AssignNode.prototype.compilePatternMatch = function(o) {
|
||||||
var _b, _c, _d, accessClass, assigns, code, i, idx, isString, obj, oindex, olength, splat, val, valVar, value;
|
var _b, _c, _d, accessClass, assigns, code, i, idx, isString, obj, oindex, olength, splat, val, valVar, value;
|
||||||
valVar = o.scope.freeVariable();
|
valVar = o.scope.freeVariable();
|
||||||
value = this.value.isStatement() ? ClosureNode.wrap(this.value) : this.value;
|
value = this.value.isStatement(o) ? ClosureNode.wrap(this.value) : this.value;
|
||||||
assigns = [("" + (this.tab) + (valVar) + " = " + (value.compile(o)) + ";")];
|
assigns = [("" + (this.tab) + (valVar) + " = " + (value.compile(o)) + ";")];
|
||||||
o.top = true;
|
o.top = true;
|
||||||
o.asStatement = true;
|
o.asStatement = true;
|
||||||
|
@ -1213,7 +1213,7 @@
|
||||||
}));
|
}));
|
||||||
} else {
|
} else {
|
||||||
post = '';
|
post = '';
|
||||||
};
|
}
|
||||||
return "" + (pre) + " {\n" + (this.body.compile(o)) + "\n" + (this.tab) + "}" + (post);
|
return "" + (pre) + " {\n" + (this.body.compile(o)) + "\n" + (this.tab) + "}" + (post);
|
||||||
};
|
};
|
||||||
return WhileNode;
|
return WhileNode;
|
||||||
|
@ -1227,7 +1227,7 @@
|
||||||
this.flip = !!flip;
|
this.flip = !!flip;
|
||||||
if (this.first instanceof ValueNode && this.first.base instanceof ObjectNode) {
|
if (this.first instanceof ValueNode && this.first.base instanceof ObjectNode) {
|
||||||
this.first = new ParentheticalNode(this.first);
|
this.first = new ParentheticalNode(this.first);
|
||||||
};
|
}
|
||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
__extends(OpNode, BaseNode);
|
__extends(OpNode, BaseNode);
|
||||||
|
@ -1448,8 +1448,8 @@
|
||||||
__extends(ParentheticalNode, BaseNode);
|
__extends(ParentheticalNode, BaseNode);
|
||||||
ParentheticalNode.prototype["class"] = 'ParentheticalNode';
|
ParentheticalNode.prototype["class"] = 'ParentheticalNode';
|
||||||
ParentheticalNode.prototype.children = ['expression'];
|
ParentheticalNode.prototype.children = ['expression'];
|
||||||
ParentheticalNode.prototype.isStatement = function() {
|
ParentheticalNode.prototype.isStatement = function(o) {
|
||||||
return this.expression.isStatement();
|
return this.expression.isStatement(o);
|
||||||
};
|
};
|
||||||
ParentheticalNode.prototype.makeReturn = function() {
|
ParentheticalNode.prototype.makeReturn = function() {
|
||||||
return this.expression.makeReturn();
|
return this.expression.makeReturn();
|
||||||
|
@ -1461,7 +1461,7 @@
|
||||||
var code, l, top;
|
var code, l, top;
|
||||||
top = del(o, 'top');
|
top = del(o, 'top');
|
||||||
code = this.expression.compile(o);
|
code = this.expression.compile(o);
|
||||||
if (this.isStatement()) {
|
if (this.isStatement(o)) {
|
||||||
return (top ? this.tab + code + ';' : code);
|
return (top ? this.tab + code + ';' : code);
|
||||||
}
|
}
|
||||||
l = code.length;
|
l = code.length;
|
||||||
|
@ -1583,7 +1583,7 @@
|
||||||
}
|
}
|
||||||
if (this.guard) {
|
if (this.guard) {
|
||||||
body = Expressions.wrap([new IfNode(this.guard, body)]);
|
body = Expressions.wrap([new IfNode(this.guard, body)]);
|
||||||
};
|
}
|
||||||
if (codeInBody) {
|
if (codeInBody) {
|
||||||
if (range) {
|
if (range) {
|
||||||
body.unshift(literal(("var " + (name) + " = " + (ivar))));
|
body.unshift(literal(("var " + (name) + " = " + (ivar))));
|
||||||
|
@ -1682,8 +1682,8 @@
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
IfNode.prototype.isStatement = function() {
|
IfNode.prototype.isStatement = function(o) {
|
||||||
return this.statement = this.statement || (!!(this.tags.statement || this.bodyNode().isStatement() || (this.elseBody && this.elseBodyNode().isStatement())));
|
return this.statement = this.statement || (!!((o && o.top) || this.tags.statement || this.bodyNode().isStatement(o) || (this.elseBody && this.elseBodyNode().isStatement(o))));
|
||||||
};
|
};
|
||||||
IfNode.prototype.compileCondition = function(o) {
|
IfNode.prototype.compileCondition = function(o) {
|
||||||
var _b, _c, _d, _e, cond;
|
var _b, _c, _d, _e, cond;
|
||||||
|
@ -1697,7 +1697,7 @@
|
||||||
}).call(this).join(' || ');
|
}).call(this).join(' || ');
|
||||||
};
|
};
|
||||||
IfNode.prototype.compileNode = function(o) {
|
IfNode.prototype.compileNode = function(o) {
|
||||||
return o.top || this.isStatement() ? this.compileStatement(o) : this.compileTernary(o);
|
return this.isStatement(o) ? this.compileStatement(o) : this.compileTernary(o);
|
||||||
};
|
};
|
||||||
IfNode.prototype.makeReturn = function() {
|
IfNode.prototype.makeReturn = function() {
|
||||||
if (this.isStatement()) {
|
if (this.isStatement()) {
|
||||||
|
@ -1721,7 +1721,7 @@
|
||||||
condO = merge(o);
|
condO = merge(o);
|
||||||
o.indent = this.idt(1);
|
o.indent = this.idt(1);
|
||||||
o.top = true;
|
o.top = true;
|
||||||
ifDent = child || (top && !this.isStatement()) ? '' : this.idt();
|
ifDent = child || (top && !this.isStatement(o)) ? '' : this.idt();
|
||||||
comDent = child ? this.idt() : '';
|
comDent = child ? this.idt() : '';
|
||||||
body = this.body.compile(o);
|
body = this.body.compile(o);
|
||||||
ifPart = ("" + (ifDent) + "if (" + (this.compileCondition(condO)) + ") {\n" + (body) + "\n" + (this.tab) + "}");
|
ifPart = ("" + (ifDent) + "if (" + (this.compileCondition(condO)) + ") {\n" + (body) + "\n" + (this.tab) + "}");
|
||||||
|
|
|
@ -77,13 +77,13 @@
|
||||||
this.tokens.splice(i - 2, 1);
|
this.tokens.splice(i - 2, 1);
|
||||||
} else {
|
} else {
|
||||||
this.tokens.splice(i, 0, after);
|
this.tokens.splice(i, 0, after);
|
||||||
};
|
}
|
||||||
} else if (prev && !('TERMINATOR' === (_d = prev[0]) || 'INDENT' === _d || 'OUTDENT' === _d)) {
|
} else if (prev && !('TERMINATOR' === (_d = prev[0]) || 'INDENT' === _d || 'OUTDENT' === _d)) {
|
||||||
if (post && post[0] === 'TERMINATOR' && after && after[0] === 'OUTDENT') {
|
if (post && post[0] === 'TERMINATOR' && after && after[0] === 'OUTDENT') {
|
||||||
this.tokens.splice.apply(this.tokens, [i + 2, 0].concat(this.tokens.splice(i, 2)));
|
this.tokens.splice.apply(this.tokens, [i + 2, 0].concat(this.tokens.splice(i, 2)));
|
||||||
if (this.tokens[i + 2][0] !== 'TERMINATOR') {
|
if (this.tokens[i + 2][0] !== 'TERMINATOR') {
|
||||||
this.tokens.splice(i + 2, 0, ['TERMINATOR', "\n", prev[2]]);
|
this.tokens.splice(i + 2, 0, ['TERMINATOR', "\n", prev[2]]);
|
||||||
};
|
}
|
||||||
} else {
|
} else {
|
||||||
this.tokens.splice(i, 0, ['TERMINATOR', "\n", prev[2]]);
|
this.tokens.splice(i, 0, ['TERMINATOR', "\n", prev[2]]);
|
||||||
}
|
}
|
||||||
|
@ -148,10 +148,10 @@
|
||||||
var action, condition, idx, last;
|
var action, condition, idx, last;
|
||||||
if (include(EXPRESSION_START, token[0])) {
|
if (include(EXPRESSION_START, token[0])) {
|
||||||
stack.push((token[0] === 'INDENT' && (this.tag(i - 1) === '{')) ? '{' : token[0]);
|
stack.push((token[0] === 'INDENT' && (this.tag(i - 1) === '{')) ? '{' : token[0]);
|
||||||
};
|
}
|
||||||
if (include(EXPRESSION_END, token[0])) {
|
if (include(EXPRESSION_END, token[0])) {
|
||||||
stack.pop();
|
stack.pop();
|
||||||
};
|
}
|
||||||
last = stack[stack.length - 1];
|
last = stack[stack.length - 1];
|
||||||
if (token[0] === ':' && (!last || last[0] !== '{')) {
|
if (token[0] === ':' && (!last || last[0] !== '{')) {
|
||||||
stack.push('{');
|
stack.push('{');
|
||||||
|
@ -287,7 +287,7 @@
|
||||||
value = _d[key];
|
value = _d[key];
|
||||||
if (value > 0) {
|
if (value > 0) {
|
||||||
_c.push(key);
|
_c.push(key);
|
||||||
};
|
}
|
||||||
}
|
}
|
||||||
return _c;
|
return _c;
|
||||||
})();
|
})();
|
||||||
|
|
|
@ -83,7 +83,7 @@
|
||||||
val = _b[key];
|
val = _b[key];
|
||||||
if (val === 'var') {
|
if (val === 'var') {
|
||||||
_a.push(key);
|
_a.push(key);
|
||||||
};
|
}
|
||||||
}
|
}
|
||||||
return _a;
|
return _a;
|
||||||
}).call(this).sort();
|
}).call(this).sort();
|
||||||
|
@ -96,7 +96,7 @@
|
||||||
val = _b[key];
|
val = _b[key];
|
||||||
if (val.assigned) {
|
if (val.assigned) {
|
||||||
_a.push(("" + (key) + " = " + (val.value)));
|
_a.push(("" + (key) + " = " + (val.value)));
|
||||||
};
|
}
|
||||||
}
|
}
|
||||||
return _a;
|
return _a;
|
||||||
};
|
};
|
||||||
|
|
|
@ -46,7 +46,7 @@ exports.BaseNode = class BaseNode
|
||||||
del @options, 'operation'
|
del @options, 'operation'
|
||||||
del @options, 'chainRoot' unless this instanceof AccessorNode or this instanceof IndexNode
|
del @options, 'chainRoot' unless this instanceof AccessorNode or this instanceof IndexNode
|
||||||
top = if @topSensitive() then @options.top else del @options, 'top'
|
top = if @topSensitive() then @options.top else del @options, 'top'
|
||||||
closure = @isStatement() and not @isPureStatement() and not top and
|
closure = @isStatement(o) and not @isPureStatement() and not top and
|
||||||
not @options.asStatement and not (this instanceof CommentNode) and
|
not @options.asStatement and not (this instanceof CommentNode) and
|
||||||
not @containsPureStatement()
|
not @containsPureStatement()
|
||||||
if closure then @compileClosure(@options) else @compileNode(@options)
|
if closure then @compileClosure(@options) else @compileNode(@options)
|
||||||
|
@ -221,7 +221,7 @@ exports.Expressions = class Expressions extends BaseNode
|
||||||
compileExpression: (node, o) ->
|
compileExpression: (node, o) ->
|
||||||
@tab = o.indent
|
@tab = o.indent
|
||||||
compiledNode = node.compile merge o, top: true
|
compiledNode = node.compile merge o, top: true
|
||||||
if node.isStatement() then compiledNode else "#{@idt()}#{compiledNode};"
|
if node.isStatement(o) then compiledNode else "#{@idt()}#{compiledNode};"
|
||||||
|
|
||||||
# Wrap up the given nodes as an **Expressions**, unless it already happens
|
# Wrap up the given nodes as an **Expressions**, unless it already happens
|
||||||
# to be one.
|
# to be one.
|
||||||
|
@ -250,8 +250,8 @@ exports.LiteralNode = class LiteralNode extends BaseNode
|
||||||
isPureStatement: LiteralNode::isStatement
|
isPureStatement: LiteralNode::isStatement
|
||||||
|
|
||||||
compileNode: (o) ->
|
compileNode: (o) ->
|
||||||
idt = if @isStatement() then @idt() else ''
|
idt = if @isStatement(o) then @idt() else ''
|
||||||
end = if @isStatement() then ';' else ''
|
end = if @isStatement(o) then ';' else ''
|
||||||
idt + @value + end
|
idt + @value + end
|
||||||
|
|
||||||
toString: (idt) ->
|
toString: (idt) ->
|
||||||
|
@ -279,7 +279,7 @@ exports.ReturnNode = class ReturnNode extends BaseNode
|
||||||
super o
|
super o
|
||||||
|
|
||||||
compileNode: (o) ->
|
compileNode: (o) ->
|
||||||
o.asStatement = true if @expression.isStatement()
|
o.asStatement = true if @expression.isStatement(o)
|
||||||
"#{@tab}return #{@expression.compile(o)};"
|
"#{@tab}return #{@expression.compile(o)};"
|
||||||
|
|
||||||
#### ValueNode
|
#### ValueNode
|
||||||
|
@ -323,8 +323,8 @@ exports.ValueNode = class ValueNode extends BaseNode
|
||||||
if @properties.length then this else @base
|
if @properties.length then this else @base
|
||||||
|
|
||||||
# Values are considered to be statements if their base is a statement.
|
# Values are considered to be statements if their base is a statement.
|
||||||
isStatement: ->
|
isStatement: (o) ->
|
||||||
@base.isStatement and @base.isStatement() and not @hasProperties()
|
@base.isStatement and @base.isStatement(o) and not @hasProperties()
|
||||||
|
|
||||||
isNumber: ->
|
isNumber: ->
|
||||||
@base instanceof LiteralNode and @base.value.match NUMBER
|
@base instanceof LiteralNode and @base.value.match NUMBER
|
||||||
|
@ -775,7 +775,7 @@ exports.AssignNode = class AssignNode extends BaseNode
|
||||||
# has not been seen yet within the current scope, declare it.
|
# has not been seen yet within the current scope, declare it.
|
||||||
compileNode: (o) ->
|
compileNode: (o) ->
|
||||||
top = del o, 'top'
|
top = del o, 'top'
|
||||||
return @compilePatternMatch(o) if @isStatement()
|
return @compilePatternMatch(o) if @isStatement(o)
|
||||||
return @compileSplice(o) if @isValue() and @variable.isSplice()
|
return @compileSplice(o) if @isValue() and @variable.isSplice()
|
||||||
stmt = del o, 'asStatement'
|
stmt = del o, 'asStatement'
|
||||||
name = @variable.compile(o)
|
name = @variable.compile(o)
|
||||||
|
@ -798,7 +798,7 @@ exports.AssignNode = class AssignNode extends BaseNode
|
||||||
# for details.
|
# for details.
|
||||||
compilePatternMatch: (o) ->
|
compilePatternMatch: (o) ->
|
||||||
valVar = o.scope.freeVariable()
|
valVar = o.scope.freeVariable()
|
||||||
value = if @value.isStatement() then ClosureNode.wrap(@value) else @value
|
value = if @value.isStatement(o) then ClosureNode.wrap(@value) else @value
|
||||||
assigns = ["#{@tab}#{valVar} = #{ value.compile(o) };"]
|
assigns = ["#{@tab}#{valVar} = #{ value.compile(o) };"]
|
||||||
o.top = true
|
o.top = true
|
||||||
o.asStatement = true
|
o.asStatement = true
|
||||||
|
@ -1233,8 +1233,8 @@ exports.ParentheticalNode = class ParentheticalNode extends BaseNode
|
||||||
|
|
||||||
constructor: (@expression) ->
|
constructor: (@expression) ->
|
||||||
|
|
||||||
isStatement: ->
|
isStatement: (o) ->
|
||||||
@expression.isStatement()
|
@expression.isStatement(o)
|
||||||
|
|
||||||
makeReturn: ->
|
makeReturn: ->
|
||||||
@expression.makeReturn()
|
@expression.makeReturn()
|
||||||
|
@ -1245,7 +1245,7 @@ exports.ParentheticalNode = class ParentheticalNode extends BaseNode
|
||||||
compileNode: (o) ->
|
compileNode: (o) ->
|
||||||
top = del o, 'top'
|
top = del o, 'top'
|
||||||
code = @expression.compile(o)
|
code = @expression.compile(o)
|
||||||
if @isStatement()
|
if @isStatement(o)
|
||||||
return (if top then @tab + code + ';' else code)
|
return (if top then @tab + code + ';' else code)
|
||||||
l = code.length
|
l = code.length
|
||||||
code = code.substr(o, l-1) if code.substr(l-1, 1) is ';'
|
code = code.substr(o, l-1) if code.substr(l-1, 1) is ';'
|
||||||
|
@ -1404,14 +1404,14 @@ exports.IfNode = class IfNode extends BaseNode
|
||||||
|
|
||||||
# The **IfNode** only compiles into a statement if either of its bodies needs
|
# The **IfNode** only compiles into a statement if either of its bodies needs
|
||||||
# to be a statement. Otherwise a ternary is safe.
|
# to be a statement. Otherwise a ternary is safe.
|
||||||
isStatement: ->
|
isStatement: (o) ->
|
||||||
@statement or= !!(@tags.statement or @bodyNode().isStatement() or (@elseBody and @elseBodyNode().isStatement()))
|
@statement or= !!((o and o.top) or @tags.statement or @bodyNode().isStatement(o) or (@elseBody and @elseBodyNode().isStatement(o)))
|
||||||
|
|
||||||
compileCondition: (o) ->
|
compileCondition: (o) ->
|
||||||
(cond.compile(o) for cond in flatten([@condition])).join(' || ')
|
(cond.compile(o) for cond in flatten([@condition])).join(' || ')
|
||||||
|
|
||||||
compileNode: (o) ->
|
compileNode: (o) ->
|
||||||
if o.top or @isStatement() then @compileStatement(o) else @compileTernary(o)
|
if @isStatement(o) then @compileStatement(o) else @compileTernary(o)
|
||||||
|
|
||||||
makeReturn: ->
|
makeReturn: ->
|
||||||
if @isStatement()
|
if @isStatement()
|
||||||
|
@ -1433,7 +1433,7 @@ exports.IfNode = class IfNode extends BaseNode
|
||||||
condO = merge o
|
condO = merge o
|
||||||
o.indent = @idt 1
|
o.indent = @idt 1
|
||||||
o.top = true
|
o.top = true
|
||||||
ifDent = if child or (top and not @isStatement()) then '' else @idt()
|
ifDent = if child or (top and not @isStatement(o)) then '' else @idt()
|
||||||
comDent = if child then @idt() else ''
|
comDent = if child then @idt() else ''
|
||||||
body = @body.compile(o)
|
body = @body.compile(o)
|
||||||
ifPart = "#{ifDent}if (#{ @compileCondition(condO) }) {\n#{body}\n#{@tab}}"
|
ifPart = "#{ifDent}if (#{ @compileCondition(condO) }) {\n#{body}\n#{@tab}}"
|
||||||
|
|
Loading…
Reference in New Issue