diff --git a/lib/6to5/generation/buffer.js b/lib/6to5/generation/buffer.js index e40d4787f7..1ba135089f 100644 --- a/lib/6to5/generation/buffer.js +++ b/lib/6to5/generation/buffer.js @@ -61,7 +61,7 @@ Buffer.prototype.space = function () { Buffer.prototype.removeLast = function (cha) { if (!this.isLast(cha)) return; - this.buf = this.buf.slice(0, -1); + this.buf = this.buf.substr(0, this.buf.length - 1); this.position.unshift(cha); }; @@ -114,13 +114,14 @@ Buffer.prototype._push = function (str) { }; Buffer.prototype.endsWith = function (str) { - return this.buf.slice(-str.length) === str; + var d = this.buf.length - str.length; + return d >= 0 && this.buf.lastIndexOf(str) === d; }; Buffer.prototype.isLast = function (cha, trimRight) { var buf = this.buf; if (trimRight) buf = util.trimRight(buf); - var last = _.last(buf); + var last = buf[buf.length - 1]; if (_.isArray(cha)) { return _.contains(cha, last); diff --git a/lib/6to5/generation/node/index.js b/lib/6to5/generation/node/index.js index 8828ba9030..42daaafaec 100644 --- a/lib/6to5/generation/node/index.js +++ b/lib/6to5/generation/node/index.js @@ -6,14 +6,19 @@ var t = require("../../types"); var _ = require("lodash"); var find = function (obj, node, parent) { + if (!obj) return; var result; - _.each(obj, function (fn, type) { + var types = Object.keys(obj); + for (var i = 0; i < types.length; i++) { + var type = types[i]; + if (t["is" + type](node)) { + var fn = obj[type]; result = fn(node, parent); - if (result != null) return false; + if (result != null) break; } - }); + } return result; }; @@ -99,7 +104,13 @@ _.each(Node.prototype, function (fn, key) { Node[key] = function (node, parent) { var n = new Node(node, parent); - var args = _.toArray(arguments).slice(2); + // Avoid leaking arguments to prevent deoptimization + var skipCount = 2; + var args = new Array(arguments.length - skipCount); + for (var i = 0; i < args.length; i++) { + args[i] = arguments[i + 2]; + } + return n[key].apply(n, args); }; });