diff --git a/lib/cake.js b/lib/cake.js index a0b30b63..91ec5270 100755 --- a/lib/cake.js +++ b/lib/cake.js @@ -1,8 +1,6 @@ (function(){ var CoffeeScript, fs, helpers, no_such_task, oparse, options, optparse, path, print_tasks, switches, tasks; - var __slice = function(array, from, to, exclusive) { - return array.slice.apply(array, __range(array, from, to, exclusive)); - }, __range = function(array, from, to, exclusive) { + var __range = function(array, from, to, exclusive) { return [ (from < 0 ? from + array.length : from || 0), (to < 0 ? to + array.length : to || array.length) + (exclusive ? 0 : 1) @@ -60,7 +58,7 @@ if (!(exists)) { throw new Error("Cakefile not found in " + (process.cwd())); } - args = __slice(process.argv, 2, process.argv.length, true); + args = process.argv.slice.apply(process.argv, __range(process.argv, 2, process.argv.length, true)); CoffeeScript.run(fs.readFileSync('Cakefile'), { source: 'Cakefile' }); diff --git a/lib/command.js b/lib/command.js index 9e9015e4..5967cea7 100644 --- a/lib/command.js +++ b/lib/command.js @@ -1,8 +1,6 @@ (function(){ var BANNER, CoffeeScript, SWITCHES, compile_options, compile_script, compile_scripts, compile_stdio, fs, lint, option_parser, options, optparse, parse_options, path, print_tokens, sources, usage, version, watch_scripts, write_js; - var __slice = function(array, from, to, exclusive) { - return array.slice.apply(array, __range(array, from, to, exclusive)); - }, __range = function(array, from, to, exclusive) { + var __range = function(array, from, to, exclusive) { return [ (from < 0 ? from + array.length : from || 0), (to < 0 ? to + array.length : to || array.length) + (exclusive ? 0 : 1) @@ -53,8 +51,8 @@ separator = sources.indexOf('--'); flags = []; if (separator >= 0) { - flags = __slice(sources, (separator + 1), sources.length, true); - sources = __slice(sources, 0, separator, true); + flags = sources.slice.apply(sources, __range(sources, (separator + 1), sources.length, true)); + sources = sources.slice.apply(sources, __range(sources, 0, separator, true)); } process.ARGV = (process.argv = flags); if (options.watch) { @@ -210,7 +208,7 @@ o = (options = option_parser.parse(process.argv)); options.run = !(o.compile || o.print || o.lint); options.print = !!(o.print || (o.eval || o.stdio && o.compile)); - sources = __slice(options.arguments, 2, options.arguments.length, true); + sources = options.arguments.slice.apply(options.arguments, __range(options.arguments, 2, options.arguments.length, true)); return sources; }; // The compile-time options to pass to the CoffeeScript compiler. diff --git a/lib/nodes.js b/lib/nodes.js index b05fc481..c2d7d58a 100644 --- a/lib/nodes.js +++ b/lib/nodes.js @@ -6,8 +6,6 @@ child.__superClass__ = parent.prototype; child.prototype = new ctor(); child.prototype.constructor = child; - }, __slice = function(array, from, to, exclusive) { - return array.slice.apply(array, __range(array, from, to, exclusive)); }, __range = function(array, from, to, exclusive) { return [ (from < 0 ? from + array.length : from || 0), @@ -440,7 +438,7 @@ op = del(o, 'operation'); splice = del(o, 'splice'); replace = del(o, 'replace'); - props = only ? __slice(this.properties, 0, this.properties.length - 1, true) : this.properties; + props = only ? this.properties.slice.apply(this.properties, __range(this.properties, 0, this.properties.length - 1, true)) : this.properties; baseline = this.base.compile(o); if (this.base instanceof ObjectNode && this.has_properties()) { baseline = "(" + baseline + ")"; @@ -749,13 +747,13 @@ return call.compile(o); }; SliceNode.prototype.compile_slice = function compile_slice(o) { - var _a, _b, array, call, exclusive, from, ref, to; + var _a, _b, array, call, exclusive, from, rng, to; array = del(o, 'array'); from = (typeof (_a = this.range.from) !== "undefined" && _a !== null) ? this.range.from : literal('null'); to = (typeof (_b = this.range.to) !== "undefined" && _b !== null) ? this.range.to : literal('null'); exclusive = this.range.exclusive ? 'true' : 'false'; - ref = new ValueNode(literal(o.scope.utility('slice'))); - call = new CallNode(ref, [literal(array), from, to, literal(exclusive)]); + rng = new CallNode(new ValueNode(literal(o.scope.utility('range'))), [literal(array), from, to, literal(exclusive)]); + call = new CallNode(new ValueNode(literal(array), [literal('.slice.apply')]), [literal(array), rng]); return call.compile(o); }; return SliceNode; diff --git a/lib/utilities.js b/lib/utilities.js index 9a2b82fd..883afc80 100644 --- a/lib/utilities.js +++ b/lib/utilities.js @@ -12,15 +12,13 @@ return "" + (utilities.key(key)) + " = " + (utilities.functions[key].replace(/\n/g, "\n" + tab) || 'undefined'); }; utilities.dependencies = { - slice: ['range'], - splice: ['range'], - bind: ['arraySlice'] + bind: ['arraySlice'], + splice: ['range'] }; utilities.functions = { extend: "function(child, parent) {\n var ctor = function(){ };\n ctor.prototype = parent.prototype;\n child.__superClass__ = parent.prototype;\n child.prototype = new ctor();\n child.prototype.constructor = child;\n}", bind: "function(func, obj, args) {\n obj = obj || {};\n return (typeof args !== 'undefined' && args !== null) ? function() {\n return func.apply(obj, args.concat(" + (utilities.key('arraySlice')) + ".call(arguments, 0)));\n } : function() {\n return func.apply(obj, arguments);\n };\n}", range: "function(array, from, to, exclusive) {\n return [\n (from < 0 ? from + array.length : from || 0),\n (to < 0 ? to + array.length : to || array.length) + (exclusive ? 0 : 1)\n ];\n}", - slice: "function(array, from, to, exclusive) {\n return array.slice.apply(array, " + (utilities.key('range')) + "(array, from, to, exclusive));\n}", splice: "function(array, from, to, exclusive, replace) {\n return array.splice.apply(array, [(_a = " + (utilities.key('range')) + "(array, from, to, exclusive))[0], \n _a[1] - _a[0]].concat(replace));\n}", hasProp: 'Object.prototype.hasOwnProperty', arraySlice: 'Array.prototype.slice' diff --git a/src/nodes.coffee b/src/nodes.coffee index 4a4666c9..5ce6447c 100644 --- a/src/nodes.coffee +++ b/src/nodes.coffee @@ -555,8 +555,8 @@ exports.SliceNode: class SliceNode extends BaseNode from: if @range.from? then @range.from else literal('null') to: if @range.to? then @range.to else literal('null') exclusive: if @range.exclusive then 'true' else 'false' - ref: new ValueNode literal(o.scope.utility('slice')) - call: new CallNode ref, [literal(array), from, to, literal(exclusive)] + rng: new CallNode new ValueNode(literal(o.scope.utility('range'))), [literal(array), from, to, literal(exclusive)] + call: new CallNode new ValueNode(literal(array), [literal('.slice.apply')]), [literal(array), rng] call.compile(o) #### ObjectNode diff --git a/src/utilities.coffee b/src/utilities.coffee index c562fc29..aafb839e 100644 --- a/src/utilities.coffee +++ b/src/utilities.coffee @@ -8,9 +8,8 @@ exports.utilities: class utilities "${utilities.key(key)} = ${utilities.functions[key].replace(/\n/g, "\n$tab") or 'undefined'}" @dependencies: { - slice: ['range'] - splice: ['range'] bind: ['arraySlice'] + splice: ['range'] } @functions: { @@ -41,11 +40,6 @@ exports.utilities: class utilities ]; } """ - slice: """ - function(array, from, to, exclusive) { - return array.slice.apply(array, ${utilities.key('range')}(array, from, to, exclusive)); - } - """ splice: """ function(array, from, to, exclusive, replace) { return array.splice.apply(array, [(_a = ${utilities.key('range')}(array, from, to, exclusive))[0],