From 1d4d7e96fa58a2119798ccd131ac951019335ef5 Mon Sep 17 00:00:00 2001 From: satyr Date: Wed, 13 Oct 2010 05:47:45 +0900 Subject: [PATCH] quit using sp?licing ranges --- lib/cake.js | 2 +- lib/command.js | 9 ++++----- lib/optparse.js | 2 +- src/cake.coffee | 2 +- src/command.coffee | 9 ++++----- src/grammar.coffee | 2 +- src/lexer.coffee | 8 ++++---- src/optparse.coffee | 2 +- 8 files changed, 17 insertions(+), 19 deletions(-) diff --git a/lib/cake.js b/lib/cake.js index 7d91f000..770a648b 100755 --- a/lib/cake.js +++ b/lib/cake.js @@ -37,7 +37,7 @@ if (!exists) { throw new Error("Cakefile not found in " + (process.cwd())); } - args = process.argv.slice(2, process.argv.length); + args = process.argv.slice(2); CoffeeScript.run(fs.readFileSync('Cakefile').toString(), { fileName: 'Cakefile' }); diff --git a/lib/command.js b/lib/command.js index 85e35f3d..10b60fac 100644 --- a/lib/command.js +++ b/lib/command.js @@ -38,12 +38,11 @@ separator = sources.indexOf('--'); flags = []; if (separator >= 0) { - flags = sources.slice((separator + 1), sources.length); - sources = sources.slice(0, separator); + flags = sources.splice(separator + 1); + sources.pop(); } if (opts.run) { - flags = sources.slice(1, sources.length + 1).concat(flags); - sources = [sources[0]]; + flags = sources.splice(1).concat(flags); } process.ARGV = (process.argv = flags); return compileScripts(); @@ -204,7 +203,7 @@ parseOptions = function() { var o; optionParser = new optparse.OptionParser(SWITCHES, BANNER); - o = (opts = optionParser.parse(process.argv.slice(2, process.argv.length))); + o = (opts = optionParser.parse(process.argv.slice(2))); o.compile || (o.compile = !!o.output); o.run = !(o.compile || o.print || o.lint); o.print = !!(o.print || (o.eval || o.stdio && o.compile)); diff --git a/lib/optparse.js b/lib/optparse.js index c28fb5d5..4a9ae283 100755 --- a/lib/optparse.js +++ b/lib/optparse.js @@ -32,7 +32,7 @@ throw new Error("unrecognized option: " + arg); } if (!isOption) { - options.arguments = args.slice(i, args.length); + options.arguments = args.slice(i); break; } } diff --git a/src/cake.coffee b/src/cake.coffee index fd093658..61567bc6 100644 --- a/src/cake.coffee +++ b/src/cake.coffee @@ -46,7 +46,7 @@ helpers.extend global, exports.run = -> path.exists 'Cakefile', (exists) -> throw new Error("Cakefile not found in #{process.cwd()}") unless exists - args = process.argv[2...process.argv.length] + args = process.argv.slice 2 CoffeeScript.run fs.readFileSync('Cakefile').toString(), fileName: 'Cakefile' oparse = new optparse.OptionParser switches return printTasks() unless args.length diff --git a/src/command.coffee b/src/command.coffee index a7f8b89b..58196baf 100644 --- a/src/command.coffee +++ b/src/command.coffee @@ -62,11 +62,10 @@ exports.run = -> separator = sources.indexOf '--' flags = [] if separator >= 0 - flags = sources[(separator + 1)...sources.length] - sources = sources[0...separator] + flags = sources.splice separator + 1 + sources.pop() if opts.run - flags = sources[1..sources.length].concat flags - sources = [sources[0]] + flags = sources.splice(1).concat flags process.ARGV = process.argv = flags compileScripts() @@ -176,7 +175,7 @@ printTokens = (tokens) -> # `process.argv` that are specified in `SWITCHES`. parseOptions = -> optionParser = new optparse.OptionParser SWITCHES, BANNER - o = opts = optionParser.parse(process.argv[2...process.argv.length]) + o = opts = optionParser.parse process.argv.slice 2 o.compile or= !!o.output o.run = not (o.compile or o.print or o.lint) o.print = !! (o.print or (o.eval or o.stdio and o.compile)) diff --git a/src/grammar.coffee b/src/grammar.coffee index 603f14fe..b04ff452 100644 --- a/src/grammar.coffee +++ b/src/grammar.coffee @@ -549,7 +549,7 @@ grammar = if $2 is '!in' new Op '!', new In $1, $3 else - new Op '!', new Parens new Op $2[1..], $1, $3 + new Op '!', new Parens new Op $2.slice(1), $1, $3 else if $2 is 'in' then new In $1, $3 else new Op $2, $1, $3 ] diff --git a/src/lexer.coffee b/src/lexer.coffee index 4f89ff85..1c30123f 100644 --- a/src/lexer.coffee +++ b/src/lexer.coffee @@ -47,7 +47,7 @@ exports.Lexer = class Lexer # At every position, run through this list of attempted matches, # short-circuiting if any of them succeed. Their order determines precedence: # `@literalToken` is the fallback catch-all. - while (@chunk = code[@i..]) + while @chunk = code.slice @i @identifierToken() or @commentToken() or @whitespaceToken() or @@ -445,9 +445,9 @@ exports.Lexer = class Lexer i += 1 continue unless letter is '#' and str.charAt(i+1) is '{' and - (expr = @balancedString str[i+1..], [['{', '}']]) + (expr = @balancedString str.slice(i+1), [['{', '}']]) continue - tokens.push ['TO_BE_STRING', str[pi...i]] if pi < i + tokens.push ['TO_BE_STRING', str.slice(pi, i)] if pi < i inner = expr.slice(1, -1).replace(LEADING_SPACES, '').replace(TRAILING_SPACES, '') if inner.length nested = new Lexer().tokenize inner, line: @line, rewrite: off @@ -458,7 +458,7 @@ exports.Lexer = class Lexer tokens.push ['TOKENS', nested] i += expr.length pi = i + 1 - tokens.push ['TO_BE_STRING', str[pi..]] if i > pi < str.length + tokens.push ['TO_BE_STRING', str.slice pi] if i > pi < str.length return tokens if regex return @token 'STRING', '""' unless tokens.length tokens.unshift ['', ''] unless tokens[0][0] is 'TO_BE_STRING' diff --git a/src/optparse.coffee b/src/optparse.coffee index 7a0aa628..5a6c9ee7 100644 --- a/src/optparse.coffee +++ b/src/optparse.coffee @@ -36,7 +36,7 @@ exports.OptionParser = class OptionParser break throw new Error "unrecognized option: #{arg}" if isOption and not matchedRule if not isOption - options.arguments = args[i...args.length] + options.arguments = args.slice i break options