diff --git a/lib/nodes.js b/lib/nodes.js index 8329a825..734bf187 100644 --- a/lib/nodes.js +++ b/lib/nodes.js @@ -781,7 +781,7 @@ __extends(ObjectLiteral, Base); ObjectLiteral.prototype.children = ['properties']; ObjectLiteral.prototype.compileNode = function(o) { - var _i, _len, _len2, _ref2, _ref3, _result, _result2, i, indent, join, lastNoncom, nonComments, obj, prop, props, top; + var _i, _len, _ref2, _result, i, indent, join, lastNoncom, nonComments, obj, prop, props, top; top = del(o, 'top'); o.indent = this.idt(1); nonComments = (function() { @@ -796,10 +796,10 @@ }).call(this); lastNoncom = last(nonComments); props = (function() { - _result2 = []; - for (i = 0, _len2 = (_ref3 = this.properties).length; i < _len2; i++) { - prop = _ref3[i]; - _result2.push((function() { + _result = []; + for (i = 0, _len = (_ref2 = this.properties).length; i < _len; i++) { + prop = _ref2[i]; + _result.push((function() { join = i === this.properties.length - 1 ? '' : (prop === lastNoncom || prop instanceof Comment ? '\n' : ',\n'); indent = prop instanceof Comment ? '' : this.idt(1); if (prop instanceof Value && prop.tags["this"]) { @@ -810,7 +810,7 @@ return indent + prop.compile(o) + join; }).call(this)); } - return _result2; + return _result; }).call(this); props = props.join(''); obj = ("{" + (props ? '\n' + props + '\n' + this.idt() : '') + "}"); @@ -1123,7 +1123,7 @@ __extends(Code, Base); Code.prototype.children = ['params', 'body']; Code.prototype.compileNode = function(o) { - var _i, _j, _len, _len2, _len3, _ref2, _ref3, _result, close, code, comm, empty, func, i, open, param, params, sharedScope, splat, top, value; + var _i, _len, _len2, _ref2, _ref3, _result, close, code, comm, empty, func, i, open, param, params, sharedScope, splat, top, value; sharedScope = del(o, 'sharedScope'); top = del(o, 'top'); o.scope = sharedScope || new Scope(o.scope, this.body, this); @@ -1171,8 +1171,8 @@ if (!(empty || this.noReturn)) { this.body.makeReturn(); } - for (_j = 0, _len3 = params.length; _j < _len3; _j++) { - param = params[_j]; + for (_i = 0, _len2 = params.length; _i < _len2; _i++) { + param = params[_i]; (o.scope.parameter(param)); } comm = this.comment ? this.comment.compile(o) + '\n' : ''; diff --git a/lib/scope.js b/lib/scope.js index 3e72f828..dc8a46d4 100644 --- a/lib/scope.js +++ b/lib/scope.js @@ -43,22 +43,13 @@ return this.garbage.push([]); }; Scope.prototype.endLevel = function() { - var _i, _len, _len2, _ref2, _result, garbage, i, v, vars; + var _i, _len, _ref2, _result, garbage, vars; vars = this.variables; _result = []; for (_i = 0, _len = (_ref2 = this.garbage.pop()).length; _i < _len; _i++) { garbage = _ref2[_i]; if (this.type(garbage) === 'var') { - for (i = 0, _len2 = vars.length; i < _len2; i++) { - v = vars[i]; - if (v.name === garbage.name) { - vars.splice(i, 1, { - name: garbage.name, - type: 'reuse' - }); - break; - } - } + _result.push(this.setVar(garbage, 'reuse')); } } return _result; diff --git a/src/scope.coffee b/src/scope.coffee index b14c8e97..55feee85 100644 --- a/src/scope.coffee +++ b/src/scope.coffee @@ -43,9 +43,7 @@ exports.Scope = class Scope endLevel: -> vars = @variables for garbage in @garbage.pop() when @type(garbage) is 'var' - for v, i in vars when v.name is garbage.name - vars.splice(i, 1, {name: garbage.name, type: 'reuse'}) - break + @setVar garbage, 'reuse' # Look up a variable name in lexical scope, and declare it if it does not # already exist.