making use of slicing syntax
This commit is contained in:
parent
21a499c726
commit
e2a205ab22
|
@ -282,7 +282,7 @@
|
||||||
|
|
||||||
unwatchDir = function(source, base) {
|
unwatchDir = function(source, base) {
|
||||||
var file, prevSources, toRemove, _i, _len;
|
var file, prevSources, toRemove, _i, _len;
|
||||||
prevSources = sources.slice();
|
prevSources = sources.slice(0);
|
||||||
toRemove = (function() {
|
toRemove = (function() {
|
||||||
var _i, _len, _results;
|
var _i, _len, _results;
|
||||||
_results = [];
|
_results = [];
|
||||||
|
|
|
@ -465,7 +465,7 @@
|
||||||
continue;
|
continue;
|
||||||
case end:
|
case end:
|
||||||
stack.pop();
|
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];
|
end = stack[stack.length - 1];
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,7 +46,7 @@ helpers.extend global,
|
||||||
exports.run = ->
|
exports.run = ->
|
||||||
global.__originalDirname = fs.realpathSync '.'
|
global.__originalDirname = fs.realpathSync '.'
|
||||||
process.chdir cakefileDirectory __originalDirname
|
process.chdir cakefileDirectory __originalDirname
|
||||||
args = process.argv.slice 2
|
args = process.argv[2..]
|
||||||
CoffeeScript.run fs.readFileSync('Cakefile').toString(), filename: 'Cakefile'
|
CoffeeScript.run fs.readFileSync('Cakefile').toString(), filename: 'Cakefile'
|
||||||
oparse = new optparse.OptionParser switches
|
oparse = new optparse.OptionParser switches
|
||||||
return printTasks() unless args.length
|
return printTasks() unless args.length
|
||||||
|
|
|
@ -71,7 +71,7 @@ exports.run = ->
|
||||||
return require './repl' unless sources.length
|
return require './repl' unless sources.length
|
||||||
if opts.run
|
if opts.run
|
||||||
opts.literals = sources.splice(1).concat opts.literals
|
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.argv[0] = 'coffee'
|
||||||
process.execPath = require.main.filename
|
process.execPath = require.main.filename
|
||||||
for source in sources
|
for source in sources
|
||||||
|
@ -231,7 +231,7 @@ watchDir = (source, base) ->
|
||||||
throw e unless e.code is 'ENOENT'
|
throw e unless e.code is 'ENOENT'
|
||||||
|
|
||||||
unwatchDir = (source, base) ->
|
unwatchDir = (source, base) ->
|
||||||
prevSources = sources.slice()
|
prevSources = sources[..]
|
||||||
toRemove = (file for file in sources when file.indexOf(source) >= 0)
|
toRemove = (file for file in sources when file.indexOf(source) >= 0)
|
||||||
removeSource file, base, yes for file in toRemove
|
removeSource file, base, yes for file in toRemove
|
||||||
return unless sources.some (s, i) -> prevSources[i] isnt s
|
return unless sources.some (s, i) -> prevSources[i] isnt s
|
||||||
|
@ -304,7 +304,7 @@ printTokens = (tokens) ->
|
||||||
# `process.argv` that are specified in `SWITCHES`.
|
# `process.argv` that are specified in `SWITCHES`.
|
||||||
parseOptions = ->
|
parseOptions = ->
|
||||||
optionParser = new optparse.OptionParser SWITCHES, BANNER
|
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.compile or= !!o.output
|
||||||
o.run = not (o.compile or o.print or o.lint)
|
o.run = not (o.compile or o.print or o.lint)
|
||||||
o.print = !! (o.print or (o.eval or o.stdio and o.compile))
|
o.print = !! (o.print or (o.eval or o.stdio and o.compile))
|
||||||
|
|
|
@ -531,7 +531,7 @@ grammar =
|
||||||
o 'Expression LOGIC Expression', -> new Op $2, $1, $3
|
o 'Expression LOGIC Expression', -> new Op $2, $1, $3
|
||||||
o 'Expression RELATION Expression', ->
|
o 'Expression RELATION Expression', ->
|
||||||
if $2.charAt(0) is '!'
|
if $2.charAt(0) is '!'
|
||||||
new Op($2.slice(1), $1, $3).invert()
|
new Op($2[1..], $1, $3).invert()
|
||||||
else
|
else
|
||||||
new Op $2, $1, $3
|
new Op $2, $1, $3
|
||||||
|
|
||||||
|
|
|
@ -48,7 +48,7 @@ exports.Lexer = class Lexer
|
||||||
# short-circuiting if any of them succeed. Their order determines precedence:
|
# short-circuiting if any of them succeed. Their order determines precedence:
|
||||||
# `@literalToken` is the fallback catch-all.
|
# `@literalToken` is the fallback catch-all.
|
||||||
i = 0
|
i = 0
|
||||||
while @chunk = code.slice i
|
while @chunk = code[i..]
|
||||||
i += @identifierToken() or
|
i += @identifierToken() or
|
||||||
@commentToken() or
|
@commentToken() or
|
||||||
@whitespaceToken() or
|
@whitespaceToken() or
|
||||||
|
@ -149,7 +149,7 @@ exports.Lexer = class Lexer
|
||||||
when '"'
|
when '"'
|
||||||
return 0 unless string = @balancedString @chunk, '"'
|
return 0 unless string = @balancedString @chunk, '"'
|
||||||
if 0 < string.indexOf '#{', 1
|
if 0 < string.indexOf '#{', 1
|
||||||
@interpolateString string.slice 1, -1
|
@interpolateString string[1...-1]
|
||||||
else
|
else
|
||||||
@token 'STRING', @escapeLines string
|
@token 'STRING', @escapeLines string
|
||||||
else
|
else
|
||||||
|
@ -185,7 +185,7 @@ exports.Lexer = class Lexer
|
||||||
# Matches JavaScript interpolated directly into the source via backticks.
|
# Matches JavaScript interpolated directly into the source via backticks.
|
||||||
jsToken: ->
|
jsToken: ->
|
||||||
return 0 unless @chunk.charAt(0) is '`' and match = JSTOKEN.exec @chunk
|
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
|
script.length
|
||||||
|
|
||||||
# Matches regular expression literals. Lexing regular expressions is difficult
|
# Matches regular expression literals. Lexing regular expressions is difficult
|
||||||
|
@ -420,12 +420,12 @@ exports.Lexer = class Lexer
|
||||||
when end
|
when end
|
||||||
stack.pop()
|
stack.pop()
|
||||||
unless stack.length
|
unless stack.length
|
||||||
return str.slice 0, i + 1
|
return str[0..i]
|
||||||
end = stack[stack.length - 1]
|
end = stack[stack.length - 1]
|
||||||
continue
|
continue
|
||||||
if end is '}' and letter in ['"', "'"]
|
if end is '}' and letter in ['"', "'"]
|
||||||
stack.push end = letter
|
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
|
continueCount += match[0].length - 1
|
||||||
else if end is '}' and letter is '{'
|
else if end is '}' and letter is '{'
|
||||||
stack.push end = '}'
|
stack.push end = '}'
|
||||||
|
@ -452,10 +452,10 @@ exports.Lexer = class Lexer
|
||||||
i += 1
|
i += 1
|
||||||
continue
|
continue
|
||||||
unless letter is '#' and str.charAt(i+1) is '{' and
|
unless letter is '#' and str.charAt(i+1) is '{' and
|
||||||
(expr = @balancedString str.slice(i + 1), '}')
|
(expr = @balancedString str[i + 1..], '}')
|
||||||
continue
|
continue
|
||||||
tokens.push ['NEOSTRING', str.slice(pi, i)] if pi < i
|
tokens.push ['NEOSTRING', str[pi...i]] if pi < i
|
||||||
inner = expr.slice(1, -1)
|
inner = expr[1...-1]
|
||||||
if inner.length
|
if inner.length
|
||||||
nested = new Lexer().tokenize inner, line: @line, rewrite: off
|
nested = new Lexer().tokenize inner, line: @line, rewrite: off
|
||||||
nested.pop()
|
nested.pop()
|
||||||
|
@ -467,7 +467,7 @@ exports.Lexer = class Lexer
|
||||||
tokens.push ['TOKENS', nested]
|
tokens.push ['TOKENS', nested]
|
||||||
i += expr.length
|
i += expr.length
|
||||||
pi = i + 1
|
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 tokens if regex
|
||||||
return @token 'STRING', '""' unless tokens.length
|
return @token 'STRING', '""' unless tokens.length
|
||||||
tokens.unshift ['', ''] unless tokens[0][0] is 'NEOSTRING'
|
tokens.unshift ['', ''] unless tokens[0][0] is 'NEOSTRING'
|
||||||
|
|
|
@ -874,7 +874,7 @@ exports.Class = class Class extends Base
|
||||||
# Merge the properties from a top-level object as prototypal properties
|
# Merge the properties from a top-level object as prototypal properties
|
||||||
# on the class.
|
# on the class.
|
||||||
addProperties: (node, name, o) ->
|
addProperties: (node, name, o) ->
|
||||||
props = node.base.properties[0..]
|
props = node.base.properties[..]
|
||||||
exprs = while assign = props.shift()
|
exprs = while assign = props.shift()
|
||||||
if assign instanceof Assign
|
if assign instanceof Assign
|
||||||
base = assign.variable.base
|
base = assign.variable.base
|
||||||
|
@ -1086,7 +1086,7 @@ exports.Assign = class Assign extends Base
|
||||||
compileConditional: (o) ->
|
compileConditional: (o) ->
|
||||||
[left, rite] = @variable.cacheReference o
|
[left, rite] = @variable.cacheReference o
|
||||||
if "?" in @context then o.isExistentialEquals = true
|
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
|
# Compile the assignment from an array splice literal, using JavaScript's
|
||||||
# `Array#splice` method.
|
# `Array#splice` method.
|
||||||
|
@ -1244,7 +1244,7 @@ exports.Splat = class Splat extends Base
|
||||||
then "#{ utility 'slice' }.call(#{code})"
|
then "#{ utility 'slice' }.call(#{code})"
|
||||||
else "[#{code}]"
|
else "[#{code}]"
|
||||||
return args[0] + ".concat(#{ args[1..].join ', ' })" if index is 0
|
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 ', ' })"
|
"[#{ base.join ', ' }].concat(#{ args.join ', ' })"
|
||||||
|
|
||||||
#### While
|
#### While
|
||||||
|
|
|
@ -100,7 +100,7 @@ buildRule = (shortFlag, longFlag, description, options = {}) ->
|
||||||
# Normalize arguments by expanding merged flags into multiple flags. This allows
|
# Normalize arguments by expanding merged flags into multiple flags. This allows
|
||||||
# you to have `-wl` be the same as `--watch --lint`.
|
# you to have `-wl` be the same as `--watch --lint`.
|
||||||
normalizeArguments = (args) ->
|
normalizeArguments = (args) ->
|
||||||
args = args.slice 0
|
args = args[..]
|
||||||
result = []
|
result = []
|
||||||
for arg in args
|
for arg in args
|
||||||
if match = arg.match MULTI_FLAG
|
if match = arg.match MULTI_FLAG
|
||||||
|
|
|
@ -85,7 +85,7 @@ completeVariable = (text) ->
|
||||||
free = (text.match SIMPLEVAR)?[1]
|
free = (text.match SIMPLEVAR)?[1]
|
||||||
if free?
|
if free?
|
||||||
vars = Script.runInThisContext 'Object.getOwnPropertyNames(this)'
|
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
|
possibilities = vars.concat keywords
|
||||||
completions = getCompletions free, possibilities
|
completions = getCompletions free, possibilities
|
||||||
[completions, free]
|
[completions, free]
|
||||||
|
|
Loading…
Reference in New Issue