mirror of
https://github.com/jashkenas/coffeescript.git
synced 2026-02-18 11:31:20 -05:00
disabled interpolations in normal regexes
This commit is contained in:
186
lib/nodes.js
186
lib/nodes.js
@@ -214,16 +214,16 @@
|
||||
o.scope = new Scope(null, this, null);
|
||||
code = this.compileWithDeclarations(o);
|
||||
code = code.replace(TRAILING_WHITESPACE, '');
|
||||
return o.noWrap ? code : ("(function() {\n" + (code) + "\n}).call(this);\n");
|
||||
return o.noWrap ? code : ("(function() {\n" + code + "\n}).call(this);\n");
|
||||
};
|
||||
Expressions.prototype.compileWithDeclarations = function(o) {
|
||||
var code;
|
||||
code = this.compileNode(o);
|
||||
if (o.scope.hasAssignments(this)) {
|
||||
code = ("" + (this.tab) + "var " + (o.scope.compiledAssignments()) + ";\n" + (code));
|
||||
code = ("" + this.tab + "var " + (o.scope.compiledAssignments()) + ";\n" + code);
|
||||
}
|
||||
if (!o.globals && o.scope.hasDeclarations(this)) {
|
||||
code = ("" + (this.tab) + "var " + (o.scope.compiledDeclarations()) + ";\n" + (code));
|
||||
code = ("" + this.tab + "var " + (o.scope.compiledDeclarations()) + ";\n" + code);
|
||||
}
|
||||
return code;
|
||||
};
|
||||
@@ -233,7 +233,7 @@
|
||||
compiledNode = node.compile(merge(o, {
|
||||
top: true
|
||||
}));
|
||||
return node.isStatement(o) ? compiledNode : ("" + (this.idt()) + (compiledNode) + ";");
|
||||
return node.isStatement(o) ? compiledNode : ("" + (this.idt()) + compiledNode + ";");
|
||||
};
|
||||
return Expressions;
|
||||
})();
|
||||
@@ -295,7 +295,7 @@
|
||||
if (this.expression.isStatement(o)) {
|
||||
o.asStatement = true;
|
||||
}
|
||||
return "" + (this.tab) + "return " + (this.expression.compile(o)) + ";";
|
||||
return "" + this.tab + "return " + (this.expression.compile(o)) + ";";
|
||||
};
|
||||
return ReturnNode;
|
||||
})();
|
||||
@@ -376,7 +376,7 @@
|
||||
}
|
||||
code = this.base.compile(o);
|
||||
if (props[0] instanceof AccessorNode && this.isNumber() || o.top && this.base instanceof ObjectNode) {
|
||||
code = ("(" + (code) + ")");
|
||||
code = ("(" + code + ")");
|
||||
}
|
||||
for (_i = 0, _len = props.length; _i < _len; _i++) {
|
||||
prop = props[_i];
|
||||
@@ -477,7 +477,7 @@
|
||||
if (!(name)) {
|
||||
throw Error("cannot call super on an anonymous function.");
|
||||
}
|
||||
return method.klass ? ("" + (method.klass) + ".__super__." + (name)) : ("" + (name) + ".__super__.constructor");
|
||||
return method.klass ? ("" + (method.klass) + ".__super__." + name) : ("" + name + ".__super__.constructor");
|
||||
};
|
||||
CallNode.prototype.unfoldSoak = function(o) {
|
||||
var _i, _len, _ref2, call, list, node;
|
||||
@@ -530,7 +530,7 @@
|
||||
}
|
||||
left = ("typeof " + (left.compile(o)) + " !== \"function\"");
|
||||
rite = rite.compile(o);
|
||||
return ("(" + (left) + " ? undefined : " + (rite) + ")");
|
||||
return ("(" + left + " ? undefined : " + rite + ")");
|
||||
}
|
||||
_ref2 = this.args;
|
||||
for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
|
||||
@@ -547,16 +547,16 @@
|
||||
}
|
||||
return _result;
|
||||
}).call(this).join(', ');
|
||||
return this.isSuper ? this.compileSuper(args, o) : ("" + (this.prefix()) + (this.variable.compile(o)) + "(" + (args) + ")");
|
||||
return this.isSuper ? this.compileSuper(args, o) : ("" + (this.prefix()) + (this.variable.compile(o)) + "(" + args + ")");
|
||||
};
|
||||
CallNode.prototype.compileSuper = function(args, o) {
|
||||
return "" + (this.superReference(o)) + ".call(this" + (args.length ? ', ' : '') + (args) + ")";
|
||||
return "" + (this.superReference(o)) + ".call(this" + (args.length ? ', ' : '') + args + ")";
|
||||
};
|
||||
CallNode.prototype.compileSplat = function(o) {
|
||||
var _i, _len, _ref2, a, arg, argvar, b, base, c, call, fun, idt, name, ref, splatargs;
|
||||
splatargs = this.compileSplatArguments(o);
|
||||
if (this.isSuper) {
|
||||
return ("" + (this.superReference(o)) + ".apply(this, " + (splatargs) + ")");
|
||||
return ("" + (this.superReference(o)) + ".apply(this, " + splatargs + ")");
|
||||
}
|
||||
if (!(this.isNew)) {
|
||||
if (!((base = this.variable) instanceof ValueNode)) {
|
||||
@@ -564,14 +564,14 @@
|
||||
}
|
||||
if ((name = base.properties.pop()) && base.isComplex()) {
|
||||
ref = o.scope.freeVariable('this');
|
||||
fun = ("(" + (ref) + " = " + (base.compile(o)) + ")" + (name.compile(o)));
|
||||
fun = ("(" + ref + " = " + (base.compile(o)) + ")" + (name.compile(o)));
|
||||
} else {
|
||||
fun = (ref = base.compile(o));
|
||||
if (name) {
|
||||
fun += name.compile(o);
|
||||
}
|
||||
}
|
||||
return ("" + (fun) + ".apply(" + (ref) + ", " + (splatargs) + ")");
|
||||
return ("" + fun + ".apply(" + ref + ", " + splatargs + ")");
|
||||
}
|
||||
call = 'call(this)';
|
||||
argvar = function(n) {
|
||||
@@ -588,7 +588,7 @@
|
||||
a = o.scope.freeVariable('ctor');
|
||||
b = o.scope.freeVariable('ref');
|
||||
c = o.scope.freeVariable('result');
|
||||
return "(function() {\n" + (idt = this.idt(1)) + "var ctor = function() {};\n" + (idt) + (utility('extends')) + "(ctor, " + (a) + " = " + (this.variable.compile(o)) + ");\n" + (idt) + "return typeof (" + (c) + " = " + (a) + ".apply(" + (b) + " = new ctor, " + (splatargs) + ")) === \"object\" ? " + (c) + " : " + (b) + ";\n" + (this.tab) + "})." + (call);
|
||||
return "(function() {\n" + (idt = this.idt(1)) + "var ctor = function() {};\n" + idt + (utility('extends')) + "(ctor, " + a + " = " + (this.variable.compile(o)) + ");\n" + idt + "return typeof (" + c + " = " + a + ".apply(" + b + " = new ctor, " + splatargs + ")) === \"object\" ? " + c + " : " + b + ";\n" + this.tab + "})." + call;
|
||||
};
|
||||
return CallNode;
|
||||
})();
|
||||
@@ -623,7 +623,7 @@
|
||||
AccessorNode.prototype.compileNode = function(o) {
|
||||
var name, namePart;
|
||||
name = this.name.compile(o);
|
||||
namePart = name.match(IS_STRING) ? ("[" + (name) + "]") : ("." + (name));
|
||||
namePart = name.match(IS_STRING) ? ("[" + name + "]") : ("." + name);
|
||||
return this.prototype + namePart;
|
||||
};
|
||||
AccessorNode.prototype.isComplex = NO;
|
||||
@@ -642,7 +642,7 @@
|
||||
var idx, prefix;
|
||||
idx = this.index.compile(o);
|
||||
prefix = this.proto ? '.prototype' : '';
|
||||
return "" + (prefix) + "[" + (idx) + "]";
|
||||
return "" + prefix + "[" + idx + "]";
|
||||
};
|
||||
IndexNode.prototype.isComplex = function() {
|
||||
return this.index.isComplex();
|
||||
@@ -692,20 +692,20 @@
|
||||
}
|
||||
idx = del(o, 'index');
|
||||
step = del(o, 'step');
|
||||
vars = ("" + (idx) + " = " + (this.fromVar));
|
||||
intro = ("(" + (this.fromVar) + " <= " + (this.toVar) + " ? " + (idx));
|
||||
compare = ("" + (intro) + " <" + (this.equals) + " " + (this.toVar) + " : " + (idx) + " >" + (this.equals) + " " + (this.toVar) + ")");
|
||||
vars = ("" + idx + " = " + this.fromVar);
|
||||
intro = ("(" + this.fromVar + " <= " + this.toVar + " ? " + idx);
|
||||
compare = ("" + intro + " <" + this.equals + " " + this.toVar + " : " + idx + " >" + this.equals + " " + this.toVar + ")");
|
||||
stepPart = step ? step.compile(o) : '1';
|
||||
incr = step ? ("" + (idx) + " += " + (stepPart)) : ("" + (intro) + " += " + (stepPart) + " : " + (idx) + " -= " + (stepPart) + ")");
|
||||
return "" + (vars) + "; " + (compare) + "; " + (incr);
|
||||
incr = step ? ("" + idx + " += " + stepPart) : ("" + intro + " += " + stepPart + " : " + idx + " -= " + stepPart + ")");
|
||||
return "" + vars + "; " + compare + "; " + incr;
|
||||
};
|
||||
RangeNode.prototype.compileSimple = function(o) {
|
||||
var _ref2, from, idx, step, to;
|
||||
_ref2 = [+this.fromNum, +this.toNum], from = _ref2[0], to = _ref2[1];
|
||||
idx = del(o, 'index');
|
||||
step = del(o, 'step');
|
||||
step && (step = ("" + (idx) + " += " + (step.compile(o))));
|
||||
return from <= to ? ("" + (idx) + " = " + (from) + "; " + (idx) + " <" + (this.equals) + " " + (to) + "; " + (step || ("" + (idx) + "++"))) : ("" + (idx) + " = " + (from) + "; " + (idx) + " >" + (this.equals) + " " + (to) + "; " + (step || ("" + (idx) + "--")));
|
||||
step && (step = ("" + idx + " += " + (step.compile(o))));
|
||||
return from <= to ? ("" + idx + " = " + from + "; " + idx + " <" + this.equals + " " + to + "; " + (step || ("" + idx + "++"))) : ("" + idx + " = " + from + "; " + idx + " >" + this.equals + " " + to + "; " + (step || ("" + idx + "--")));
|
||||
};
|
||||
RangeNode.prototype.compileArray = function(o) {
|
||||
var _i, _ref2, _ref3, _result, body, clause, i, idt, post, pre, range, result, vars;
|
||||
@@ -726,16 +726,16 @@
|
||||
}
|
||||
i = o.scope.freeVariable('i');
|
||||
result = o.scope.freeVariable('result');
|
||||
pre = ("\n" + (idt) + (result) + " = []; " + (vars));
|
||||
pre = ("\n" + idt + result + " = []; " + vars);
|
||||
if (this.fromNum && this.toNum) {
|
||||
o.index = i;
|
||||
body = this.compileSimple(o);
|
||||
} else {
|
||||
clause = ("" + (this.fromVar) + " <= " + (this.toVar) + " ?");
|
||||
body = ("var " + (i) + " = " + (this.fromVar) + "; " + (clause) + " " + (i) + " <" + (this.equals) + " " + (this.toVar) + " : " + (i) + " >" + (this.equals) + " " + (this.toVar) + "; " + (clause) + " " + (i) + " += 1 : " + (i) + " -= 1");
|
||||
clause = ("" + this.fromVar + " <= " + this.toVar + " ?");
|
||||
body = ("var " + i + " = " + this.fromVar + "; " + clause + " " + i + " <" + this.equals + " " + this.toVar + " : " + i + " >" + this.equals + " " + this.toVar + "; " + clause + " " + i + " += 1 : " + i + " -= 1");
|
||||
}
|
||||
post = ("{ " + (result) + ".push(" + (i) + "); }\n" + (idt) + "return " + (result) + ";\n" + (o.indent));
|
||||
return "(function() {" + (pre) + "\n" + (idt) + "for (" + (body) + ")" + (post) + "}).call(this)";
|
||||
post = ("{ " + result + ".push(" + i + "); }\n" + idt + "return " + result + ";\n" + (o.indent));
|
||||
return "(function() {" + pre + "\n" + idt + "for (" + body + ")" + post + "}).call(this)";
|
||||
};
|
||||
return RangeNode;
|
||||
})();
|
||||
@@ -756,7 +756,7 @@
|
||||
if (to) {
|
||||
to = ', ' + to;
|
||||
}
|
||||
return ".slice(" + (from) + (to) + ")";
|
||||
return ".slice(" + from + to + ")";
|
||||
};
|
||||
return SliceNode;
|
||||
})();
|
||||
@@ -808,7 +808,7 @@
|
||||
}).call(this);
|
||||
props = props.join('');
|
||||
obj = '{' + (props ? '\n' + props + '\n' + this.idt() : '') + '}';
|
||||
return top ? ("(" + (obj) + ")") : obj;
|
||||
return top ? ("(" + obj + ")") : obj;
|
||||
};
|
||||
return ObjectNode;
|
||||
})();
|
||||
@@ -836,15 +836,15 @@
|
||||
if (obj instanceof SplatNode) {
|
||||
return this.compileSplatLiteral(o);
|
||||
} else if (obj instanceof CommentNode) {
|
||||
objects.push("\n" + (code) + "\n" + (o.indent));
|
||||
objects.push("\n" + code + "\n" + (o.indent));
|
||||
} else if (i === this.objects.length - 1) {
|
||||
objects.push(code);
|
||||
} else {
|
||||
objects.push("" + (code) + ", ");
|
||||
objects.push("" + code + ", ");
|
||||
}
|
||||
}
|
||||
objects = objects.join('');
|
||||
return indexOf(objects, '\n') >= 0 ? ("[\n" + (this.idt(1)) + (objects) + "\n" + (this.tab) + "]") : ("[" + (objects) + "]");
|
||||
return indexOf(objects, '\n') >= 0 ? ("[\n" + (this.idt(1)) + objects + "\n" + this.tab + "]") : ("[" + objects + "]");
|
||||
};
|
||||
return ArrayNode;
|
||||
})();
|
||||
@@ -909,7 +909,7 @@
|
||||
if (constructor.body.empty()) {
|
||||
constructor.body.push(new ReturnNode(literal('this')));
|
||||
}
|
||||
constructor.body.unshift(literal("this." + (pname) + " = function(){ return " + (className) + ".prototype." + (pname) + ".apply(" + (me) + ", arguments); }"));
|
||||
constructor.body.unshift(literal("this." + pname + " = function(){ return " + className + ".prototype." + pname + ".apply(" + me + ", arguments); }"));
|
||||
}
|
||||
}
|
||||
if (pvar) {
|
||||
@@ -920,7 +920,7 @@
|
||||
props.push(prop);
|
||||
}
|
||||
if (me) {
|
||||
constructor.body.unshift(literal("" + (me) + " = this"));
|
||||
constructor.body.unshift(literal("" + me + " = this"));
|
||||
}
|
||||
construct = this.idt() + (new AssignNode(this.variable, constructor)).compile(merge(o, {
|
||||
sharedScope: constScope
|
||||
@@ -970,16 +970,16 @@
|
||||
}
|
||||
val = this.value.compile(o);
|
||||
if (this.context === 'object') {
|
||||
return ("" + (name) + ": " + (val));
|
||||
return ("" + name + ": " + val);
|
||||
}
|
||||
if (!(isValue && (this.variable.hasProperties() || this.variable.namespaced))) {
|
||||
o.scope.find(name);
|
||||
}
|
||||
val = ("" + (name) + " = " + (val));
|
||||
val = ("" + name + " = " + val);
|
||||
if (stmt) {
|
||||
return ("" + (this.tab) + (val) + ";");
|
||||
return ("" + this.tab + val + ";");
|
||||
}
|
||||
return top || this.parenthetical ? val : ("(" + (val) + ")");
|
||||
return top || this.parenthetical ? val : ("(" + val + ")");
|
||||
};
|
||||
AssignNode.prototype.compilePatternMatch = function(o) {
|
||||
var _len, _ref2, accessClass, assigns, code, i, idx, isObject, obj, objects, olength, otop, splat, top, val, valVar, value;
|
||||
@@ -1009,7 +1009,7 @@
|
||||
top: true
|
||||
});
|
||||
valVar = o.scope.freeVariable('ref');
|
||||
assigns = [("" + (valVar) + " = " + (value.compile(o)))];
|
||||
assigns = [("" + valVar + " = " + (value.compile(o)))];
|
||||
splat = false;
|
||||
for (i = 0, _len = objects.length; i < _len; i++) {
|
||||
obj = objects[i];
|
||||
@@ -1030,7 +1030,7 @@
|
||||
splat = true;
|
||||
} else {
|
||||
if (typeof idx !== 'object') {
|
||||
idx = literal(splat ? ("" + (valVar) + ".length - " + (olength - idx)) : idx);
|
||||
idx = literal(splat ? ("" + valVar + ".length - " + (olength - idx)) : idx);
|
||||
}
|
||||
val = new ValueNode(literal(valVar), [new accessClass(idx)]);
|
||||
}
|
||||
@@ -1040,7 +1040,7 @@
|
||||
assigns.push(valVar);
|
||||
}
|
||||
code = assigns.join(', ');
|
||||
return top || this.parenthetical ? code : ("(" + (code) + ")");
|
||||
return top || this.parenthetical ? code : ("(" + code + ")");
|
||||
};
|
||||
AssignNode.prototype.compileSplice = function(o) {
|
||||
var from, name, plus, range, ref, to, val;
|
||||
@@ -1048,10 +1048,10 @@
|
||||
name = this.variable.compile(o);
|
||||
plus = range.exclusive ? '' : ' + 1';
|
||||
from = range.from ? range.from.compile(o) : '0';
|
||||
to = range.to ? range.to.compile(o) + ' - ' + from + plus : ("" + (name) + ".length");
|
||||
to = range.to ? range.to.compile(o) + ' - ' + from + plus : ("" + name + ".length");
|
||||
ref = o.scope.freeVariable('ref');
|
||||
val = this.value.compile(o);
|
||||
return "([].splice.apply(" + (name) + ", [" + (from) + ", " + (to) + "].concat(" + (ref) + " = " + (val) + ")), " + (ref) + ")";
|
||||
return "([].splice.apply(" + name + ", [" + from + ", " + to + "].concat(" + ref + " = " + val + ")), " + ref + ")";
|
||||
};
|
||||
return AssignNode;
|
||||
})();
|
||||
@@ -1125,11 +1125,11 @@
|
||||
(o.scope.parameter(param));
|
||||
}
|
||||
code = this.body.expressions.length ? ("\n" + (this.body.compileWithDeclarations(o)) + "\n") : '';
|
||||
func = ("function(" + (params.join(', ')) + ") {" + (code) + (code && this.tab) + "}");
|
||||
func = ("function(" + (params.join(', ')) + ") {" + code + (code && this.tab) + "}");
|
||||
if (this.bound) {
|
||||
return ("(" + (utility('bind')) + "(" + (func) + ", " + (this.context) + "))");
|
||||
return ("(" + (utility('bind')) + "(" + func + ", " + this.context + "))");
|
||||
}
|
||||
return top ? ("(" + (func) + ")") : func;
|
||||
return top ? ("(" + func + ")") : func;
|
||||
};
|
||||
CodeNode.prototype.topSensitive = YES;
|
||||
CodeNode.prototype.traverseChildren = function(crossScope, func) {
|
||||
@@ -1190,7 +1190,7 @@
|
||||
o.scope.assign(len, "arguments.length");
|
||||
variadic = o.scope.freeVariable('result');
|
||||
o.scope.assign(variadic, len + ' >= ' + this.arglength);
|
||||
end = this.trailings.length ? (", " + (len) + " - " + (this.trailings.length)) : undefined;
|
||||
end = this.trailings.length ? (", " + len + " - " + (this.trailings.length)) : undefined;
|
||||
_ref2 = this.trailings;
|
||||
for (idx = 0, _len = _ref2.length; idx < _len; idx++) {
|
||||
trailing = _ref2[idx];
|
||||
@@ -1200,15 +1200,15 @@
|
||||
assign.value = trailing;
|
||||
}
|
||||
pos = this.trailings.length - idx;
|
||||
o.scope.assign(trailing.compile(o), "arguments[" + (variadic) + " ? " + (len) + " - " + (pos) + " : " + (this.index + idx) + "]");
|
||||
o.scope.assign(trailing.compile(o), "arguments[" + variadic + " ? " + len + " - " + pos + " : " + (this.index + idx) + "]");
|
||||
}
|
||||
}
|
||||
return "" + (name) + " = " + (utility('slice')) + ".call(arguments, " + (this.index) + (end) + ")";
|
||||
return "" + name + " = " + (utility('slice')) + ".call(arguments, " + this.index + end + ")";
|
||||
};
|
||||
SplatNode.prototype.compileValue = function(o, name, index, trailings) {
|
||||
var trail;
|
||||
trail = trailings ? (", " + (name) + ".length - " + (trailings)) : '';
|
||||
return "" + (utility('slice')) + ".call(" + (name) + ", " + (index) + (trail) + ")";
|
||||
trail = trailings ? (", " + name + ".length - " + trailings) : '';
|
||||
return "" + (utility('slice')) + ".call(" + name + ", " + index + trail + ")";
|
||||
};
|
||||
SplatNode.compileSplattedArray = function(list, o) {
|
||||
var _len, arg, args, code, end, i, prev;
|
||||
@@ -1220,16 +1220,16 @@
|
||||
prev = args[end];
|
||||
if (!(arg instanceof SplatNode)) {
|
||||
if (prev && starts(prev, '[') && ends(prev, ']')) {
|
||||
args[end] = ("" + (prev.slice(0, -1)) + ", " + (code) + "]");
|
||||
args[end] = ("" + (prev.slice(0, -1)) + ", " + code + "]");
|
||||
continue;
|
||||
}
|
||||
if (prev && starts(prev, '.concat([') && ends(prev, '])')) {
|
||||
args[end] = ("" + (prev.slice(0, -2)) + ", " + (code) + "])");
|
||||
args[end] = ("" + (prev.slice(0, -2)) + ", " + code + "])");
|
||||
continue;
|
||||
}
|
||||
code = ("[" + (code) + "]");
|
||||
code = ("[" + code + "]");
|
||||
}
|
||||
args[++end] = i === 0 ? code : (".concat(" + (code) + ")");
|
||||
args[++end] = i === 0 ? code : (".concat(" + code + ")");
|
||||
}
|
||||
return args.join('');
|
||||
};
|
||||
@@ -1271,12 +1271,12 @@
|
||||
set = '';
|
||||
if (!(top)) {
|
||||
rvar = o.scope.freeVariable('result');
|
||||
set = ("" + (this.tab) + (rvar) + " = [];\n");
|
||||
set = ("" + this.tab + rvar + " = [];\n");
|
||||
if (this.body) {
|
||||
this.body = PushNode.wrap(rvar, this.body);
|
||||
}
|
||||
}
|
||||
pre = ("" + (set) + (this.tab) + "while (" + (cond) + ")");
|
||||
pre = ("" + set + this.tab + "while (" + cond + ")");
|
||||
if (this.guard) {
|
||||
this.body = Expressions.wrap([new IfNode(this.guard, this.body)]);
|
||||
}
|
||||
@@ -1287,7 +1287,7 @@
|
||||
} else {
|
||||
post = '';
|
||||
}
|
||||
return "" + (pre) + " {\n" + (this.body.compile(o)) + "\n" + (this.tab) + "}" + (post);
|
||||
return "" + pre + " {\n" + (this.body.compile(o)) + "\n" + this.tab + "}" + post;
|
||||
};
|
||||
return WhileNode;
|
||||
})();
|
||||
@@ -1377,7 +1377,7 @@
|
||||
shared = this.first.unwrap().second;
|
||||
_ref2 = shared.compileReference(o), this.first.second = _ref2[0], shared = _ref2[1];
|
||||
_ref2 = [this.first.compile(o), this.second.compile(o), shared.compile(o)], first = _ref2[0], second = _ref2[1], shared = _ref2[2];
|
||||
return "(" + (first) + ") && (" + (shared) + " " + (this.operator) + " " + (second) + ")";
|
||||
return "(" + first + ") && (" + shared + " " + this.operator + " " + second + ")";
|
||||
};
|
||||
OpNode.prototype.compileAssignment = function(o) {
|
||||
var _ref2, left, rite;
|
||||
@@ -1394,7 +1394,7 @@
|
||||
fst = this.first;
|
||||
ref = fst.compile(o);
|
||||
}
|
||||
return new ExistenceNode(fst).compile(o) + (" ? " + (ref) + " : " + (this.second.compile(o)));
|
||||
return new ExistenceNode(fst).compile(o) + (" ? " + ref + " : " + (this.second.compile(o)));
|
||||
};
|
||||
OpNode.prototype.compileUnary = function(o) {
|
||||
var parts, space;
|
||||
@@ -1446,7 +1446,7 @@
|
||||
}), this.arr1 = _ref2[0], this.arr2 = _ref2[1];
|
||||
_ref2 = [o.scope.freeVariable('i'), o.scope.freeVariable('len')], i = _ref2[0], l = _ref2[1];
|
||||
prefix = this.obj1 !== this.obj2 ? this.obj1 + '; ' : '';
|
||||
return "(function(){ " + (prefix) + "for (var " + (i) + "=0, " + (l) + "=" + (this.arr1) + ".length; " + (i) + "<" + (l) + "; " + (i) + "++) { if (" + (this.arr2) + "[" + (i) + "] === " + (this.obj2) + ") return true; } return false; }).call(this)";
|
||||
return "(function(){ " + prefix + "for (var " + i + "=0, " + l + "=" + this.arr1 + ".length; " + i + "<" + l + "; " + i + "++) { if (" + this.arr2 + "[" + i + "] === " + this.obj2 + ") return true; } return false; }).call(this)";
|
||||
};
|
||||
return InNode;
|
||||
})();
|
||||
@@ -1478,9 +1478,9 @@
|
||||
o.top = true;
|
||||
attemptPart = this.attempt.compile(o);
|
||||
errorPart = this.error ? (" (" + (this.error.compile(o)) + ") ") : ' ';
|
||||
catchPart = this.recovery ? (" catch" + (errorPart) + "{\n" + (this.recovery.compile(o)) + "\n" + (this.tab) + "}") : '';
|
||||
finallyPart = (this.ensure || '') && ' finally {\n' + this.ensure.compile(merge(o)) + ("\n" + (this.tab) + "}");
|
||||
return "" + (this.tab) + "try {\n" + (attemptPart) + "\n" + (this.tab) + "}" + (catchPart) + (finallyPart);
|
||||
catchPart = this.recovery ? (" catch" + errorPart + "{\n" + (this.recovery.compile(o)) + "\n" + this.tab + "}") : '';
|
||||
finallyPart = (this.ensure || '') && ' finally {\n' + this.ensure.compile(merge(o)) + ("\n" + this.tab + "}");
|
||||
return "" + this.tab + "try {\n" + attemptPart + "\n" + this.tab + "}" + catchPart + finallyPart;
|
||||
};
|
||||
return TryNode;
|
||||
})();
|
||||
@@ -1496,7 +1496,7 @@
|
||||
ThrowNode.prototype.isStatement = YES;
|
||||
ThrowNode.prototype.makeReturn = THIS;
|
||||
ThrowNode.prototype.compileNode = function(o) {
|
||||
return "" + (this.tab) + "throw " + (this.expression.compile(o)) + ";";
|
||||
return "" + this.tab + "throw " + (this.expression.compile(o)) + ";";
|
||||
};
|
||||
return ThrowNode;
|
||||
})();
|
||||
@@ -1512,8 +1512,8 @@
|
||||
ExistenceNode.prototype.compileNode = function(o) {
|
||||
var code;
|
||||
code = this.expression.compile(o);
|
||||
code = IDENTIFIER.test(code) && !o.scope.check(code) ? ("typeof " + (code) + " !== \"undefined\" && " + (code) + " !== null") : ("" + (code) + " != null");
|
||||
return this.parenthetical ? code : ("(" + (code) + ")");
|
||||
code = IDENTIFIER.test(code) && !o.scope.check(code) ? ("typeof " + code + " !== \"undefined\" && " + code + " !== null") : ("" + code + " != null");
|
||||
return this.parenthetical ? code : ("(" + code + ")");
|
||||
};
|
||||
return ExistenceNode;
|
||||
})();
|
||||
@@ -1547,7 +1547,7 @@
|
||||
if (this.parenthetical || this.isStatement(o)) {
|
||||
return top ? this.tab + code + ';' : code;
|
||||
}
|
||||
return "(" + (code) + ")";
|
||||
return "(" + code + ")";
|
||||
};
|
||||
return ParentheticalNode;
|
||||
})();
|
||||
@@ -1638,20 +1638,20 @@
|
||||
sourcePart = '';
|
||||
} else {
|
||||
ref = scope.freeVariable('ref');
|
||||
sourcePart = ("" + (ref) + " = " + (svar) + ";");
|
||||
sourcePart = ("" + ref + " = " + svar + ";");
|
||||
svar = ref;
|
||||
}
|
||||
namePart = this.pattern ? new AssignNode(this.name, literal("" + (svar) + "[" + (ivar) + "]")).compile(merge(o, {
|
||||
namePart = this.pattern ? new AssignNode(this.name, literal("" + svar + "[" + ivar + "]")).compile(merge(o, {
|
||||
top: true
|
||||
})) : (name ? ("" + (name) + " = " + (svar) + "[" + (ivar) + "]") : undefined);
|
||||
})) : (name ? ("" + name + " = " + svar + "[" + ivar + "]") : undefined);
|
||||
if (!(this.object)) {
|
||||
lvar = scope.freeVariable('len');
|
||||
stepPart = this.step ? ("" + (ivar) + " += " + (this.step.compile(o))) : ("" + (ivar) + "++");
|
||||
forPart = ("" + (ivar) + " = 0, " + (lvar) + " = " + (svar) + ".length; " + (ivar) + " < " + (lvar) + "; " + (stepPart));
|
||||
stepPart = this.step ? ("" + ivar + " += " + (this.step.compile(o))) : ("" + ivar + "++");
|
||||
forPart = ("" + ivar + " = 0, " + lvar + " = " + svar + ".length; " + ivar + " < " + lvar + "; " + stepPart);
|
||||
}
|
||||
}
|
||||
sourcePart = (rvar ? ("" + (rvar) + " = []; ") : '') + sourcePart;
|
||||
sourcePart = sourcePart ? ("" + (this.tab) + (sourcePart) + "\n" + (this.tab)) : this.tab;
|
||||
sourcePart = (rvar ? ("" + rvar + " = []; ") : '') + sourcePart;
|
||||
sourcePart = sourcePart ? ("" + this.tab + sourcePart + "\n" + this.tab) : this.tab;
|
||||
returnResult = this.compileReturnValue(rvar, o);
|
||||
if (!(topLevel)) {
|
||||
body = PushNode.wrap(rvar, body);
|
||||
@@ -1661,32 +1661,32 @@
|
||||
}
|
||||
if (codeInBody) {
|
||||
if (range) {
|
||||
body.unshift(literal("var " + (name) + " = " + (ivar)));
|
||||
body.unshift(literal("var " + name + " = " + ivar));
|
||||
}
|
||||
if (namePart) {
|
||||
body.unshift(literal("var " + (namePart)));
|
||||
body.unshift(literal("var " + namePart));
|
||||
}
|
||||
if (index) {
|
||||
body.unshift(literal("var " + (index) + " = " + (ivar)));
|
||||
body.unshift(literal("var " + index + " = " + ivar));
|
||||
}
|
||||
body = ClosureNode.wrap(body, true);
|
||||
} else {
|
||||
if (namePart) {
|
||||
varPart = ("" + (idt1) + (namePart) + ";\n");
|
||||
varPart = ("" + idt1 + namePart + ";\n");
|
||||
}
|
||||
}
|
||||
if (this.object) {
|
||||
forPart = ("" + (ivar) + " in " + (svar));
|
||||
forPart = ("" + ivar + " in " + svar);
|
||||
if (!(this.raw)) {
|
||||
guardPart = ("\n" + (idt1) + "if (!" + (utility('hasProp')) + ".call(" + (svar) + ", " + (ivar) + ")) continue;");
|
||||
guardPart = ("\n" + idt1 + "if (!" + (utility('hasProp')) + ".call(" + svar + ", " + ivar + ")) continue;");
|
||||
}
|
||||
}
|
||||
body = body.compile(merge(o, {
|
||||
indent: idt1,
|
||||
top: true
|
||||
}));
|
||||
vars = range ? name : ("" + (name) + ", " + (ivar));
|
||||
return "" + (sourcePart) + "for (" + (forPart) + ") {" + (guardPart) + "\n" + (varPart) + (body) + "\n" + (this.tab) + "}" + (returnResult);
|
||||
vars = range ? name : ("" + name + ", " + ivar);
|
||||
return "" + sourcePart + "for (" + forPart + ") {" + guardPart + "\n" + varPart + body + "\n" + this.tab + "}" + returnResult;
|
||||
};
|
||||
return ForNode;
|
||||
})();
|
||||
@@ -1720,7 +1720,7 @@
|
||||
var _i, _j, _len, _len2, _ref2, _ref3, block, code, condition, conditions, exprs, idt, pair;
|
||||
idt = (o.indent = this.idt(2));
|
||||
o.top = true;
|
||||
code = ("" + (this.tab) + "switch (" + (this.subject.compile(o)) + ") {");
|
||||
code = ("" + this.tab + "switch (" + (this.subject.compile(o)) + ") {");
|
||||
_ref2 = this.cases;
|
||||
for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
|
||||
pair = _ref2[_i];
|
||||
@@ -1736,13 +1736,13 @@
|
||||
}
|
||||
code += ("\n" + (block.compile(o)));
|
||||
if (!(last(exprs) instanceof ReturnNode)) {
|
||||
code += ("\n" + (idt) + "break;");
|
||||
code += ("\n" + idt + "break;");
|
||||
}
|
||||
}
|
||||
if (this.otherwise) {
|
||||
code += ("\n" + (this.idt(1)) + "default:\n" + (this.otherwise.compile(o)));
|
||||
}
|
||||
code += ("\n" + (this.tab) + "}");
|
||||
code += ("\n" + this.tab + "}");
|
||||
return code;
|
||||
};
|
||||
return SwitchNode;
|
||||
@@ -1828,15 +1828,15 @@
|
||||
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) + "}");
|
||||
ifPart = ("" + ifDent + "if (" + (this.compileCondition(condO)) + ") {\n" + body + "\n" + this.tab + "}");
|
||||
if (!(this.elseBody)) {
|
||||
return ifPart;
|
||||
}
|
||||
elsePart = this.isChain ? ' else ' + this.elseBodyNode().compile(merge(o, {
|
||||
indent: this.idt(),
|
||||
chainChild: true
|
||||
})) : (" else {\n" + (this.elseBody.compile(o)) + "\n" + (this.tab) + "}");
|
||||
return "" + (ifPart) + (elsePart);
|
||||
})) : (" else {\n" + (this.elseBody.compile(o)) + "\n" + this.tab + "}");
|
||||
return "" + ifPart + elsePart;
|
||||
};
|
||||
IfNode.prototype.compileTernary = function(o) {
|
||||
var code, elsePart, ifPart;
|
||||
@@ -1846,8 +1846,8 @@
|
||||
}
|
||||
ifPart = this.condition.compile(o) + ' ? ' + this.bodyNode().compile(o);
|
||||
elsePart = this.elseBody ? this.elseBodyNode().compile(o) : 'undefined';
|
||||
code = ("" + (ifPart) + " : " + (elsePart));
|
||||
return this.tags.operation ? ("(" + (code) + ")") : code;
|
||||
code = ("" + ifPart + " : " + elsePart);
|
||||
return this.tags.operation ? ("(" + code + ")") : code;
|
||||
};
|
||||
return IfNode;
|
||||
})();
|
||||
@@ -1904,7 +1904,7 @@
|
||||
};
|
||||
utility = function(name) {
|
||||
var ref;
|
||||
ref = ("__" + (name));
|
||||
ref = ("__" + name);
|
||||
Scope.root.assign(ref, UTILITIES[name]);
|
||||
return ref;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user