fixed over-escaping in here documents and addressed Stan's comments

This commit is contained in:
satyr
2010-10-05 03:30:48 +09:00
parent cdd033ffb0
commit 42a91219cb
8 changed files with 117 additions and 123 deletions

View File

@@ -220,10 +220,10 @@
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;
};
@@ -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;
})();
@@ -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;
})();
@@ -692,9 +692,9 @@
}
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;
@@ -705,7 +705,7 @@
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 + "--")));
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;
@@ -731,8 +731,8 @@
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)";
@@ -844,7 +844,7 @@
}
}
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;
})();
@@ -977,7 +977,7 @@
}
val = ("" + name + " = " + val);
if (stmt) {
return ("" + this.tab + val + ";");
return ("" + (this.tab) + val + ";");
}
return top || this.parenthetical ? val : ("(" + val + ")");
};
@@ -1127,7 +1127,7 @@
code = this.body.expressions.length ? ("\n" + (this.body.compileWithDeclarations(o)) + "\n") : '';
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;
};
@@ -1203,7 +1203,7 @@
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;
@@ -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;
@@ -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;
})();
@@ -1651,7 +1651,7 @@
}
}
sourcePart = (rvar ? ("" + rvar + " = []; ") : '') + sourcePart;
sourcePart = sourcePart ? ("" + this.tab + sourcePart + "\n" + this.tab) : this.tab;
sourcePart = sourcePart ? ("" + (this.tab) + sourcePart + "\n" + (this.tab)) : this.tab;
returnResult = this.compileReturnValue(rvar, o);
if (!(topLevel)) {
body = PushNode.wrap(rvar, body);
@@ -1686,7 +1686,7 @@
top: true
}));
vars = range ? name : ("" + name + ", " + ivar);
return "" + sourcePart + "for (" + forPart + ") {" + guardPart + "\n" + varPart + body + "\n" + this.tab + "}" + returnResult;
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];
@@ -1742,7 +1742,7 @@
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,14 +1828,14 @@
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 + "}");
})) : (" else {\n" + (this.elseBody.compile(o)) + "\n" + (this.tab) + "}");
return "" + ifPart + elsePart;
};
IfNode.prototype.compileTernary = function(o) {