From e2a205ab22a39ac9d2efb5ec2920e503d7d8f451 Mon Sep 17 00:00:00 2001 From: Michael Ficarra Date: Sat, 24 Dec 2011 06:04:05 -0500 Subject: [PATCH] making use of slicing syntax --- lib/coffee-script/command.js | 2 +- lib/coffee-script/lexer.js | 2 +- src/cake.coffee | 2 +- src/command.coffee | 6 +++--- src/grammar.coffee | 2 +- src/lexer.coffee | 18 +++++++++--------- src/nodes.coffee | 6 +++--- src/optparse.coffee | 2 +- src/repl.coffee | 2 +- 9 files changed, 21 insertions(+), 21 deletions(-) diff --git a/lib/coffee-script/command.js b/lib/coffee-script/command.js index ad789b2e..34388099 100644 --- a/lib/coffee-script/command.js +++ b/lib/coffee-script/command.js @@ -282,7 +282,7 @@ unwatchDir = function(source, base) { var file, prevSources, toRemove, _i, _len; - prevSources = sources.slice(); + prevSources = sources.slice(0); toRemove = (function() { var _i, _len, _results; _results = []; diff --git a/lib/coffee-script/lexer.js b/lib/coffee-script/lexer.js index 3d79665d..950b1a31 100644 --- a/lib/coffee-script/lexer.js +++ b/lib/coffee-script/lexer.js @@ -465,7 +465,7 @@ continue; case end: stack.pop(); - if (!stack.length) return str.slice(0, i + 1); + if (!stack.length) return str.slice(0, i + 1 || 9e9); end = stack[stack.length - 1]; continue; } diff --git a/src/cake.coffee b/src/cake.coffee index fe4deae1..1c621e4d 100644 --- a/src/cake.coffee +++ b/src/cake.coffee @@ -46,7 +46,7 @@ helpers.extend global, exports.run = -> global.__originalDirname = fs.realpathSync '.' process.chdir cakefileDirectory __originalDirname - args = process.argv.slice 2 + args = process.argv[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 7b17e118..5a56217e 100644 --- a/src/command.coffee +++ b/src/command.coffee @@ -71,7 +71,7 @@ exports.run = -> return require './repl' unless sources.length if opts.run opts.literals = sources.splice(1).concat opts.literals - process.argv = process.argv.slice(0, 2).concat opts.literals + process.argv = process.argv[0..1].concat opts.literals process.argv[0] = 'coffee' process.execPath = require.main.filename for source in sources @@ -231,7 +231,7 @@ watchDir = (source, base) -> throw e unless e.code is 'ENOENT' unwatchDir = (source, base) -> - prevSources = sources.slice() + prevSources = sources[..] toRemove = (file for file in sources when file.indexOf(source) >= 0) removeSource file, base, yes for file in toRemove return unless sources.some (s, i) -> prevSources[i] isnt s @@ -304,7 +304,7 @@ printTokens = (tokens) -> # `process.argv` that are specified in `SWITCHES`. parseOptions = -> optionParser = new optparse.OptionParser SWITCHES, BANNER - o = opts = optionParser.parse process.argv.slice 2 + o = opts = optionParser.parse process.argv[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 95706dd7..91ab43c5 100644 --- a/src/grammar.coffee +++ b/src/grammar.coffee @@ -531,7 +531,7 @@ grammar = o 'Expression LOGIC Expression', -> new Op $2, $1, $3 o 'Expression RELATION Expression', -> if $2.charAt(0) is '!' - new Op($2.slice(1), $1, $3).invert() + new Op($2[1..], $1, $3).invert() else new Op $2, $1, $3 diff --git a/src/lexer.coffee b/src/lexer.coffee index b504a618..bedbb831 100644 --- a/src/lexer.coffee +++ b/src/lexer.coffee @@ -48,7 +48,7 @@ exports.Lexer = class Lexer # short-circuiting if any of them succeed. Their order determines precedence: # `@literalToken` is the fallback catch-all. i = 0 - while @chunk = code.slice i + while @chunk = code[i..] i += @identifierToken() or @commentToken() or @whitespaceToken() or @@ -149,7 +149,7 @@ exports.Lexer = class Lexer when '"' return 0 unless string = @balancedString @chunk, '"' if 0 < string.indexOf '#{', 1 - @interpolateString string.slice 1, -1 + @interpolateString string[1...-1] else @token 'STRING', @escapeLines string else @@ -185,7 +185,7 @@ exports.Lexer = class Lexer # Matches JavaScript interpolated directly into the source via backticks. jsToken: -> return 0 unless @chunk.charAt(0) is '`' and match = JSTOKEN.exec @chunk - @token 'JS', (script = match[0]).slice 1, -1 + @token 'JS', (script = match[0])[1...-1] script.length # Matches regular expression literals. Lexing regular expressions is difficult @@ -420,12 +420,12 @@ exports.Lexer = class Lexer when end stack.pop() unless stack.length - return str.slice 0, i + 1 + return str[0..i] end = stack[stack.length - 1] continue if end is '}' and letter in ['"', "'"] stack.push end = letter - else if end is '}' and letter is '/' and match = (HEREGEX.exec(str.slice i) or REGEX.exec(str.slice i)) + else if end is '}' and letter is '/' and match = (HEREGEX.exec(str[i..]) or REGEX.exec(str[i..])) continueCount += match[0].length - 1 else if end is '}' and letter is '{' stack.push end = '}' @@ -452,10 +452,10 @@ exports.Lexer = class Lexer i += 1 continue unless letter is '#' and str.charAt(i+1) is '{' and - (expr = @balancedString str.slice(i + 1), '}') + (expr = @balancedString str[i + 1..], '}') continue - tokens.push ['NEOSTRING', str.slice(pi, i)] if pi < i - inner = expr.slice(1, -1) + tokens.push ['NEOSTRING', str[pi...i]] if pi < i + inner = expr[1...-1] if inner.length nested = new Lexer().tokenize inner, line: @line, rewrite: off nested.pop() @@ -467,7 +467,7 @@ exports.Lexer = class Lexer tokens.push ['TOKENS', nested] i += expr.length pi = i + 1 - tokens.push ['NEOSTRING', str.slice pi] if i > pi < str.length + tokens.push ['NEOSTRING', str[pi..]] if i > pi < str.length return tokens if regex return @token 'STRING', '""' unless tokens.length tokens.unshift ['', ''] unless tokens[0][0] is 'NEOSTRING' diff --git a/src/nodes.coffee b/src/nodes.coffee index 8bf04386..3ab6c2a7 100644 --- a/src/nodes.coffee +++ b/src/nodes.coffee @@ -874,7 +874,7 @@ exports.Class = class Class extends Base # Merge the properties from a top-level object as prototypal properties # on the class. addProperties: (node, name, o) -> - props = node.base.properties[0..] + props = node.base.properties[..] exprs = while assign = props.shift() if assign instanceof Assign base = assign.variable.base @@ -1086,7 +1086,7 @@ exports.Assign = class Assign extends Base compileConditional: (o) -> [left, rite] = @variable.cacheReference o if "?" in @context then o.isExistentialEquals = true - new Op(@context[0...-1], left, new Assign(rite, @value, '=') ).compile o + new Op(@context[...-1], left, new Assign(rite, @value, '=') ).compile o # Compile the assignment from an array splice literal, using JavaScript's # `Array#splice` method. @@ -1244,7 +1244,7 @@ exports.Splat = class Splat extends Base then "#{ utility 'slice' }.call(#{code})" else "[#{code}]" return args[0] + ".concat(#{ args[1..].join ', ' })" if index is 0 - base = (node.compile o, LEVEL_LIST for node in list[0...index]) + base = (node.compile o, LEVEL_LIST for node in list[...index]) "[#{ base.join ', ' }].concat(#{ args.join ', ' })" #### While diff --git a/src/optparse.coffee b/src/optparse.coffee index 94bfb94a..d03ae356 100644 --- a/src/optparse.coffee +++ b/src/optparse.coffee @@ -100,7 +100,7 @@ buildRule = (shortFlag, longFlag, description, options = {}) -> # Normalize arguments by expanding merged flags into multiple flags. This allows # you to have `-wl` be the same as `--watch --lint`. normalizeArguments = (args) -> - args = args.slice 0 + args = args[..] result = [] for arg in args if match = arg.match MULTI_FLAG diff --git a/src/repl.coffee b/src/repl.coffee index cf551431..f8de6ce0 100644 --- a/src/repl.coffee +++ b/src/repl.coffee @@ -85,7 +85,7 @@ completeVariable = (text) -> free = (text.match SIMPLEVAR)?[1] if free? vars = Script.runInThisContext 'Object.getOwnPropertyNames(this)' - keywords = (r for r in CoffeeScript.RESERVED when r[0..1] isnt '__') + keywords = (r for r in CoffeeScript.RESERVED when r[..1] isnt '__') possibilities = vars.concat keywords completions = getCompletions free, possibilities [completions, free]