mirror of
https://github.com/jashkenas/coffeescript.git
synced 2026-02-18 19:34:27 -05:00
compound assignments are now represented as Assign nodes (rather than Op) and have the same precedence as =
This commit is contained in:
72
lib/nodes.js
72
lib/nodes.js
@@ -62,13 +62,7 @@
|
||||
return pair;
|
||||
};
|
||||
Base.prototype.idt = function(tabs) {
|
||||
var idt, num;
|
||||
idt = this.tab || '';
|
||||
num = (tabs || 0) + 1;
|
||||
while (num -= 1) {
|
||||
idt += TAB;
|
||||
}
|
||||
return idt;
|
||||
return (this.tab || '') + Array((tabs || 0) + 1).join(TAB);
|
||||
};
|
||||
Base.prototype.makeReturn = function() {
|
||||
return new Return(this);
|
||||
@@ -154,6 +148,7 @@
|
||||
Base.prototype.isStatement = NO;
|
||||
Base.prototype.isPureStatement = NO;
|
||||
Base.prototype.isComplex = YES;
|
||||
Base.prototype.isChainable = NO;
|
||||
Base.prototype.topSensitive = NO;
|
||||
Base.prototype.unfoldSoak = NO;
|
||||
Base.prototype.assigns = NO;
|
||||
@@ -189,7 +184,7 @@
|
||||
var end, idx;
|
||||
end = this.expressions[(idx = this.expressions.length - 1)];
|
||||
if (end instanceof Comment) {
|
||||
end = this.expressions[idx -= 1];
|
||||
end = this.expressions[(idx -= 1)];
|
||||
}
|
||||
if (end && !(end instanceof Return)) {
|
||||
this.expressions[idx] = end.makeReturn();
|
||||
@@ -718,7 +713,7 @@
|
||||
};
|
||||
Range.prototype.compileArray = function(o) {
|
||||
var _i, _ref2, _ref3, _result, body, clause, i, idt, post, pre, range, result, vars;
|
||||
if (this.fromNum && this.toNum && (Math.abs(this.fromNum - this.toNum) <= 20)) {
|
||||
if (this.fromNum && this.toNum && Math.abs(this.fromNum - this.toNum) <= 20) {
|
||||
range = (function() {
|
||||
_result = [];
|
||||
for (var _i = _ref2 = +this.fromNum, _ref3 = +this.toNum; _ref2 <= _ref3 ? _i <= _ref3 : _i >= _ref3; _ref2 <= _ref3 ? _i += 1 : _i -= 1){ _result.push(_i); }
|
||||
@@ -761,7 +756,7 @@
|
||||
var from, to;
|
||||
from = this.range.from ? this.range.from.compile(o) : '0';
|
||||
to = this.range.to ? this.range.to.compile(o) : '';
|
||||
to += (!to || this.range.exclusive ? '' : ' + 1');
|
||||
to += !to || this.range.exclusive ? '' : ' + 1';
|
||||
if (to) {
|
||||
to = ', ' + to;
|
||||
}
|
||||
@@ -894,7 +889,7 @@
|
||||
return this;
|
||||
};
|
||||
Class.prototype.compileNode = function(o) {
|
||||
var _i, _len, _ref2, _ref3, _ref4, access, applied, apply, className, constScope, construct, constructor, extension, func, me, pname, prop, props, pvar, ref, returns, val, variable;
|
||||
var _i, _len, _ref2, _ref3, access, applied, apply, className, constScope, construct, constructor, extension, func, me, pname, prop, props, pvar, ref, returns, val, variable;
|
||||
variable = this.variable;
|
||||
if (variable.value === '__temp__') {
|
||||
variable = new Literal(o.scope.freeVariable('ctor'));
|
||||
@@ -913,10 +908,10 @@
|
||||
}
|
||||
for (_i = 0, _len = (_ref2 = this.properties).length; _i < _len; _i++) {
|
||||
prop = _ref2[_i];
|
||||
_ref3 = [prop.variable, prop.value], pvar = _ref3[0], func = _ref3[1];
|
||||
pvar = prop.variable, func = prop.value;
|
||||
if (pvar && pvar.base.value === 'constructor') {
|
||||
if (!(func instanceof Code)) {
|
||||
_ref4 = func.compileReference(o), func = _ref4[0], ref = _ref4[1];
|
||||
_ref3 = func.compileReference(o), func = _ref3[0], ref = _ref3[1];
|
||||
if (func !== ref) {
|
||||
props.push(func);
|
||||
}
|
||||
@@ -931,7 +926,7 @@
|
||||
variable = new Value(variable);
|
||||
variable.namespaced = 0 < className.indexOf('.');
|
||||
constructor = func;
|
||||
if (props.expressions[props.expressions.length - 1] instanceof Comment) {
|
||||
if (last(props.expressions) instanceof Comment) {
|
||||
constructor.comment = props.expressions.pop();
|
||||
}
|
||||
continue;
|
||||
@@ -984,14 +979,12 @@
|
||||
})();
|
||||
__extends(Assign, Base);
|
||||
Assign.prototype.METHOD_DEF = /^(?:(\S+)\.prototype\.)?([$A-Za-z_][$\w]*)$/;
|
||||
Assign.prototype.CONDITIONAL = ['||=', '&&=', '?='];
|
||||
Assign.prototype.children = ['variable', 'value'];
|
||||
Assign.prototype.topSensitive = YES;
|
||||
Assign.prototype.isValue = function() {
|
||||
return this.variable instanceof Value;
|
||||
};
|
||||
Assign.prototype.compileNode = function(o) {
|
||||
var ifn, isValue, match, name, stmt, top, val;
|
||||
if (isValue = this.isValue()) {
|
||||
if (isValue = this.variable instanceof Value) {
|
||||
if (this.variable.isArray() || this.variable.isObject()) {
|
||||
return this.compilePatternMatch(o);
|
||||
}
|
||||
@@ -1002,6 +995,9 @@
|
||||
delete o.top;
|
||||
return ifn.compile(o);
|
||||
}
|
||||
if (include(this.CONDITIONAL, this.context)) {
|
||||
return this.compileConditional(o);
|
||||
}
|
||||
}
|
||||
top = del(o, 'top');
|
||||
stmt = del(o, 'asStatement');
|
||||
@@ -1017,7 +1013,7 @@
|
||||
if (!(isValue && (this.variable.hasProperties() || this.variable.namespaced))) {
|
||||
o.scope.find(name);
|
||||
}
|
||||
val = ("" + name + " = " + val);
|
||||
val = name + (" " + (this.context || '=') + " ") + val;
|
||||
if (stmt) {
|
||||
return ("" + (this.tab) + val + ";");
|
||||
}
|
||||
@@ -1099,6 +1095,11 @@
|
||||
val = this.value.compile(o);
|
||||
return "([].splice.apply(" + name + ", [" + from + ", " + to + "].concat(" + ref + " = " + val + ")), " + ref + ")";
|
||||
};
|
||||
Assign.prototype.compileConditional = function(o) {
|
||||
var _ref2, left, rite;
|
||||
_ref2 = this.variable.cacheReference(o), left = _ref2[0], rite = _ref2[1];
|
||||
return new Op(this.context.slice(0, -1), left, new Assign(rite, this.value)).compile(o);
|
||||
};
|
||||
Assign.prototype.assigns = function(name) {
|
||||
return this[this.context === 'object' ? 'value' : 'variable'].assigns(name);
|
||||
};
|
||||
@@ -1373,15 +1374,15 @@
|
||||
Op.prototype.CONVERSIONS = {
|
||||
'==': '===',
|
||||
'!=': '!==',
|
||||
of: 'in'
|
||||
'of': 'in'
|
||||
};
|
||||
Op.prototype.INVERSIONS = {
|
||||
'!==': '===',
|
||||
'===': '!=='
|
||||
};
|
||||
Op.prototype.CHAINABLE = ['<', '>', '>=', '<=', '===', '!=='];
|
||||
Op.prototype.ASSIGNMENT = ['||=', '&&=', '?='];
|
||||
Op.prototype.PREFIX_OPERATORS = ['new', 'typeof', 'delete'];
|
||||
Op.prototype.MUTATORS = ['++', '--', 'delete'];
|
||||
Op.prototype.children = ['first', 'second'];
|
||||
Op.prototype.isUnary = function() {
|
||||
return !this.second;
|
||||
@@ -1389,10 +1390,6 @@
|
||||
Op.prototype.isComplex = function() {
|
||||
return this.operator !== '!' || this.first.isComplex();
|
||||
};
|
||||
Op.prototype.isMutator = function() {
|
||||
var _ref2;
|
||||
return ends(this.operator, '=') && !((_ref2 = this.operator) === '===' || _ref2 === '!==');
|
||||
};
|
||||
Op.prototype.isChainable = function() {
|
||||
return include(this.CHAINABLE, this.operator);
|
||||
};
|
||||
@@ -1407,27 +1404,20 @@
|
||||
return Op.__super__.toString.call(this, idt, this.constructor.name + ' ' + this.operator);
|
||||
};
|
||||
Op.prototype.compileNode = function(o) {
|
||||
if (this.second) {
|
||||
this.first.tags.front = this.tags.front;
|
||||
}
|
||||
if (this.isChainable() && this.first.unwrap() instanceof Op && this.first.unwrap().isChainable()) {
|
||||
var ifn;
|
||||
if (this.isChainable() && this.first.unwrap().isChainable()) {
|
||||
return this.compileChain(o);
|
||||
}
|
||||
if (include(this.ASSIGNMENT, this.operator)) {
|
||||
return this.compileAssignment(o);
|
||||
}
|
||||
if (this.isUnary()) {
|
||||
if (include(this.MUTATORS, this.operator) && (ifn = If.unfoldSoak(o, this, 'first'))) {
|
||||
return ifn.compile(o);
|
||||
}
|
||||
return this.compileUnary(o);
|
||||
}
|
||||
if (this.operator === '?') {
|
||||
return this.compileExistence(o);
|
||||
}
|
||||
if (this.first instanceof Op && this.first.isMutator()) {
|
||||
this.first = new Parens(this.first);
|
||||
}
|
||||
if (this.second instanceof Op && this.second.isMutator()) {
|
||||
this.second = new Parens(this.second);
|
||||
}
|
||||
this.first.tags.front = this.tags.front;
|
||||
return [this.first.compile(o), this.operator, this.second.compile(o)].join(' ');
|
||||
};
|
||||
Op.prototype.compileChain = function(o) {
|
||||
@@ -1437,12 +1427,6 @@
|
||||
_ref3 = [this.first.compile(o), this.second.compile(o), shared.compile(o)], first = _ref3[0], second = _ref3[1], shared = _ref3[2];
|
||||
return "(" + first + ") && (" + shared + " " + (this.operator) + " " + second + ")";
|
||||
};
|
||||
Op.prototype.compileAssignment = function(o) {
|
||||
var _ref2, left, rite;
|
||||
_ref2 = this.first.cacheReference(o), left = _ref2[0], rite = _ref2[1];
|
||||
rite = new Assign(rite, this.second);
|
||||
return new Op(this.operator.slice(0, -1), left, rite).compile(o);
|
||||
};
|
||||
Op.prototype.compileExistence = function(o) {
|
||||
var fst, ref;
|
||||
if (this.first.isComplex()) {
|
||||
|
||||
Reference in New Issue
Block a user