mirror of
https://github.com/jashkenas/coffeescript.git
synced 2026-05-03 03:00:14 -04:00
Merge pull request #4089 from lydell/issue-4088
Fix #4088: Don't declare caught variables
This commit is contained in:
@@ -2721,7 +2721,9 @@
|
||||
var catchPart, ensurePart, generatedErrorVariableName, placeholder, tryPart;
|
||||
o.indent += TAB;
|
||||
tryPart = this.attempt.compileToFragments(o, LEVEL_TOP);
|
||||
catchPart = this.recovery ? (generatedErrorVariableName = o.scope.freeVariable('error'), placeholder = new Literal(generatedErrorVariableName), this.errorVariable ? this.recovery.unshift(new Assign(this.errorVariable, placeholder)) : void 0, [].concat(this.makeCode(" catch ("), placeholder.compileToFragments(o), this.makeCode(") {\n"), this.recovery.compileToFragments(o, LEVEL_TOP), this.makeCode("\n" + this.tab + "}"))) : !(this.ensure || this.recovery) ? [this.makeCode(" catch (" + generatedErrorVariableName + ") {}")] : [];
|
||||
catchPart = this.recovery ? (generatedErrorVariableName = o.scope.freeVariable('error', {
|
||||
reserve: false
|
||||
}), placeholder = new Literal(generatedErrorVariableName), this.errorVariable ? this.recovery.unshift(new Assign(this.errorVariable, placeholder)) : void 0, [].concat(this.makeCode(" catch ("), placeholder.compileToFragments(o), this.makeCode(") {\n"), this.recovery.compileToFragments(o, LEVEL_TOP), this.makeCode("\n" + this.tab + "}"))) : !(this.ensure || this.recovery) ? [this.makeCode(" catch (" + generatedErrorVariableName + ") {}")] : [];
|
||||
ensurePart = this.ensure ? [].concat(this.makeCode(" finally {\n"), this.ensure.compileToFragments(o, LEVEL_TOP), this.makeCode("\n" + this.tab + "}")) : [];
|
||||
return [].concat(this.makeCode(this.tab + "try {\n"), tryPart, this.makeCode("\n" + this.tab + "}"), catchPart, ensurePart);
|
||||
};
|
||||
|
||||
@@ -1920,7 +1920,7 @@ exports.Try = class Try extends Base
|
||||
tryPart = @attempt.compileToFragments o, LEVEL_TOP
|
||||
|
||||
catchPart = if @recovery
|
||||
generatedErrorVariableName = o.scope.freeVariable 'error'
|
||||
generatedErrorVariableName = o.scope.freeVariable 'error', reserve: no
|
||||
placeholder = new Literal generatedErrorVariableName
|
||||
@recovery.unshift new Assign @errorVariable, placeholder if @errorVariable
|
||||
[].concat @makeCode(" catch ("), placeholder.compileToFragments(o), @makeCode(") {\n"),
|
||||
|
||||
Reference in New Issue
Block a user