mirror of
https://github.com/jashkenas/coffeescript.git
synced 2026-02-18 11:31:20 -05:00
removed extra parens from in/return compilations
This commit is contained in:
@@ -15,11 +15,11 @@
|
|||||||
if (!action) {
|
if (!action) {
|
||||||
_ref = [description, action], action = _ref[0], description = _ref[1];
|
_ref = [description, action], action = _ref[0], description = _ref[1];
|
||||||
}
|
}
|
||||||
return (tasks[name] = {
|
return tasks[name] = {
|
||||||
name: name,
|
name: name,
|
||||||
description: description,
|
description: description,
|
||||||
action: action
|
action: action
|
||||||
});
|
};
|
||||||
},
|
},
|
||||||
option: function(letter, flag, description) {
|
option: function(letter, flag, description) {
|
||||||
return switches.push([letter, flag, description]);
|
return switches.push([letter, flag, description]);
|
||||||
|
|||||||
@@ -64,7 +64,7 @@
|
|||||||
},
|
},
|
||||||
setInput: function(tokens) {
|
setInput: function(tokens) {
|
||||||
this.tokens = tokens;
|
this.tokens = tokens;
|
||||||
return (this.pos = 0);
|
return this.pos = 0;
|
||||||
},
|
},
|
||||||
upcomingInput: function() {
|
upcomingInput: function() {
|
||||||
return "";
|
return "";
|
||||||
|
|||||||
@@ -208,7 +208,7 @@
|
|||||||
o.compile || (o.compile = !!o.output);
|
o.compile || (o.compile = !!o.output);
|
||||||
o.run = !(o.compile || o.print || o.lint);
|
o.run = !(o.compile || o.print || o.lint);
|
||||||
o.print = !!(o.print || (o.eval || o.stdio && o.compile));
|
o.print = !!(o.print || (o.eval || o.stdio && o.compile));
|
||||||
return (sources = o.arguments);
|
return sources = o.arguments;
|
||||||
};
|
};
|
||||||
compileOptions = function(fileName) {
|
compileOptions = function(fileName) {
|
||||||
return {
|
return {
|
||||||
|
|||||||
@@ -342,7 +342,7 @@
|
|||||||
if (!prev[1].reserved && (_ref2 = prev[1], __indexOf.call(JS_FORBIDDEN, _ref2) >= 0)) {
|
if (!prev[1].reserved && (_ref2 = prev[1], __indexOf.call(JS_FORBIDDEN, _ref2) >= 0)) {
|
||||||
this.assignmentError();
|
this.assignmentError();
|
||||||
}
|
}
|
||||||
if (((_ref3 = prev[1]) === '||' || _ref3 === '&&')) {
|
if ((_ref3 = prev[1]) === '||' || _ref3 === '&&') {
|
||||||
prev[0] = 'COMPOUND_ASSIGN';
|
prev[0] = 'COMPOUND_ASSIGN';
|
||||||
prev[1] += '=';
|
prev[1] += '=';
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
42
lib/nodes.js
42
lib/nodes.js
@@ -263,7 +263,7 @@
|
|||||||
};
|
};
|
||||||
Literal.prototype.isStatement = function() {
|
Literal.prototype.isStatement = function() {
|
||||||
var _ref2;
|
var _ref2;
|
||||||
return ((_ref2 = this.value) === 'break' || _ref2 === 'continue' || _ref2 === 'debugger');
|
return (_ref2 = this.value) === 'break' || _ref2 === 'continue' || _ref2 === 'debugger';
|
||||||
};
|
};
|
||||||
Literal.prototype.isPureStatement = Literal.prototype.isStatement;
|
Literal.prototype.isPureStatement = Literal.prototype.isStatement;
|
||||||
Literal.prototype.isComplex = NO;
|
Literal.prototype.isComplex = NO;
|
||||||
@@ -314,7 +314,7 @@
|
|||||||
if (this.expression.isStatement(o)) {
|
if (this.expression.isStatement(o)) {
|
||||||
o.asStatement = true;
|
o.asStatement = true;
|
||||||
}
|
}
|
||||||
expr = ' ' + this.expression.compile(o);
|
expr = ' ' + this.expression.compileBare(o);
|
||||||
}
|
}
|
||||||
return "" + (this.tab) + "return" + expr + ";";
|
return "" + (this.tab) + "return" + expr + ";";
|
||||||
};
|
};
|
||||||
@@ -576,7 +576,7 @@
|
|||||||
var base, fun, idt, name, ref, splatargs;
|
var base, fun, idt, name, ref, splatargs;
|
||||||
splatargs = this.compileSplatArguments(o);
|
splatargs = this.compileSplatArguments(o);
|
||||||
if (this.isSuper) {
|
if (this.isSuper) {
|
||||||
return ("" + (this.superReference(o)) + ".apply(this, " + splatargs + ")");
|
return "" + (this.superReference(o)) + ".apply(this, " + splatargs + ")";
|
||||||
}
|
}
|
||||||
if (!this.isNew) {
|
if (!this.isNew) {
|
||||||
base = Value.wrap(this.variable);
|
base = Value.wrap(this.variable);
|
||||||
@@ -589,7 +589,7 @@
|
|||||||
fun += name.compile(o);
|
fun += name.compile(o);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return ("" + fun + ".apply(" + ref + ", " + splatargs + ")");
|
return "" + fun + ".apply(" + ref + ", " + splatargs + ")";
|
||||||
}
|
}
|
||||||
idt = this.idt(1);
|
idt = this.idt(1);
|
||||||
return "(function(func, args, ctor) {\n" + idt + "ctor.prototype = func.prototype;\n" + idt + "var child = new ctor, result = func.apply(child, args);\n" + idt + "return typeof result === \"object\" ? result : child;\n" + (this.tab) + "})(" + (this.variable.compile(o)) + ", " + splatargs + ", function() {})";
|
return "(function(func, args, ctor) {\n" + idt + "ctor.prototype = func.prototype;\n" + idt + "var child = new ctor, result = func.apply(child, args);\n" + idt + "return typeof result === \"object\" ? result : child;\n" + (this.tab) + "})(" + (this.variable.compile(o)) + ", " + splatargs + ", function() {})";
|
||||||
@@ -722,7 +722,7 @@
|
|||||||
if (this.exclusive) {
|
if (this.exclusive) {
|
||||||
range.pop();
|
range.pop();
|
||||||
}
|
}
|
||||||
return ("[" + (range.join(', ')) + "]");
|
return "[" + (range.join(', ')) + "]";
|
||||||
}
|
}
|
||||||
idt = this.idt(1);
|
idt = this.idt(1);
|
||||||
i = o.scope.freeVariable('i');
|
i = o.scope.freeVariable('i');
|
||||||
@@ -1006,14 +1006,14 @@
|
|||||||
}
|
}
|
||||||
val = this.value.compileBare(o);
|
val = this.value.compileBare(o);
|
||||||
if (this.context === 'object') {
|
if (this.context === 'object') {
|
||||||
return ("" + name + ": " + val);
|
return "" + name + ": " + val;
|
||||||
}
|
}
|
||||||
if (!(isValue && (this.variable.hasProperties() || this.variable.namespaced))) {
|
if (!(isValue && (this.variable.hasProperties() || this.variable.namespaced))) {
|
||||||
o.scope.find(name);
|
o.scope.find(name);
|
||||||
}
|
}
|
||||||
val = name + (" " + (this.context || '=') + " ") + val;
|
val = name + (" " + (this.context || '=') + " ") + val;
|
||||||
if (stmt) {
|
if (stmt) {
|
||||||
return ("" + (this.tab) + val + ";");
|
return "" + (this.tab) + val + ";";
|
||||||
}
|
}
|
||||||
return top || this.parenthetical ? val : "(" + val + ")";
|
return top || this.parenthetical ? val : "(" + val + ")";
|
||||||
};
|
};
|
||||||
@@ -1181,7 +1181,7 @@
|
|||||||
func = "" + open + (params.join(', ')) + ") {" + code + close;
|
func = "" + open + (params.join(', ')) + ") {" + code + close;
|
||||||
o.scope.endLevel();
|
o.scope.endLevel();
|
||||||
if (this.bound) {
|
if (this.bound) {
|
||||||
return ("" + (utility('bind')) + "(" + func + ", " + (this.context) + ")");
|
return "" + (utility('bind')) + "(" + func + ", " + (this.context) + ")";
|
||||||
}
|
}
|
||||||
return this.tags.front ? "(" + func + ")" : func;
|
return this.tags.front ? "(" + func + ")" : func;
|
||||||
};
|
};
|
||||||
@@ -1386,7 +1386,7 @@
|
|||||||
};
|
};
|
||||||
Op.prototype.isChainable = function() {
|
Op.prototype.isChainable = function() {
|
||||||
var _ref2;
|
var _ref2;
|
||||||
return (_ref2 = this.operator, __indexOf.call(this.CHAINABLE, _ref2) >= 0);
|
return _ref2 = this.operator, __indexOf.call(this.CHAINABLE, _ref2) >= 0;
|
||||||
};
|
};
|
||||||
Op.prototype.invert = function() {
|
Op.prototype.invert = function() {
|
||||||
var op;
|
var op;
|
||||||
@@ -1452,37 +1452,35 @@
|
|||||||
})();
|
})();
|
||||||
__extends(In, Base);
|
__extends(In, Base);
|
||||||
In.prototype.children = ['object', 'array'];
|
In.prototype.children = ['object', 'array'];
|
||||||
In.prototype.isArray = function() {
|
|
||||||
return this.array instanceof Value && this.array.isArray();
|
|
||||||
};
|
|
||||||
In.prototype.compileNode = function(o) {
|
In.prototype.compileNode = function(o) {
|
||||||
return this.isArray() ? this.compileOrTest(o) : this.compileLoopTest(o);
|
var code;
|
||||||
|
code = this.array instanceof Value && this.array.isArray() ? this.compileOrTest(o) : this.compileLoopTest(o);
|
||||||
|
return this.parenthetical ? code : "(" + code + ")";
|
||||||
};
|
};
|
||||||
In.prototype.compileOrTest = function(o) {
|
In.prototype.compileOrTest = function(o) {
|
||||||
var _len, _ref2, _ref3, _result, i, item, obj1, obj2, tests;
|
var _len, _ref2, _ref3, _result, i, item, ref, sub, tests;
|
||||||
_ref2 = this.object.compileReference(o, {
|
_ref2 = this.object.compileReference(o, {
|
||||||
precompile: true
|
precompile: true
|
||||||
}), obj1 = _ref2[0], obj2 = _ref2[1];
|
}), sub = _ref2[0], ref = _ref2[1];
|
||||||
tests = (function() {
|
tests = (function() {
|
||||||
_result = [];
|
_result = [];
|
||||||
for (i = 0, _len = (_ref3 = this.array.base.objects).length; i < _len; i++) {
|
for (i = 0, _len = (_ref3 = this.array.base.objects).length; i < _len; i++) {
|
||||||
item = _ref3[i];
|
item = _ref3[i];
|
||||||
_result.push("" + (i ? obj2 : obj1) + " === " + (item.compile(o)));
|
_result.push("" + (i ? ref : sub) + " === " + (item.compile(o)));
|
||||||
}
|
}
|
||||||
return _result;
|
return _result;
|
||||||
}).call(this);
|
}).call(this);
|
||||||
return "(" + (tests.join(' || ')) + ")";
|
return tests.join(' || ');
|
||||||
};
|
};
|
||||||
In.prototype.compileLoopTest = function(o) {
|
In.prototype.compileLoopTest = function(o) {
|
||||||
var _ref2, code, obj1, obj2, prefix;
|
var _ref2, code, ref, sub;
|
||||||
_ref2 = this.object.compileReference(merge(o, {
|
_ref2 = this.object.compileReference(merge(o, {
|
||||||
top: true
|
top: true
|
||||||
}), {
|
}), {
|
||||||
precompile: true
|
precompile: true
|
||||||
}), obj1 = _ref2[0], obj2 = _ref2[1];
|
}), sub = _ref2[0], ref = _ref2[1];
|
||||||
prefix = obj1 !== obj2 ? "" + obj1 + ", " : '';
|
code = utility('indexOf') + (".call(" + (this.array.compile(o)) + ", " + ref + ") >= 0");
|
||||||
code = "" + prefix + (utility('indexOf')) + ".call(" + (this.array.compile(o)) + ", " + obj2 + ") >= 0";
|
return sub === ref ? code : sub + ', ' + code;
|
||||||
return this.parenthetical ? code : "(" + code + ")";
|
|
||||||
};
|
};
|
||||||
return In;
|
return In;
|
||||||
})();
|
})();
|
||||||
|
|||||||
@@ -112,7 +112,7 @@
|
|||||||
return ((_ref = token[0]) === ')' || _ref === 'CALL_END') || token[0] === 'OUTDENT' && this.tag(i - 1) === ')';
|
return ((_ref = token[0]) === ')' || _ref === 'CALL_END') || token[0] === 'OUTDENT' && this.tag(i - 1) === ')';
|
||||||
};
|
};
|
||||||
action = function(token, i) {
|
action = function(token, i) {
|
||||||
return (this.tokens[token[0] === 'OUTDENT' ? i - 1 : i][0] = 'CALL_END');
|
return this.tokens[token[0] === 'OUTDENT' ? i - 1 : i][0] = 'CALL_END';
|
||||||
};
|
};
|
||||||
return this.scanTokens(function(token, i) {
|
return this.scanTokens(function(token, i) {
|
||||||
if (token[0] === 'CALL_START') {
|
if (token[0] === 'CALL_START') {
|
||||||
@@ -125,10 +125,10 @@
|
|||||||
var action, condition;
|
var action, condition;
|
||||||
condition = function(token, i) {
|
condition = function(token, i) {
|
||||||
var _ref;
|
var _ref;
|
||||||
return ((_ref = token[0]) === ']' || _ref === 'INDEX_END');
|
return (_ref = token[0]) === ']' || _ref === 'INDEX_END';
|
||||||
};
|
};
|
||||||
action = function(token, i) {
|
action = function(token, i) {
|
||||||
return (token[0] = 'INDEX_END');
|
return token[0] = 'INDEX_END';
|
||||||
};
|
};
|
||||||
return this.scanTokens(function(token, i) {
|
return this.scanTokens(function(token, i) {
|
||||||
if (token[0] === 'INDEX_START') {
|
if (token[0] === 'INDEX_START') {
|
||||||
@@ -142,7 +142,7 @@
|
|||||||
stack = [];
|
stack = [];
|
||||||
condition = function(token, i) {
|
condition = function(token, i) {
|
||||||
var _ref, _ref2, one, tag, three, two;
|
var _ref, _ref2, one, tag, three, two;
|
||||||
if (('HERECOMMENT' === this.tag(i + 1) || 'HERECOMMENT' === this.tag(i - 1))) {
|
if ('HERECOMMENT' === this.tag(i + 1) || 'HERECOMMENT' === this.tag(i - 1)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
_ref = this.tokens.slice(i + 1, i + 4), one = _ref[0], two = _ref[1], three = _ref[2];
|
_ref = this.tokens.slice(i + 1, i + 4), one = _ref[0], two = _ref[1], three = _ref[2];
|
||||||
@@ -211,7 +211,7 @@
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
tag = token[0];
|
tag = token[0];
|
||||||
if ((tag === 'IF' || tag === 'ELSE' || tag === 'UNLESS' || tag === '->' || tag === '=>')) {
|
if (tag === 'IF' || tag === 'ELSE' || tag === 'UNLESS' || tag === '->' || tag === '=>') {
|
||||||
seenSingle = true;
|
seenSingle = true;
|
||||||
}
|
}
|
||||||
if (tag === 'PROPERTY_ACCESS' && this.tag(i - 1) === 'OUTDENT') {
|
if (tag === 'PROPERTY_ACCESS' && this.tag(i - 1) === 'OUTDENT') {
|
||||||
@@ -265,7 +265,7 @@
|
|||||||
var condition;
|
var condition;
|
||||||
condition = function(token, i) {
|
condition = function(token, i) {
|
||||||
var _ref;
|
var _ref;
|
||||||
return ((_ref = token[0]) === 'TERMINATOR' || _ref === 'INDENT');
|
return (_ref = token[0]) === 'TERMINATOR' || _ref === 'INDENT';
|
||||||
};
|
};
|
||||||
return this.scanTokens(function(token, i) {
|
return this.scanTokens(function(token, i) {
|
||||||
var _ref, original;
|
var _ref, original;
|
||||||
|
|||||||
@@ -110,7 +110,7 @@
|
|||||||
Scope.prototype.hasDeclarations = function(body) {
|
Scope.prototype.hasDeclarations = function(body) {
|
||||||
return body === this.expressions && this.any(function(v) {
|
return body === this.expressions && this.any(function(v) {
|
||||||
var _ref2;
|
var _ref2;
|
||||||
return ((_ref2 = v.type) === 'var' || _ref2 === 'reuse');
|
return (_ref2 = v.type) === 'var' || _ref2 === 'reuse';
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
Scope.prototype.hasAssignments = function(body) {
|
Scope.prototype.hasAssignments = function(body) {
|
||||||
@@ -124,7 +124,7 @@
|
|||||||
_result = [];
|
_result = [];
|
||||||
for (_i = 0, _len = (_ref2 = this.variables).length; _i < _len; _i++) {
|
for (_i = 0, _len = (_ref2 = this.variables).length; _i < _len; _i++) {
|
||||||
v = _ref2[_i];
|
v = _ref2[_i];
|
||||||
if (((_ref3 = v.type) === 'var' || _ref3 === 'reuse')) {
|
if ((_ref3 = v.type) === 'var' || _ref3 === 'reuse') {
|
||||||
_result.push(v.name);
|
_result.push(v.name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -296,7 +296,7 @@ exports.Return = class Return extends Base
|
|||||||
expr = ''
|
expr = ''
|
||||||
if @expression
|
if @expression
|
||||||
o.asStatement = true if @expression.isStatement(o)
|
o.asStatement = true if @expression.isStatement(o)
|
||||||
expr = ' ' + @expression.compile(o)
|
expr = ' ' + @expression.compileBare o
|
||||||
"#{@tab}return#{expr};"
|
"#{@tab}return#{expr};"
|
||||||
|
|
||||||
#### Value
|
#### Value
|
||||||
@@ -1252,23 +1252,23 @@ exports.In = class In extends Base
|
|||||||
constructor: (@object, @array) ->
|
constructor: (@object, @array) ->
|
||||||
super()
|
super()
|
||||||
|
|
||||||
isArray: ->
|
|
||||||
@array instanceof Value and @array.isArray()
|
|
||||||
|
|
||||||
compileNode: (o) ->
|
compileNode: (o) ->
|
||||||
if @isArray() then @compileOrTest o else @compileLoopTest o
|
code = if @array instanceof Value and @array.isArray()
|
||||||
|
@compileOrTest o
|
||||||
|
else
|
||||||
|
@compileLoopTest o
|
||||||
|
if @parenthetical then code else "(#{code})"
|
||||||
|
|
||||||
compileOrTest: (o) ->
|
compileOrTest: (o) ->
|
||||||
[obj1, obj2] = @object.compileReference o, precompile: yes
|
[sub, ref] = @object.compileReference o, precompile: yes
|
||||||
tests = for item, i in @array.base.objects
|
tests = for item, i in @array.base.objects
|
||||||
"#{ if i then obj2 else obj1 } === #{ item.compile o }"
|
"#{ if i then ref else sub } === #{ item.compile o }"
|
||||||
"(#{ tests.join ' || ' })"
|
tests.join ' || '
|
||||||
|
|
||||||
compileLoopTest: (o) ->
|
compileLoopTest: (o) ->
|
||||||
[obj1, obj2] = @object.compileReference merge(o, top: yes), precompile: yes
|
[sub, ref] = @object.compileReference merge(o, top: yes), precompile: yes
|
||||||
prefix = if obj1 isnt obj2 then "#{obj1}, " else ''
|
code = utility('indexOf') + ".call(#{ @array.compile o }, #{ref}) >= 0"
|
||||||
code = "#{prefix}#{utility 'indexOf'}.call(#{@array.compile o}, #{obj2}) >= 0"
|
if sub is ref then code else sub + ', ' + code
|
||||||
if @parenthetical then code else "(#{code})"
|
|
||||||
|
|
||||||
#### Try
|
#### Try
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user