mirror of
https://github.com/jashkenas/coffeescript.git
synced 2026-02-18 11:31:20 -05:00
added last to helpers
This commit is contained in:
58
lib/nodes.js
58
lib/nodes.js
@@ -1,5 +1,5 @@
|
||||
(function() {
|
||||
var AccessorNode, ArrayNode, AssignNode, BaseNode, CallNode, ClassNode, ClosureNode, CodeNode, CommentNode, ExistenceNode, Expressions, ExtendsNode, ForNode, IDENTIFIER, IS_STRING, IfNode, InNode, IndexNode, LiteralNode, NO, NUMBER, ObjectNode, OpNode, ParamNode, ParentheticalNode, PushNode, RangeNode, ReturnNode, SIMPLENUM, Scope, SliceNode, SplatNode, SwitchNode, TAB, TRAILING_WHITESPACE, ThrowNode, TryNode, UTILITIES, ValueNode, WhileNode, YES, _ref, compact, del, ends, flatten, include, indexOf, literal, merge, starts, utility;
|
||||
var AccessorNode, ArrayNode, AssignNode, BaseNode, CallNode, ClassNode, ClosureNode, CodeNode, CommentNode, ExistenceNode, Expressions, ExtendsNode, ForNode, IDENTIFIER, IS_STRING, IfNode, InNode, IndexNode, LiteralNode, NO, NUMBER, ObjectNode, OpNode, ParamNode, ParentheticalNode, PushNode, RangeNode, ReturnNode, SIMPLENUM, Scope, SliceNode, SplatNode, SwitchNode, TAB, TRAILING_WHITESPACE, ThrowNode, TryNode, UTILITIES, ValueNode, WhileNode, YES, _ref, compact, del, ends, flatten, include, indexOf, last, literal, merge, starts, utility;
|
||||
var __extends = function(child, parent) {
|
||||
var ctor = function(){};
|
||||
ctor.prototype = parent.prototype;
|
||||
@@ -19,6 +19,7 @@
|
||||
indexOf = _ref.indexOf;
|
||||
starts = _ref.starts;
|
||||
ends = _ref.ends;
|
||||
last = _ref.last;
|
||||
YES = function() {
|
||||
return true;
|
||||
};
|
||||
@@ -191,16 +192,14 @@
|
||||
return this.expressions.length === 0;
|
||||
};
|
||||
Expressions.prototype.makeReturn = function() {
|
||||
var idx, last;
|
||||
idx = this.expressions.length - 1;
|
||||
last = this.expressions[idx];
|
||||
if (last instanceof CommentNode) {
|
||||
last = this.expressions[idx -= 1];
|
||||
var end, idx;
|
||||
end = this.expressions[(idx = this.expressions.length - 1)];
|
||||
if (end instanceof CommentNode) {
|
||||
end = this.expressions[idx -= 1];
|
||||
}
|
||||
if (!last || last instanceof ReturnNode) {
|
||||
return this;
|
||||
if (end && !(end instanceof ReturnNode)) {
|
||||
this.expressions[idx] = end.makeReturn();
|
||||
}
|
||||
this.expressions[idx] = last.makeReturn();
|
||||
return this;
|
||||
};
|
||||
Expressions.prototype.compile = function(o) {
|
||||
@@ -335,10 +334,10 @@
|
||||
return this.base instanceof ObjectNode && !this.hasProperties();
|
||||
};
|
||||
ValueNode.prototype.isSplice = function() {
|
||||
return this.hasProperties() && this.properties[this.properties.length - 1] instanceof SliceNode;
|
||||
return last(this.properties) instanceof SliceNode;
|
||||
};
|
||||
ValueNode.prototype.isComplex = function() {
|
||||
return this.base.isComplex() || this.properties.length;
|
||||
return this.base.isComplex() || this.hasProperties();
|
||||
};
|
||||
ValueNode.prototype.makeReturn = function() {
|
||||
return this.hasProperties() ? ValueNode.__super__.makeReturn.call(this) : this.base.makeReturn();
|
||||
@@ -380,7 +379,7 @@
|
||||
return !o.top || this.properties.length ? ValueNode.__super__.compile.call(this, o) : this.base.compile(o);
|
||||
};
|
||||
ValueNode.prototype.compileNode = function(o) {
|
||||
var _i, _len, _ref2, baseline, complete, copy, hasSoak, i, me, only, op, part, prevcomp, prop, props, temp;
|
||||
var _i, _len, _ref2, baseline, complete, copy, hasSoak, i, me, only, op, part, prop, props, temp;
|
||||
only = del(o, 'onlyFirst');
|
||||
op = this.tags.operation;
|
||||
props = only ? this.properties.slice(0, -1) : this.properties;
|
||||
@@ -413,7 +412,7 @@
|
||||
if (prop.soakNode) {
|
||||
if (i === 0 && this.base.isComplex()) {
|
||||
temp = o.scope.freeVariable('ref');
|
||||
complete = ("(" + (baseline = temp) + " = (" + (prevcomp = complete) + "))");
|
||||
complete = ("(" + (baseline = temp) + " = (" + (complete) + "))");
|
||||
}
|
||||
complete = i === 0 && !o.scope.check(complete) ? ("(typeof " + (complete) + " === \"undefined\" || " + (baseline) + " === null)") : ("" + (complete) + " == null");
|
||||
complete += ' ? undefined : ' + (baseline += prop.compile(o));
|
||||
@@ -493,7 +492,7 @@
|
||||
}
|
||||
op = this.tags.operation;
|
||||
if (this.exist) {
|
||||
if (this.variable instanceof ValueNode && this.variable.properties[this.variable.properties.length - 1] instanceof AccessorNode) {
|
||||
if (this.variable instanceof ValueNode && last(this.variable.properties) instanceof AccessorNode) {
|
||||
methodAccessor = this.variable.properties.pop();
|
||||
_ref2 = this.variable.compileReference(o);
|
||||
first = _ref2[0];
|
||||
@@ -771,7 +770,7 @@
|
||||
}
|
||||
return _result;
|
||||
}).call(this);
|
||||
lastNoncom = nonComments[nonComments.length - 1];
|
||||
lastNoncom = last(nonComments);
|
||||
props = (function() {
|
||||
_result = []; _ref2 = this.properties;
|
||||
for (i = 0, _len = _ref2.length; i < _len; i++) {
|
||||
@@ -949,7 +948,7 @@
|
||||
return this.isValue() && (this.variable.isArray() || this.variable.isObject());
|
||||
};
|
||||
AssignNode.prototype.compileNode = function(o) {
|
||||
var last, match, name, proto, stmt, top, val;
|
||||
var end, match, name, proto, stmt, top, val;
|
||||
top = del(o, 'top');
|
||||
if (this.isStatement(o)) {
|
||||
return this.compilePatternMatch(o);
|
||||
@@ -959,12 +958,12 @@
|
||||
}
|
||||
stmt = del(o, 'asStatement');
|
||||
name = this.variable.compile(o);
|
||||
last = this.isValue() ? this.variable.last.replace(this.LEADING_DOT, '') : name;
|
||||
end = this.isValue() ? this.variable.last.replace(this.LEADING_DOT, '') : name;
|
||||
match = name.match(this.PROTO_ASSIGN);
|
||||
proto = match && match[1];
|
||||
if (this.value instanceof CodeNode) {
|
||||
if (last.match(IDENTIFIER)) {
|
||||
this.value.name = last;
|
||||
if (IDENTIFIER.test(end)) {
|
||||
this.value.name = end;
|
||||
}
|
||||
if (proto) {
|
||||
this.value.proto = proto;
|
||||
@@ -1202,25 +1201,26 @@
|
||||
return "" + (utility('slice')) + ".call(" + (name) + ", " + (index) + (trail) + ")";
|
||||
};
|
||||
SplatNode.compileSplattedArray = function(list, o) {
|
||||
var _len, _ref2, arg, args, code, i, last, prev;
|
||||
var _len, _ref2, arg, args, code, end, i, prev;
|
||||
args = [];
|
||||
end = -1;
|
||||
_ref2 = list;
|
||||
for (i = 0, _len = _ref2.length; i < _len; i++) {
|
||||
arg = _ref2[i];
|
||||
code = arg.compile(o);
|
||||
prev = args[(last = args.length - 1)];
|
||||
prev = args[end];
|
||||
if (!(arg instanceof SplatNode)) {
|
||||
if (prev && starts(prev, '[') && ends(prev, ']')) {
|
||||
args[last] = ("" + (prev.slice(0, -1)) + ", " + (code) + "]");
|
||||
args[end] = ("" + (prev.slice(0, -1)) + ", " + (code) + "]");
|
||||
continue;
|
||||
} else if (prev && starts(prev, '.concat([') && ends(prev, '])')) {
|
||||
args[last] = ("" + (prev.slice(0, -2)) + ", " + (code) + "])");
|
||||
continue;
|
||||
} else {
|
||||
code = ("[" + (code) + "]");
|
||||
}
|
||||
if (prev && starts(prev, '.concat([') && ends(prev, '])')) {
|
||||
args[end] = ("" + (prev.slice(0, -2)) + ", " + (code) + "])");
|
||||
continue;
|
||||
}
|
||||
code = ("[" + (code) + "]");
|
||||
}
|
||||
args.push(i === 0 ? code : (".concat(" + (code) + ")"));
|
||||
args[++end] = i === 0 ? code : (".concat(" + (code) + ")");
|
||||
}
|
||||
return args.join('');
|
||||
};
|
||||
@@ -1756,7 +1756,7 @@
|
||||
code += ("\n" + (this.idt(1)) + "case " + (condition.compile(o)) + ":");
|
||||
}
|
||||
code += ("\n" + (block.compile(o)));
|
||||
if (!(exprs[exprs.length - 1] instanceof ReturnNode)) {
|
||||
if (!(last(exprs) instanceof ReturnNode)) {
|
||||
code += ("\n" + (idt) + "break;");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user