1
0
Fork 0
mirror of https://github.com/jashkenas/coffeescript.git synced 2022-11-09 12:23:24 -05:00

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:
Jeremy Ashkenas 2010-08-14 11:42:19 -04:00
parent ead9b1041c
commit ca18f1fad6
7 changed files with 49 additions and 49 deletions

View file

@ -10,7 +10,7 @@
require.registerExtension('.coffee', function(content) {
return compile(content);
});
};
}
} else {
this.exports = (this.CoffeeScript = {});
Lexer = this.Lexer;
@ -67,7 +67,7 @@
tag = _c[_b];
if (tag.type === 'text/coffeescript') {
_a.push(eval(exports.compile(tag.innerHTML)));
};
}
}
return _a;
};

View file

@ -36,7 +36,7 @@
item = _c[_b];
if (item) {
_a.push(item);
};
}
}
return _a;
});
@ -86,7 +86,7 @@
memo = memo.concat(item);
} else {
memo.push(item);
};
}
}
return memo;
});

View file

@ -508,7 +508,7 @@
tok = _e[idx];
if (tok[0] === 'CALL_END') {
(tok[0] = ')');
};
}
}
nested.pop();
tokens.push(['TOKENS', nested]);

View file

@ -38,7 +38,7 @@
}
}
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);
};
BaseNode.prototype.compileClosure = function(o) {
@ -246,7 +246,7 @@
compiledNode = node.compile(merge(o, {
top: true
}));
return node.isStatement() ? compiledNode : ("" + (this.idt()) + (compiledNode) + ";");
return node.isStatement(o) ? compiledNode : ("" + (this.idt()) + (compiledNode) + ";");
};
return Expressions;
})();
@ -272,8 +272,8 @@
LiteralNode.prototype.isPureStatement = LiteralNode.prototype.isStatement;
LiteralNode.prototype.compileNode = function(o) {
var end, idt;
idt = this.isStatement() ? this.idt() : '';
end = this.isStatement() ? ';' : '';
idt = this.isStatement(o) ? this.idt() : '';
end = this.isStatement(o) ? ';' : '';
return idt + this.value + end;
};
LiteralNode.prototype.toString = function(idt) {
@ -307,7 +307,7 @@
return ReturnNode.__superClass__.compile.call(this, o);
};
ReturnNode.prototype.compileNode = function(o) {
if (this.expression.isStatement()) {
if (this.expression.isStatement(o)) {
o.asStatement = true;
}
return "" + (this.tab) + "return " + (this.expression.compile(o)) + ";";
@ -346,8 +346,8 @@
ValueNode.prototype.unwrap = function() {
return this.properties.length ? this : this.base;
};
ValueNode.prototype.isStatement = function() {
return this.base.isStatement && this.base.isStatement() && !this.hasProperties();
ValueNode.prototype.isStatement = function(o) {
return this.base.isStatement && this.base.isStatement(o) && !this.hasProperties();
};
ValueNode.prototype.isNumber = function() {
return this.base instanceof LiteralNode && this.base.value.match(NUMBER);
@ -481,7 +481,7 @@
arg = _c[_b];
if (arg instanceof SplatNode) {
compilation = this.compileSplat(o);
};
}
}
if (!(compilation)) {
args = (function() {
@ -704,7 +704,7 @@
prop = _d[_c];
if (!(prop instanceof CommentNode)) {
_b.push(prop);
};
}
}
return _b;
}).call(this);
@ -885,7 +885,7 @@
AssignNode.prototype.compileNode = function(o) {
var last, match, name, proto, stmt, top, val;
top = del(o, 'top');
if (this.isStatement()) {
if (this.isStatement(o)) {
return this.compilePatternMatch(o);
}
if (this.isValue() && this.variable.isSplice()) {
@ -920,7 +920,7 @@
AssignNode.prototype.compilePatternMatch = function(o) {
var _b, _c, _d, accessClass, assigns, code, i, idx, isString, obj, oindex, olength, splat, val, valVar, value;
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)) + ";")];
o.top = true;
o.asStatement = true;
@ -1213,7 +1213,7 @@
}));
} else {
post = '';
};
}
return "" + (pre) + " {\n" + (this.body.compile(o)) + "\n" + (this.tab) + "}" + (post);
};
return WhileNode;
@ -1227,7 +1227,7 @@
this.flip = !!flip;
if (this.first instanceof ValueNode && this.first.base instanceof ObjectNode) {
this.first = new ParentheticalNode(this.first);
};
}
return this;
};
__extends(OpNode, BaseNode);
@ -1448,8 +1448,8 @@
__extends(ParentheticalNode, BaseNode);
ParentheticalNode.prototype["class"] = 'ParentheticalNode';
ParentheticalNode.prototype.children = ['expression'];
ParentheticalNode.prototype.isStatement = function() {
return this.expression.isStatement();
ParentheticalNode.prototype.isStatement = function(o) {
return this.expression.isStatement(o);
};
ParentheticalNode.prototype.makeReturn = function() {
return this.expression.makeReturn();
@ -1461,7 +1461,7 @@
var code, l, top;
top = del(o, 'top');
code = this.expression.compile(o);
if (this.isStatement()) {
if (this.isStatement(o)) {
return (top ? this.tab + code + ';' : code);
}
l = code.length;
@ -1583,7 +1583,7 @@
}
if (this.guard) {
body = Expressions.wrap([new IfNode(this.guard, body)]);
};
}
if (codeInBody) {
if (range) {
body.unshift(literal(("var " + (name) + " = " + (ivar))));
@ -1682,8 +1682,8 @@
}
return this;
};
IfNode.prototype.isStatement = function() {
return this.statement = this.statement || (!!(this.tags.statement || this.bodyNode().isStatement() || (this.elseBody && this.elseBodyNode().isStatement())));
IfNode.prototype.isStatement = function(o) {
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) {
var _b, _c, _d, _e, cond;
@ -1697,7 +1697,7 @@
}).call(this).join(' || ');
};
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() {
if (this.isStatement()) {
@ -1721,7 +1721,7 @@
condO = merge(o);
o.indent = this.idt(1);
o.top = true;
ifDent = child || (top && !this.isStatement()) ? '' : this.idt();
ifDent = child || (top && !this.isStatement(o)) ? '' : this.idt();
comDent = child ? this.idt() : '';
body = this.body.compile(o);
ifPart = ("" + (ifDent) + "if (" + (this.compileCondition(condO)) + ") {\n" + (body) + "\n" + (this.tab) + "}");

View file

@ -77,13 +77,13 @@
this.tokens.splice(i - 2, 1);
} else {
this.tokens.splice(i, 0, after);
};
}
} else if (prev && !('TERMINATOR' === (_d = prev[0]) || 'INDENT' === _d || 'OUTDENT' === _d)) {
if (post && post[0] === 'TERMINATOR' && after && after[0] === 'OUTDENT') {
this.tokens.splice.apply(this.tokens, [i + 2, 0].concat(this.tokens.splice(i, 2)));
if (this.tokens[i + 2][0] !== 'TERMINATOR') {
this.tokens.splice(i + 2, 0, ['TERMINATOR', "\n", prev[2]]);
};
}
} else {
this.tokens.splice(i, 0, ['TERMINATOR', "\n", prev[2]]);
}
@ -148,10 +148,10 @@
var action, condition, idx, last;
if (include(EXPRESSION_START, token[0])) {
stack.push((token[0] === 'INDENT' && (this.tag(i - 1) === '{')) ? '{' : token[0]);
};
}
if (include(EXPRESSION_END, token[0])) {
stack.pop();
};
}
last = stack[stack.length - 1];
if (token[0] === ':' && (!last || last[0] !== '{')) {
stack.push('{');
@ -287,7 +287,7 @@
value = _d[key];
if (value > 0) {
_c.push(key);
};
}
}
return _c;
})();

View file

@ -83,7 +83,7 @@
val = _b[key];
if (val === 'var') {
_a.push(key);
};
}
}
return _a;
}).call(this).sort();
@ -96,7 +96,7 @@
val = _b[key];
if (val.assigned) {
_a.push(("" + (key) + " = " + (val.value)));
};
}
}
return _a;
};

View file

@ -46,7 +46,7 @@ exports.BaseNode = class BaseNode
del @options, 'operation'
del @options, 'chainRoot' unless this instanceof AccessorNode or this instanceof IndexNode
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 @containsPureStatement()
if closure then @compileClosure(@options) else @compileNode(@options)
@ -221,7 +221,7 @@ exports.Expressions = class Expressions extends BaseNode
compileExpression: (node, o) ->
@tab = o.indent
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
# to be one.
@ -250,8 +250,8 @@ exports.LiteralNode = class LiteralNode extends BaseNode
isPureStatement: LiteralNode::isStatement
compileNode: (o) ->
idt = if @isStatement() then @idt() else ''
end = if @isStatement() then ';' else ''
idt = if @isStatement(o) then @idt() else ''
end = if @isStatement(o) then ';' else ''
idt + @value + end
toString: (idt) ->
@ -279,7 +279,7 @@ exports.ReturnNode = class ReturnNode extends BaseNode
super o
compileNode: (o) ->
o.asStatement = true if @expression.isStatement()
o.asStatement = true if @expression.isStatement(o)
"#{@tab}return #{@expression.compile(o)};"
#### ValueNode
@ -323,8 +323,8 @@ exports.ValueNode = class ValueNode extends BaseNode
if @properties.length then this else @base
# Values are considered to be statements if their base is a statement.
isStatement: ->
@base.isStatement and @base.isStatement() and not @hasProperties()
isStatement: (o) ->
@base.isStatement and @base.isStatement(o) and not @hasProperties()
isNumber: ->
@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.
compileNode: (o) ->
top = del o, 'top'
return @compilePatternMatch(o) if @isStatement()
return @compilePatternMatch(o) if @isStatement(o)
return @compileSplice(o) if @isValue() and @variable.isSplice()
stmt = del o, 'asStatement'
name = @variable.compile(o)
@ -798,7 +798,7 @@ exports.AssignNode = class AssignNode extends BaseNode
# for details.
compilePatternMatch: (o) ->
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) };"]
o.top = true
o.asStatement = true
@ -1233,8 +1233,8 @@ exports.ParentheticalNode = class ParentheticalNode extends BaseNode
constructor: (@expression) ->
isStatement: ->
@expression.isStatement()
isStatement: (o) ->
@expression.isStatement(o)
makeReturn: ->
@expression.makeReturn()
@ -1245,7 +1245,7 @@ exports.ParentheticalNode = class ParentheticalNode extends BaseNode
compileNode: (o) ->
top = del o, 'top'
code = @expression.compile(o)
if @isStatement()
if @isStatement(o)
return (if top then @tab + code + ';' else code)
l = code.length
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
# to be a statement. Otherwise a ternary is safe.
isStatement: ->
@statement or= !!(@tags.statement or @bodyNode().isStatement() or (@elseBody and @elseBodyNode().isStatement()))
isStatement: (o) ->
@statement or= !!((o and o.top) or @tags.statement or @bodyNode().isStatement(o) or (@elseBody and @elseBodyNode().isStatement(o)))
compileCondition: (o) ->
(cond.compile(o) for cond in flatten([@condition])).join(' || ')
compileNode: (o) ->
if o.top or @isStatement() then @compileStatement(o) else @compileTernary(o)
if @isStatement(o) then @compileStatement(o) else @compileTernary(o)
makeReturn: ->
if @isStatement()
@ -1433,7 +1433,7 @@ exports.IfNode = class IfNode extends BaseNode
condO = merge o
o.indent = @idt 1
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 ''
body = @body.compile(o)
ifPart = "#{ifDent}if (#{ @compileCondition(condO) }) {\n#{body}\n#{@tab}}"