Removing extraneous semicolon, adding back in final break -- src now lints cleanly.

This commit is contained in:
Jeremy Ashkenas 2010-10-24 20:51:55 -04:00
parent 5b16d4790c
commit c2da8c2d54
8 changed files with 50 additions and 47 deletions

View File

@ -110,7 +110,7 @@
} else { } else {
t.output = CoffeeScript.compile(t.input, t.options); t.output = CoffeeScript.compile(t.input, t.options);
CoffeeScript.emit('success', task); CoffeeScript.emit('success', task);
return o.print ? console.log(t.output.trim()) : o.compile ? writeJs(t.file, t.output, base) : o.lint ? lint(t.output) : undefined; return o.print ? console.log(t.output.trim()) : o.compile ? writeJs(t.file, t.output, base) : o.lint ? lint(t.file, t.output) : undefined;
} }
} catch (err) { } catch (err) {
CoffeeScript.emit('failure', err, task); CoffeeScript.emit('failure', err, task);
@ -170,10 +170,10 @@
return exists ? compile() : exec("mkdir -p " + dir, compile); return exists ? compile() : exec("mkdir -p " + dir, compile);
}); });
}; };
lint = function(js) { lint = function(file, js) {
var conf, jsl, printIt; var conf, jsl, printIt;
printIt = function(buffer) { printIt = function(buffer) {
return console.log(buffer.toString().trim()); return console.log(file + ':\t' + buffer.toString().trim());
}; };
conf = __dirname + '/../extras/jsl.conf'; conf = __dirname + '/../extras/jsl.conf';
jsl = spawn('jsl', ['-nologo', '-stdin', '-conf', conf]); jsl = spawn('jsl', ['-nologo', '-stdin', '-conf', conf]);

View File

@ -1,7 +1,9 @@
(function() { (function() {
var ASSIGNED, BOOL, CALLABLE, CODE, COFFEE_ALIASES, COFFEE_KEYWORDS, COMMENT, COMPARE, COMPOUND_ASSIGN, HEREDOC, HEREDOC_INDENT, HEREGEX, HEREGEX_OMIT, IDENTIFIER, INDEXABLE, JSTOKEN, JS_FORBIDDEN, JS_KEYWORDS, LEADING_SPACES, LINE_BREAK, LOGIC, Lexer, MATH, MULTILINER, MULTI_DENT, NEXT_CHARACTER, NEXT_ELLIPSIS, NOT_REGEX, NO_NEWLINE, NUMBER, OPERATOR, REGEX, RELATION, RESERVED, Rewriter, SHIFT, SIMPLESTR, TRAILING_SPACES, UNARY, WHITESPACE, _ref, compact, count, last, op, starts; var ASSIGNED, BOOL, CALLABLE, CODE, COFFEE_ALIASES, COFFEE_KEYWORDS, COMMENT, COMPARE, COMPOUND_ASSIGN, HEREDOC, HEREDOC_INDENT, HEREGEX, HEREGEX_OMIT, IDENTIFIER, INDEXABLE, JSTOKEN, JS_FORBIDDEN, JS_KEYWORDS, LEADING_SPACES, LINE_BREAK, LOGIC, Lexer, MATH, MULTILINER, MULTI_DENT, NEXT_CHARACTER, NEXT_ELLIPSIS, NOT_REGEX, NO_NEWLINE, NUMBER, OPERATOR, REGEX, RELATION, RESERVED, Rewriter, SHIFT, SIMPLESTR, TRAILING_SPACES, UNARY, WHITESPACE, _ref, compact, count, last, op, starts;
var __indexOf = Array.prototype.indexOf || function(item) { var __indexOf = Array.prototype.indexOf || function(item) {
for (var i = 0, l = this.length; i < l; i++) if (this[i] === item) return i; for (var i = 0, l = this.length; i < l; i++) {
if (this[i] === item) return i;
}
return -1; return -1;
}; };
Rewriter = require('./rewriter').Rewriter; Rewriter = require('./rewriter').Rewriter;
@ -10,7 +12,7 @@
Lexer = (function() { Lexer = (function() {
function Lexer() { function Lexer() {
return this; return this;
}; }
return Lexer; return Lexer;
})(); })();
Lexer.prototype.tokenize = function(code, options) { Lexer.prototype.tokenize = function(code, options) {
@ -375,6 +377,7 @@
break; break;
case '::': case '::':
prev[0] = 'INDEX_PROTO'; prev[0] = 'INDEX_PROTO';
break;
} }
} }
} }

View File

@ -24,7 +24,7 @@
function Base() { function Base() {
this.tags = {}; this.tags = {};
return this; return this;
}; }
return Base; return Base;
})(); })();
Base.prototype.compile = function(o, lvl) { Base.prototype.compile = function(o, lvl) {
@ -173,7 +173,7 @@
Expressions.__super__.constructor.call(this); Expressions.__super__.constructor.call(this);
this.expressions = compact(flatten(nodes || [])); this.expressions = compact(flatten(nodes || []));
return this; return this;
}; }
return Expressions; return Expressions;
})(); })();
__extends(Expressions, Base); __extends(Expressions, Base);
@ -269,7 +269,7 @@
this.value = _arg; this.value = _arg;
Literal.__super__.constructor.call(this); Literal.__super__.constructor.call(this);
return this; return this;
}; }
return Literal; return Literal;
})(); })();
__extends(Literal, Base); __extends(Literal, Base);
@ -301,7 +301,7 @@
this.expression = _arg; this.expression = _arg;
Return.__super__.constructor.call(this); Return.__super__.constructor.call(this);
return this; return this;
}; }
return Return; return Return;
})(); })();
__extends(Return, Base); __extends(Return, Base);
@ -331,7 +331,7 @@
this.properties = props || []; this.properties = props || [];
this.tags = tag ? (_obj = {}, _obj[tag] = true, _obj) : {}; this.tags = tag ? (_obj = {}, _obj[tag] = true, _obj) : {};
return this; return this;
}; }
return Value; return Value;
})(); })();
__extends(Value, Base); __extends(Value, Base);
@ -449,7 +449,7 @@
this.comment = _arg; this.comment = _arg;
Comment.__super__.constructor.call(this); Comment.__super__.constructor.call(this);
return this; return this;
}; }
return Comment; return Comment;
})(); })();
__extends(Comment, Base); __extends(Comment, Base);
@ -471,7 +471,7 @@
this.variable = this.isSuper ? null : variable; this.variable = this.isSuper ? null : variable;
this.args || (this.args = []); this.args || (this.args = []);
return this; return this;
}; }
return Call; return Call;
})(); })();
__extends(Call, Base); __extends(Call, Base);
@ -598,7 +598,7 @@
this.child = _arg; this.child = _arg;
Extends.__super__.constructor.call(this); Extends.__super__.constructor.call(this);
return this; return this;
}; }
return Extends; return Extends;
})(); })();
__extends(Extends, Base); __extends(Extends, Base);
@ -616,7 +616,7 @@
this.proto = tag === 'prototype' ? '.prototype' : ''; this.proto = tag === 'prototype' ? '.prototype' : '';
this.soakNode = tag === 'soak'; this.soakNode = tag === 'soak';
return this; return this;
}; }
return Accessor; return Accessor;
})(); })();
__extends(Accessor, Base); __extends(Accessor, Base);
@ -635,7 +635,7 @@
this.index = _arg; this.index = _arg;
Index.__super__.constructor.call(this); Index.__super__.constructor.call(this);
return this; return this;
}; }
return Index; return Index;
})(); })();
__extends(Index, Base); __extends(Index, Base);
@ -654,7 +654,7 @@
Obj.__super__.constructor.call(this); Obj.__super__.constructor.call(this);
this.objects = this.properties = props || []; this.objects = this.properties = props || [];
return this; return this;
}; }
return Obj; return Obj;
})(); })();
__extends(Obj, Base); __extends(Obj, Base);
@ -742,7 +742,7 @@
Arr.__super__.constructor.call(this); Arr.__super__.constructor.call(this);
this.objects = objs || []; this.objects = objs || [];
return this; return this;
}; }
return Arr; return Arr;
})(); })();
__extends(Arr, Base); __extends(Arr, Base);
@ -789,7 +789,7 @@
this.properties = props || []; this.properties = props || [];
this.returns = false; this.returns = false;
return this; return this;
}; }
return Class; return Class;
})(); })();
__extends(Class, Base); __extends(Class, Base);
@ -887,7 +887,7 @@
this.variable = _arg; this.variable = _arg;
Assign.__super__.constructor.call(this); Assign.__super__.constructor.call(this);
return this; return this;
}; }
return Assign; return Assign;
})(); })();
__extends(Assign, Base); __extends(Assign, Base);
@ -1010,7 +1010,7 @@
this.context = 'this'; this.context = 'this';
} }
return this; return this;
}; }
return Code; return Code;
})(); })();
__extends(Code, Base); __extends(Code, Base);
@ -1072,7 +1072,7 @@
code = this.body.expressions.length ? "\n" + (this.body.compileWithDeclarations(o)) + "\n" : ''; code = this.body.expressions.length ? "\n" + (this.body.compileWithDeclarations(o)) + "\n" : '';
if (this.className) { if (this.className) {
open = "(function() {\n" + comm + idt + "function " + this.className + "("; open = "(function() {\n" + comm + idt + "function " + this.className + "(";
close = "" + (code && idt) + "};\n" + idt + "return " + this.className + ";\n" + this.tab + "})()"; close = "" + (code && idt) + "}\n" + idt + "return " + this.className + ";\n" + this.tab + "})()";
} else { } else {
open = "function("; open = "function(";
close = "" + (code && this.tab) + "}"; close = "" + (code && this.tab) + "}";
@ -1097,7 +1097,7 @@
Param.__super__.constructor.call(this); Param.__super__.constructor.call(this);
this.value = new Literal(this.name = name); this.value = new Literal(this.name = name);
return this; return this;
}; }
return Param; return Param;
})(); })();
__extends(Param, Base); __extends(Param, Base);
@ -1124,7 +1124,7 @@
Splat.__super__.constructor.call(this); Splat.__super__.constructor.call(this);
this.name = name.compile ? name : new Literal(name); this.name = name.compile ? name : new Literal(name);
return this; return this;
}; }
return Splat; return Splat;
})(); })();
__extends(Splat, Base); __extends(Splat, Base);
@ -1198,7 +1198,7 @@
this.condition = (opts != null ? opts.invert : undefined) ? condition.invert() : condition; this.condition = (opts != null ? opts.invert : undefined) ? condition.invert() : condition;
this.guard = opts != null ? opts.guard : undefined; this.guard = opts != null ? opts.guard : undefined;
return this; return this;
}; }
return While; return While;
})(); })();
__extends(While, Base); __extends(While, Base);
@ -1261,7 +1261,7 @@
this.second = second; this.second = second;
this.flip = !!flip; this.flip = !!flip;
return this; return this;
}; }
return Op; return Op;
})(); })();
__extends(Op, Base); __extends(Op, Base);
@ -1351,7 +1351,7 @@
this.object = _arg; this.object = _arg;
In.__super__.constructor.call(this); In.__super__.constructor.call(this);
return this; return this;
}; }
return In; return In;
})(); })();
__extends(In, Base); __extends(In, Base);
@ -1403,7 +1403,7 @@
this.attempt = _arg; this.attempt = _arg;
Try.__super__.constructor.call(this); Try.__super__.constructor.call(this);
return this; return this;
}; }
return Try; return Try;
})(); })();
__extends(Try, Base); __extends(Try, Base);
@ -1433,7 +1433,7 @@
this.expression = _arg; this.expression = _arg;
Throw.__super__.constructor.call(this); Throw.__super__.constructor.call(this);
return this; return this;
}; }
return Throw; return Throw;
})(); })();
__extends(Throw, Base); __extends(Throw, Base);
@ -1451,7 +1451,7 @@
this.expression = _arg; this.expression = _arg;
Existence.__super__.constructor.call(this); Existence.__super__.constructor.call(this);
return this; return this;
}; }
return Existence; return Existence;
})(); })();
__extends(Existence, Base); __extends(Existence, Base);
@ -1470,7 +1470,7 @@
this.expression = _arg; this.expression = _arg;
Parens.__super__.constructor.call(this); Parens.__super__.constructor.call(this);
return this; return this;
}; }
return Parens; return Parens;
})(); })();
__extends(Parens, Base); __extends(Parens, Base);
@ -1512,7 +1512,7 @@
this.pattern = this.name instanceof Value; this.pattern = this.name instanceof Value;
this.returns = false; this.returns = false;
return this; return this;
}; }
return For; return For;
})(); })();
__extends(For, Base); __extends(For, Base);
@ -1631,7 +1631,7 @@
this.subject = _arg; this.subject = _arg;
Switch.__super__.constructor.call(this); Switch.__super__.constructor.call(this);
return this; return this;
}; }
return Switch; return Switch;
})(); })();
__extends(Switch, Base); __extends(Switch, Base);
@ -1665,9 +1665,6 @@
code += idt1 + ("case " + (cond.compile(o, LEVEL_PAREN)) + ":\n"); code += idt1 + ("case " + (cond.compile(o, LEVEL_PAREN)) + ":\n");
} }
code += block.compile(o, LEVEL_TOP) + '\n'; code += block.compile(o, LEVEL_TOP) + '\n';
if (i === this.cases.length - 1 && !this.otherwise) {
break;
}
_ref5 = block.expressions; _ref5 = block.expressions;
for (_j = _ref5.length - 1; _j >= 0; _j--) { for (_j = _ref5.length - 1; _j >= 0; _j--) {
expr = _ref5[_j]; expr = _ref5[_j];
@ -1696,7 +1693,7 @@
this.elseBody = null; this.elseBody = null;
this.isChain = false; this.isChain = false;
return this; return this;
}; }
return If; return If;
})(); })();
__extends(If, Base); __extends(If, Base);
@ -1812,7 +1809,7 @@
UTILITIES = { UTILITIES = {
"extends": 'function(child, parent) {\n function ctor() { this.constructor = child; }\n ctor.prototype = parent.prototype;\n child.prototype = new ctor;\n if (typeof parent.extended === "function") parent.extended(child);\n child.__super__ = parent.prototype;\n}', "extends": 'function(child, parent) {\n function ctor() { this.constructor = child; }\n ctor.prototype = parent.prototype;\n child.prototype = new ctor;\n if (typeof parent.extended === "function") parent.extended(child);\n child.__super__ = parent.prototype;\n}',
bind: 'function(func, context) {\n return function() { return func.apply(context, arguments); };\n}', bind: 'function(func, context) {\n return function() { return func.apply(context, arguments); };\n}',
indexOf: 'Array.prototype.indexOf || function(item) {\n for (var i = 0, l = this.length; i < l; i++) if (this[i] === item) return i;\n return -1;\n}', indexOf: 'Array.prototype.indexOf || function(item) {\n for (var i = 0, l = this.length; i < l; i++) {\n if (this[i] === item) return i;\n }\n return -1;\n}',
hasProp: 'Object.prototype.hasOwnProperty', hasProp: 'Object.prototype.hasOwnProperty',
slice: 'Array.prototype.slice' slice: 'Array.prototype.slice'
}; };

View File

@ -6,7 +6,7 @@
this.banner = banner; this.banner = banner;
this.rules = buildRules(rules); this.rules = buildRules(rules);
return this; return this;
}; }
return OptionParser; return OptionParser;
})(); })();
OptionParser.prototype.parse = function(args) { OptionParser.prototype.parse = function(args) {

View File

@ -1,13 +1,15 @@
(function() { (function() {
var BALANCED_PAIRS, EXPRESSION_CLOSE, EXPRESSION_END, EXPRESSION_START, IMPLICIT_BLOCK, IMPLICIT_CALL, IMPLICIT_END, IMPLICIT_FUNC, IMPLICIT_UNSPACED_CALL, INVERSES, LINEBREAKS, SINGLE_CLOSERS, SINGLE_LINERS, _i, _len, _ref, left, rite; var BALANCED_PAIRS, EXPRESSION_CLOSE, EXPRESSION_END, EXPRESSION_START, IMPLICIT_BLOCK, IMPLICIT_CALL, IMPLICIT_END, IMPLICIT_FUNC, IMPLICIT_UNSPACED_CALL, INVERSES, LINEBREAKS, SINGLE_CLOSERS, SINGLE_LINERS, _i, _len, _ref, left, rite;
var __indexOf = Array.prototype.indexOf || function(item) { var __indexOf = Array.prototype.indexOf || function(item) {
for (var i = 0, l = this.length; i < l; i++) if (this[i] === item) return i; for (var i = 0, l = this.length; i < l; i++) {
if (this[i] === item) return i;
}
return -1; return -1;
}; };
exports.Rewriter = (function() { exports.Rewriter = (function() {
function Rewriter() { function Rewriter() {
return this; return this;
}; }
return Rewriter; return Rewriter;
})(); })();
exports.Rewriter.prototype.rewrite = function(_arg) { exports.Rewriter.prototype.rewrite = function(_arg) {

View File

@ -21,7 +21,7 @@
Scope.root = this; Scope.root = this;
} }
return this; return this;
}; }
return Scope; return Scope;
})(); })();
Scope.root = null; Scope.root = null;

View File

@ -107,7 +107,7 @@ compileScript = (file, input, base) ->
CoffeeScript.emit 'success', task CoffeeScript.emit 'success', task
if o.print then console.log t.output.trim() if o.print then console.log t.output.trim()
else if o.compile then writeJs t.file, t.output, base else if o.compile then writeJs t.file, t.output, base
else if o.lint then lint t.output else if o.lint then lint t.file, t.output
catch err catch err
CoffeeScript.emit 'failure', err, task CoffeeScript.emit 'failure', err, task
return if CoffeeScript.listeners('failure').length return if CoffeeScript.listeners('failure').length
@ -154,8 +154,8 @@ writeJs = (source, js, base) ->
# Pipe compiled JS through JSLint (requires a working `jsl` command), printing # Pipe compiled JS through JSLint (requires a working `jsl` command), printing
# any errors or warnings that arise. # any errors or warnings that arise.
lint = (js) -> lint = (file, js) ->
printIt = (buffer) -> console.log buffer.toString().trim() printIt = (buffer) -> console.log file + ':\t' + buffer.toString().trim()
conf = __dirname + '/../extras/jsl.conf' conf = __dirname + '/../extras/jsl.conf'
jsl = spawn 'jsl', ['-nologo', '-stdin', '-conf', conf] jsl = spawn 'jsl', ['-nologo', '-stdin', '-conf', conf]
jsl.stdout.on 'data', printIt jsl.stdout.on 'data', printIt

View File

@ -884,7 +884,7 @@ exports.Code = class Code extends Base
code = if @body.expressions.length then "\n#{ @body.compileWithDeclarations o }\n" else '' code = if @body.expressions.length then "\n#{ @body.compileWithDeclarations o }\n" else ''
if @className if @className
open = "(function() {\n#{comm}#{idt}function #{@className}(" open = "(function() {\n#{comm}#{idt}function #{@className}("
close = "#{ code and idt }};\n#{idt}return #{@className};\n#{@tab}})()" close = "#{ code and idt }}\n#{idt}return #{@className};\n#{@tab}})()"
else else
open = "function(" open = "function("
close = "#{ code and @tab }}" close = "#{ code and @tab }}"
@ -1367,7 +1367,6 @@ exports.Switch = class Switch extends Base
cond = cond.invert() unless @subject cond = cond.invert() unless @subject
code += idt1 + "case #{ cond.compile o, LEVEL_PAREN }:\n" code += idt1 + "case #{ cond.compile o, LEVEL_PAREN }:\n"
code += block.compile(o, LEVEL_TOP) + '\n' code += block.compile(o, LEVEL_TOP) + '\n'
break if i is @cases.length - 1 and not @otherwise
for expr in block.expressions by -1 when expr not instanceof Comment for expr in block.expressions by -1 when expr not instanceof Comment
code += idt2 + 'break;\n' unless expr instanceof Return code += idt2 + 'break;\n' unless expr instanceof Return
break break
@ -1524,7 +1523,9 @@ UTILITIES =
# Discover if an item is in an array. # Discover if an item is in an array.
indexOf: ''' indexOf: '''
Array.prototype.indexOf || function(item) { Array.prototype.indexOf || function(item) {
for (var i = 0, l = this.length; i < l; i++) if (this[i] === item) return i; for (var i = 0, l = this.length; i < l; i++) {
if (this[i] === item) return i;
}
return -1; return -1;
} }
''' '''