diff --git a/lib/lexer.js b/lib/lexer.js index 1a542d77..04309dc0 100644 --- a/lib/lexer.js +++ b/lib/lexer.js @@ -208,7 +208,7 @@ return regex.length; }; Lexer.prototype.heregexToken = function(match) { - var body, flags, heregex, re, tag, tokens, value, _i, _len, _ref, _ref2, _ref3, _this; + var body, flags, heregex, re, tag, tokens, value, _i, _len, _ref, _ref2, _ref3; heregex = match[0], body = match[1], flags = match[2]; if (0 > body.indexOf('#{')) { re = body.replace(HEREGEX_OMIT, '').replace(/\//g, '\\/'); @@ -238,7 +238,7 @@ if (((_ref3 = tokens[0]) != null ? _ref3[0] : void 0) !== 'STRING') { this.tokens.push(['STRING', '""'], ['+', '+']); } - (_this = this.tokens).push.apply(_this, tokens); + (_ref = this.tokens).push.apply(_ref, tokens); if (flags) { this.tokens.push([',', ','], ['STRING', '"' + flags + '"']); } @@ -478,7 +478,7 @@ throw new Error("unterminated " + (stack.pop()[0]) + " on line " + (this.line + 1)); }; Lexer.prototype.interpolateString = function(str, options) { - var expr, heredoc, i, inner, interpolated, letter, nested, pi, regex, tag, tokens, value, _len, _ref, _ref2, _this; + var expr, heredoc, i, inner, interpolated, letter, nested, pi, regex, tag, tokens, value, _len, _ref, _ref2; if (options == null) { options = {}; } @@ -537,7 +537,7 @@ this.token('+', '+'); } if (tag === 'TOKENS') { - (_this = this.tokens).push.apply(_this, value); + (_ref = this.tokens).push.apply(_ref, value); } else { this.token('STRING', this.makeString(value, '"', heredoc)); } diff --git a/lib/nodes.js b/lib/nodes.js index a01334b4..17553604 100644 --- a/lib/nodes.js +++ b/lib/nodes.js @@ -606,7 +606,7 @@ return _results; }.call(this)).join(', '); if (this.isSuper) { - return this.compileSuper(args, o); + return this.superReference(o) + (".call(this" + (args && ', ' + args) + ")"); } else { return (this.isNew ? 'new ' : '') + this.variable.compile(o, LEVEL_ACCESS) + ("(" + args + ")"); } @@ -619,21 +619,24 @@ if (this.isSuper) { return "" + (this.superReference(o)) + ".apply(this, " + splatArgs + ")"; } - if (!this.isNew) { - base = new Value(this.variable); - if ((name = base.properties.pop()) && base.isComplex()) { - ref = o.scope.freeVariable('this'); - fun = "(" + ref + " = " + (base.compile(o, LEVEL_LIST)) + ")" + (name.compile(o)); - } else { - fun = ref = base.compile(o, LEVEL_ACCESS); - if (name) { - fun += name.compile(o); - } - } - return "" + fun + ".apply(" + ref + ", " + splatArgs + ")"; + if (this.isNew) { + idt = this.tab + TAB; + return "(function(func, args, ctor) {\n" + idt + "ctor.prototype = func.prototype;\n" + idt + "var child = new ctor, result = func.apply(child, args);\n" + idt + "return typeof result === \"object\" ? result : child;\n" + this.tab + "})(" + (this.variable.compile(o, LEVEL_LIST)) + ", " + splatArgs + ", function() {})"; } - idt = this.tab + TAB; - return "(function(func, args, ctor) {\n" + idt + "ctor.prototype = func.prototype;\n" + idt + "var child = new ctor, result = func.apply(child, args);\n" + idt + "return typeof result === \"object\" ? result : child;\n" + this.tab + "})(" + (this.variable.compile(o, LEVEL_LIST)) + ", " + splatArgs + ", function() {})"; + base = new Value(this.variable); + if ((name = base.properties.pop()) && base.isComplex()) { + ref = o.scope.temporary('ref'); + fun = "(" + ref + " = " + (base.compile(o, LEVEL_LIST)) + ")" + (name.compile(o)); + } else { + fun = base.compile(o, LEVEL_ACCESS); + if (name) { + ref = fun; + fun += name.compile(o); + } else { + ref = 'null'; + } + } + return "" + fun + ".apply(" + ref + ", " + splatArgs + ")"; }; return Call; }(); @@ -1227,7 +1230,7 @@ return !!this.ctor; }; Code.prototype.compileNode = function(o) { - var code, exprs, i, idt, lit, p, param, ref, scope, sharedScope, splats, v, val, vars, wasEmpty, _i, _j, _k, _len, _len2, _len3, _len4, _ref, _ref2, _ref3, _results, _this; + var code, exprs, i, idt, lit, p, param, ref, scope, sharedScope, splats, v, val, vars, wasEmpty, _i, _j, _k, _len, _len2, _len3, _len4, _ref, _ref2, _ref3, _results; sharedScope = del(o, 'sharedScope'); o.scope = scope = sharedScope || new Scope(o.scope, this.body, this); o.indent += TAB; @@ -1278,7 +1281,7 @@ exprs.unshift(splats); } if (exprs.length) { - (_this = this.body.expressions).unshift.apply(_this, exprs); + (_ref = this.body.expressions).unshift.apply(_ref, exprs); } if (!splats) { for (i = 0, _len4 = vars.length; i < _len4; i++) { diff --git a/lib/optparse.js b/lib/optparse.js index 7c40b5a4..4147a361 100755 --- a/lib/optparse.js +++ b/lib/optparse.js @@ -65,7 +65,7 @@ if (tuple.length < 3) { tuple.unshift(null); } - _results.push(buildRule.apply(buildRule, tuple)); + _results.push(buildRule.apply(null, tuple)); } return _results; }; diff --git a/src/nodes.coffee b/src/nodes.coffee index 9a0f9e8d..1aeac517 100644 --- a/src/nodes.coffee +++ b/src/nodes.coffee @@ -487,7 +487,7 @@ exports.Call = class Call extends Base return @compileSplat o, code args = (arg.compile o, LEVEL_LIST for arg in @args).join ', ' if @isSuper - @compileSuper args, o + @superReference(o) + ".call(this#{ args and ', ' + args })" else (if @isNew then 'new ' else '') + @variable.compile(o, LEVEL_ACCESS) + "(#{args})" @@ -502,23 +502,27 @@ exports.Call = class Call extends Base # inner constructor in order to be able to pass the varargs. compileSplat: (o, splatArgs) -> return "#{ @superReference o }.apply(this, #{splatArgs})" if @isSuper - unless @isNew - base = new Value @variable - if (name = base.properties.pop()) and base.isComplex() - ref = o.scope.freeVariable 'this' - fun = "(#{ref} = #{ base.compile o, LEVEL_LIST })#{ name.compile o }" + if @isNew + idt = @tab + TAB + return """ + (function(func, args, ctor) { + #{idt}ctor.prototype = func.prototype; + #{idt}var child = new ctor, result = func.apply(child, args); + #{idt}return typeof result === "object" ? result : child; + #{@tab}})(#{ @variable.compile o, LEVEL_LIST }, #{splatArgs}, function() {}) + """ + base = new Value @variable + if (name = base.properties.pop()) and base.isComplex() + ref = o.scope.temporary 'ref' + fun = "(#{ref} = #{ base.compile o, LEVEL_LIST })#{ name.compile o }" + else + fun = base.compile o, LEVEL_ACCESS + if name + ref = fun + fun += name.compile o else - fun = ref = base.compile o, LEVEL_ACCESS - fun += name.compile o if name - return "#{fun}.apply(#{ref}, #{splatArgs})" - idt = @tab + TAB - """ - (function(func, args, ctor) { - #{idt}ctor.prototype = func.prototype; - #{idt}var child = new ctor, result = func.apply(child, args); - #{idt}return typeof result === "object" ? result : child; - #{@tab}})(#{ @variable.compile o, LEVEL_LIST }, #{splatArgs}, function() {}) - """ + ref = 'null' + "#{fun}.apply(#{ref}, #{splatArgs})" #### Extends