making ThrowNode not a pure_statement -- it can jump out of the closure just fine

This commit is contained in:
Jeremy Ashkenas
2010-03-08 05:19:48 -05:00
committed by Chris Hoffman
parent 270b9fde04
commit 7f0ab8308d
2 changed files with 14 additions and 4 deletions

View File

@@ -1142,7 +1142,9 @@ idt += TAB
return [this.first.compile(o), this.operator, this.second.compile(o)].join(' ');
};
// Mimic Python's chained comparisons when multiple comparison operators are
// used sequentially. For example: `50 < 65 > 10`
// used sequentially. For example:
// bin/coffee -e "puts 50 < 65 > 10"
// true
OpNode.prototype.compile_chain = function compile_chain(o) {
var _a, _b, first, second, shared;
shared = this.first.unwrap().second;
@@ -1173,6 +1175,8 @@ idt += TAB
}
return first + " = " + first + " " + (this.operator.substr(0, 2)) + " " + second;
};
// If this is an existence operator, we delegate to `ExistenceNode.compile_test`
// to give us the safe references for the variables.
OpNode.prototype.compile_existence = function compile_existence(o) {
var _a, first, second, test;
_a = [this.first.compile(o), this.second.compile(o)];
@@ -1181,6 +1185,7 @@ idt += TAB
test = ExistenceNode.compile_test(o, this.first);
return test + " ? " + first + " : " + second;
};
// Compile a unary **OpNode**.
OpNode.prototype.compile_unary = function compile_unary(o) {
var parts, space;
space = this.PREFIX_OPERATORS.indexOf(this.operator) >= 0 ? ' ' : '';
@@ -1192,7 +1197,8 @@ idt += TAB
};
return OpNode;
}).call(this);
// A try/catch/finally block.
//### TryNode
// A classic *try/catch/finally* block.
exports.TryNode = (function() {
TryNode = function TryNode(attempt, error, recovery, ensure) {
this.children = compact([(this.attempt = attempt), (this.recovery = recovery), (this.ensure = ensure)]);
@@ -1202,6 +1208,8 @@ idt += TAB
};
__extends(TryNode, BaseNode);
TryNode.prototype.type = 'Try';
// Compilation is more or less as you would expect -- the *finally* clause
// is optional, the *catch* is not.
TryNode.prototype.compile_node = function compile_node(o) {
var attempt_part, catch_part, error_part, finally_part;
o.indent = this.idt(1);
@@ -1217,6 +1225,7 @@ idt += TAB
return TryNode;
}).call(this);
statement(TryNode);
//### ThrowNode
// Throw an exception.
exports.ThrowNode = (function() {
ThrowNode = function ThrowNode(expression) {
@@ -1230,7 +1239,7 @@ idt += TAB
};
return ThrowNode;
}).call(this);
statement(ThrowNode, true);
statement(ThrowNode);
// Check an expression for existence (meaning not null or undefined).
exports.ExistenceNode = (function() {
ExistenceNode = function ExistenceNode(expression) {

View File

@@ -938,6 +938,7 @@ exports.TryNode: class TryNode extends BaseNode
statement TryNode
#### ThrowNode
# Throw an exception.
exports.ThrowNode: class ThrowNode extends BaseNode
@@ -949,7 +950,7 @@ exports.ThrowNode: class ThrowNode extends BaseNode
compile_node: (o) ->
"${@tab}throw ${@expression.compile(o)};"
statement ThrowNode, true
statement ThrowNode
# Check an expression for existence (meaning not null or undefined).