1
0
Fork 0
mirror of https://github.com/jashkenas/coffeescript.git synced 2022-11-09 12:23:24 -05:00

making use of slicing syntax

This commit is contained in:
Michael Ficarra 2011-12-24 06:04:05 -05:00
parent 21a499c726
commit e2a205ab22
9 changed files with 21 additions and 21 deletions

View file

@ -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 = [];

View file

@ -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;
}

View file

@ -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

View file

@ -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))

View file

@ -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

View file

@ -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'

View file

@ -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

View file

@ -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

View file

@ -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]