Fixes #2422 -- Catch clause scoping plus old IE

This commit is contained in:
Jeremy Ashkenas 2013-03-05 16:13:22 +13:00
parent 1b573412d3
commit f8c6b494aa
6 changed files with 27 additions and 27 deletions

View File

@ -46,7 +46,7 @@
}); });
exports.run = function() { exports.run = function() {
var arg, args, _i, _len, _ref, _results; var arg, args, e, _i, _len, _ref, _results;
global.__originalDirname = fs.realpathSync('.'); global.__originalDirname = fs.realpathSync('.');
process.chdir(cakefileDirectory(__originalDirname)); process.chdir(cakefileDirectory(__originalDirname));
args = process.argv.slice(2); args = process.argv.slice(2);
@ -59,7 +59,8 @@
} }
try { try {
options = oparse.parse(args); options = oparse.parse(args);
} catch (e) { } catch (_error) {
e = _error;
return fatalError("" + e); return fatalError("" + e);
} }
_ref = options["arguments"]; _ref = options["arguments"];

View File

@ -40,7 +40,7 @@
exports.helpers = helpers; exports.helpers = helpers;
exports.compile = compile = function(code, options) { exports.compile = compile = function(code, options) {
var answer, coffeeFile, currentColumn, currentLine, fragment, fragments, header, js, jsFile, merge, newLines, sourceMap, _j, _len1; var answer, coffeeFile, currentColumn, currentLine, err, fragment, fragments, header, js, jsFile, merge, newLines, sourceMap, _j, _len1;
if (options == null) { if (options == null) {
options = {}; options = {};
} }
@ -72,7 +72,8 @@
} }
js += fragment.code; js += fragment.code;
} }
} catch (err) { } catch (_error) {
err = _error;
if (options.filename) { if (options.filename) {
err.message = "In " + options.filename + ", " + err.message; err.message = "In " + options.filename + ", " + err.message;
} }

View File

@ -148,7 +148,7 @@
}; };
compileScript = function(file, input, base) { compileScript = function(file, input, base) {
var compiled, o, options, t, task; var compiled, err, o, options, t, task;
o = opts; o = opts;
options = compileOptions(file); options = compileOptions(file);
try { try {
@ -186,7 +186,8 @@
return lint(t.file, t.output); return lint(t.file, t.output);
} }
} }
} catch (err) { } catch (_error) {
err = _error;
CoffeeScript.emit('failure', err, task); CoffeeScript.emit('failure', err, task);
if (CoffeeScript.listeners('failure').length) { if (CoffeeScript.listeners('failure').length) {
return; return;
@ -230,7 +231,7 @@
}; };
watch = function(source, base) { watch = function(source, base) {
var compile, compileTimeout, prevStats, rewatch, watchErr, watcher; var compile, compileTimeout, e, prevStats, rewatch, watchErr, watcher;
prevStats = null; prevStats = null;
compileTimeout = null; compileTimeout = null;
watchErr = function(e) { watchErr = function(e) {
@ -241,7 +242,8 @@
try { try {
rewatch(); rewatch();
return compile(); return compile();
} catch (e) { } catch (_error) {
e = _error;
removeSource(source, base, true); removeSource(source, base, true);
return compileJoin(); return compileJoin();
} }
@ -272,7 +274,8 @@
}; };
try { try {
watcher = fs.watch(source, compile); watcher = fs.watch(source, compile);
} catch (e) { } catch (_error) {
e = _error;
watchErr(e); watchErr(e);
} }
return rewatch = function() { return rewatch = function() {
@ -284,7 +287,7 @@
}; };
watchDir = function(source, base) { watchDir = function(source, base) {
var readdirTimeout, watcher; var e, readdirTimeout, watcher;
readdirTimeout = null; readdirTimeout = null;
try { try {
return watcher = fs.watch(source, function() { return watcher = fs.watch(source, function() {
@ -319,7 +322,8 @@
}); });
}); });
}); });
} catch (e) { } catch (_error) {
e = _error;
if (e.code !== 'ENOENT') { if (e.code !== 'ENOENT') {
throw e; throw e;
} }

View File

@ -2499,19 +2499,14 @@
o.indent += TAB; o.indent += TAB;
tryPart = this.attempt.compileToFragments(o, LEVEL_TOP); tryPart = this.attempt.compileToFragments(o, LEVEL_TOP);
catchPart = (function() { catchPart = (function() {
var _base, _ref4; var _ref4;
if (this.recovery) { if (this.recovery) {
if (typeof (_base = this.error).isObject === "function" ? _base.isObject() : void 0) { placeholder = new Literal('_error');
placeholder = new Literal('_error'); this.recovery.unshift(new Assign(this.error, placeholder));
this.recovery.unshift(new Assign(this.error, placeholder)); this.error = placeholder;
this.error = placeholder;
}
if (_ref4 = this.error.value, __indexOf.call(STRICT_PROSCRIBED, _ref4) >= 0) { if (_ref4 = this.error.value, __indexOf.call(STRICT_PROSCRIBED, _ref4) >= 0) {
throw SyntaxError("catch variable may not be \"" + this.error.value + "\""); throw SyntaxError("catch variable may not be \"" + this.error.value + "\"");
} }
if (!o.scope.check(this.error.value)) {
o.scope.add(this.error.value, 'param');
}
return [].concat(this.makeCode(" catch ("), this.error.compileToFragments(o), this.makeCode(") {\n"), this.recovery.compileToFragments(o, LEVEL_TOP), this.makeCode("\n" + this.tab + "}")); return [].concat(this.makeCode(" catch ("), this.error.compileToFragments(o), this.makeCode(") {\n"), this.recovery.compileToFragments(o, LEVEL_TOP), this.makeCode("\n" + this.tab + "}"));
} else if (!(this.ensure || this.recovery)) { } else if (!(this.ensure || this.recovery)) {
return [this.makeCode(' catch (_error) {}')]; return [this.makeCode(' catch (_error) {}')];

View File

@ -13,7 +13,7 @@
replDefaults = { replDefaults = {
prompt: 'coffee> ', prompt: 'coffee> ',
"eval": function(input, context, filename, cb) { "eval": function(input, context, filename, cb) {
var js; var err, js;
input = input.replace(/\uFF00/g, '\n'); input = input.replace(/\uFF00/g, '\n');
input = input.replace(/(^|[\r\n]+)(\s*)##?(?:[^#\r\n][^\r\n]*|)($|[\r\n])/, '$1$2$3'); input = input.replace(/(^|[\r\n]+)(\s*)##?(?:[^#\r\n][^\r\n]*|)($|[\r\n])/, '$1$2$3');
if (/^(\s*|\(\s*\))$/.test(input)) { if (/^(\s*|\(\s*\))$/.test(input)) {
@ -25,7 +25,8 @@
bare: true bare: true
}); });
return cb(null, vm.runInContext(js, context, filename)); return cb(null, vm.runInContext(js, context, filename));
} catch (err) { } catch (_error) {
err = _error;
return cb(err); return cb(err);
} }
} }

View File

@ -1739,13 +1739,11 @@ exports.Try = class Try extends Base
tryPart = @attempt.compileToFragments o, LEVEL_TOP tryPart = @attempt.compileToFragments o, LEVEL_TOP
catchPart = if @recovery catchPart = if @recovery
if @error.isObject?() placeholder = new Literal '_error'
placeholder = new Literal '_error' @recovery.unshift new Assign @error, placeholder
@recovery.unshift new Assign @error, placeholder @error = placeholder
@error = placeholder
if @error.value in STRICT_PROSCRIBED if @error.value in STRICT_PROSCRIBED
throw SyntaxError "catch variable may not be \"#{@error.value}\"" throw SyntaxError "catch variable may not be \"#{@error.value}\""
o.scope.add @error.value, 'param' unless o.scope.check @error.value
[].concat @makeCode(" catch ("), @error.compileToFragments(o), @makeCode(") {\n"), [].concat @makeCode(" catch ("), @error.compileToFragments(o), @makeCode(") {\n"),
@recovery.compileToFragments(o, LEVEL_TOP), @makeCode("\n#{@tab}}") @recovery.compileToFragments(o, LEVEL_TOP), @makeCode("\n#{@tab}}")
else unless @ensure or @recovery else unless @ensure or @recovery