coffee-script
Advanced tools
Comparing version 1.2.0 to 1.3.0
@@ -0,1 +1,2 @@ | ||
// Generated by CoffeeScript 1.3.0 | ||
(function() { | ||
@@ -8,3 +9,9 @@ var CoffeeScript, runScripts; | ||
CoffeeScript.eval = function(code, options) { | ||
CoffeeScript["eval"] = function(code, options) { | ||
if (options == null) { | ||
options = {}; | ||
} | ||
if (options.bare == null) { | ||
options.bare = true; | ||
} | ||
return eval(CoffeeScript.compile(code, options)); | ||
@@ -14,3 +21,5 @@ }; | ||
CoffeeScript.run = function(code, options) { | ||
if (options == null) options = {}; | ||
if (options == null) { | ||
options = {}; | ||
} | ||
options.bare = true; | ||
@@ -20,3 +29,5 @@ return Function(CoffeeScript.compile(code, options))(); | ||
if (typeof window === "undefined" || window === null) return; | ||
if (typeof window === "undefined" || window === null) { | ||
return; | ||
} | ||
@@ -27,3 +38,5 @@ CoffeeScript.load = function(url, callback) { | ||
xhr.open('GET', url, true); | ||
if ('overrideMimeType' in xhr) xhr.overrideMimeType('text/plain'); | ||
if ('overrideMimeType' in xhr) { | ||
xhr.overrideMimeType('text/plain'); | ||
} | ||
xhr.onreadystatechange = function() { | ||
@@ -37,3 +50,5 @@ var _ref; | ||
} | ||
if (callback) return callback(); | ||
if (callback) { | ||
return callback(); | ||
} | ||
} | ||
@@ -52,3 +67,5 @@ }; | ||
s = scripts[_i]; | ||
if (s.type === 'text/coffeescript') _results.push(s); | ||
if (s.type === 'text/coffeescript') { | ||
_results.push(s); | ||
} | ||
} | ||
@@ -55,0 +72,0 @@ return _results; |
@@ -0,1 +1,2 @@ | ||
// Generated by CoffeeScript 1.3.0 | ||
(function() { | ||
@@ -38,3 +39,5 @@ var CoffeeScript, cakefileDirectory, fatalError, fs, helpers, missingTask, oparse, options, optparse, path, printTasks, switches, tasks; | ||
invoke: function(name) { | ||
if (!tasks[name]) missingTask(name); | ||
if (!tasks[name]) { | ||
missingTask(name); | ||
} | ||
return tasks[name].action(options); | ||
@@ -53,3 +56,5 @@ } | ||
oparse = new optparse.OptionParser(switches); | ||
if (!args.length) return printTasks(); | ||
if (!args.length) { | ||
return printTasks(); | ||
} | ||
try { | ||
@@ -60,3 +65,3 @@ options = oparse.parse(args); | ||
} | ||
_ref = options.arguments; | ||
_ref = options["arguments"]; | ||
_results = []; | ||
@@ -71,4 +76,5 @@ for (_i = 0, _len = _ref.length; _i < _len; _i++) { | ||
printTasks = function() { | ||
var cakefilePath, desc, name, spaces, task; | ||
cakefilePath = path.join(path.relative(__originalDirname, process.cwd()), 'Cakefile'); | ||
var cakefilePath, desc, name, relative, spaces, task; | ||
relative = path.relative || path.resolve; | ||
cakefilePath = path.join(relative(__originalDirname, process.cwd()), 'Cakefile'); | ||
console.log("" + cakefilePath + " defines the following tasks:\n"); | ||
@@ -82,3 +88,5 @@ for (name in tasks) { | ||
} | ||
if (switches.length) return console.log(oparse.help()); | ||
if (switches.length) { | ||
return console.log(oparse.help()); | ||
} | ||
}; | ||
@@ -98,5 +106,9 @@ | ||
var parent; | ||
if (path.existsSync(path.join(dir, 'Cakefile'))) return dir; | ||
if (path.existsSync(path.join(dir, 'Cakefile'))) { | ||
return dir; | ||
} | ||
parent = path.normalize(path.join(dir, '..')); | ||
if (parent !== dir) return cakefileDirectory(parent); | ||
if (parent !== dir) { | ||
return cakefileDirectory(parent); | ||
} | ||
throw new Error("Cakefile not found in " + (process.cwd())); | ||
@@ -103,0 +115,0 @@ }; |
@@ -0,4 +1,5 @@ | ||
// Generated by CoffeeScript 1.3.0 | ||
(function() { | ||
var Lexer, RESERVED, compile, fs, lexer, parser, path, vm, _ref, | ||
__hasProp = Object.prototype.hasOwnProperty; | ||
__hasProp = {}.hasOwnProperty; | ||
@@ -29,3 +30,3 @@ fs = require('fs'); | ||
exports.VERSION = '1.2.0'; | ||
exports.VERSION = '1.3.0'; | ||
@@ -37,7 +38,12 @@ exports.RESERVED = RESERVED; | ||
exports.compile = compile = function(code, options) { | ||
var merge; | ||
if (options == null) options = {}; | ||
var header, js, merge; | ||
if (options == null) { | ||
options = {}; | ||
} | ||
merge = exports.helpers.merge; | ||
try { | ||
return (parser.parse(lexer.tokenize(code))).compile(merge({}, options)); | ||
js = (parser.parse(lexer.tokenize(code))).compile(options); | ||
if (!options.header) { | ||
return js; | ||
} | ||
} catch (err) { | ||
@@ -49,2 +55,4 @@ if (options.filename) { | ||
} | ||
header = "Generated by CoffeeScript " + this.VERSION; | ||
return "// " + header + "\n" + js; | ||
}; | ||
@@ -66,6 +74,9 @@ | ||
var mainModule; | ||
if (options == null) { | ||
options = {}; | ||
} | ||
mainModule = require.main; | ||
mainModule.filename = process.argv[1] = options.filename ? fs.realpathSync(options.filename) : '.'; | ||
mainModule.moduleCache && (mainModule.moduleCache = {}); | ||
mainModule.paths = require('module')._nodeModulePaths(path.dirname(options.filename)); | ||
mainModule.paths = require('module')._nodeModulePaths(path.dirname(fs.realpathSync(options.filename))); | ||
if (path.extname(mainModule.filename) !== '.coffee' || require.extensions) { | ||
@@ -78,6 +89,10 @@ return mainModule._compile(compile(code, options), mainModule.filename); | ||
exports.eval = function(code, options) { | ||
var Module, Script, js, k, o, r, sandbox, v, _i, _len, _module, _ref2, _ref3, _require; | ||
if (options == null) options = {}; | ||
if (!(code = code.trim())) return; | ||
exports["eval"] = function(code, options) { | ||
var Module, Script, js, k, o, r, sandbox, v, _i, _len, _module, _ref1, _ref2, _require; | ||
if (options == null) { | ||
options = {}; | ||
} | ||
if (!(code = code.trim())) { | ||
return; | ||
} | ||
Script = vm.Script; | ||
@@ -90,6 +105,6 @@ if (Script) { | ||
sandbox = Script.createContext(); | ||
_ref2 = options.sandbox; | ||
for (k in _ref2) { | ||
if (!__hasProp.call(_ref2, k)) continue; | ||
v = _ref2[k]; | ||
_ref1 = options.sandbox; | ||
for (k in _ref1) { | ||
if (!__hasProp.call(_ref1, k)) continue; | ||
v = _ref1[k]; | ||
sandbox[k] = v; | ||
@@ -111,6 +126,8 @@ } | ||
_module.filename = sandbox.__filename; | ||
_ref3 = Object.getOwnPropertyNames(require); | ||
for (_i = 0, _len = _ref3.length; _i < _len; _i++) { | ||
r = _ref3[_i]; | ||
if (r !== 'paths') _require[r] = require[r]; | ||
_ref2 = Object.getOwnPropertyNames(require); | ||
for (_i = 0, _len = _ref2.length; _i < _len; _i++) { | ||
r = _ref2[_i]; | ||
if (r !== 'paths') { | ||
_require[r] = require[r]; | ||
} | ||
} | ||
@@ -142,4 +159,4 @@ _require.paths = _module.paths = Module._nodeModulePaths(process.cwd()); | ||
lex: function() { | ||
var tag, _ref2; | ||
_ref2 = this.tokens[this.pos++] || [''], tag = _ref2[0], this.yytext = _ref2[1], this.yylineno = _ref2[2]; | ||
var tag, _ref1; | ||
_ref1 = this.tokens[this.pos++] || [''], tag = _ref1[0], this.yytext = _ref1[1], this.yylineno = _ref1[2]; | ||
return tag; | ||
@@ -146,0 +163,0 @@ }, |
@@ -0,3 +1,4 @@ | ||
// Generated by CoffeeScript 1.3.0 | ||
(function() { | ||
var BANNER, CoffeeScript, EventEmitter, SWITCHES, compileJoin, compileOptions, compilePath, compileScript, compileStdio, exec, forkNode, fs, helpers, joinTimeout, lint, loadRequires, notSources, optionParser, optparse, opts, outputPath, parseOptions, path, printLine, printTokens, printWarn, removeSource, sourceCode, sources, spawn, timeLog, unwatchDir, usage, version, wait, watch, watchDir, watchers, writeJs, _ref; | ||
var BANNER, CoffeeScript, EventEmitter, SWITCHES, compileJoin, compileOptions, compilePath, compileScript, compileStdio, exec, forkNode, fs, helpers, hidden, joinTimeout, lint, loadRequires, notSources, optionParser, optparse, opts, outputPath, parseOptions, path, printLine, printTokens, printWarn, removeSource, sourceCode, sources, spawn, timeLog, unwatchDir, usage, version, wait, watch, watchDir, watchers, writeJs, _ref; | ||
@@ -28,4 +29,8 @@ fs = require('fs'); | ||
BANNER = 'Usage: coffee [options] path/to/script.coffee\n\nIf called without options, `coffee` will run your script.'; | ||
hidden = function(file) { | ||
return /^\.|~$/.test(file); | ||
}; | ||
BANNER = 'Usage: coffee [options] path/to/script.coffee -- [args]\n\nIf called without options, `coffee` will run your script.'; | ||
SWITCHES = [['-b', '--bare', 'compile without a top-level function wrapper'], ['-c', '--compile', 'compile to JavaScript and save as .js files'], ['-e', '--eval', 'pass a string from the command line as input'], ['-h', '--help', 'display this help message'], ['-i', '--interactive', 'run an interactive CoffeeScript REPL'], ['-j', '--join [FILE]', 'concatenate the source CoffeeScript before compiling'], ['-l', '--lint', 'pipe the compiled JavaScript through JavaScript Lint'], ['-n', '--nodes', 'print out the parse tree that the parser produces'], ['--nodejs [ARGS]', 'pass options directly to the "node" binary'], ['-o', '--output [DIR]', 'set the output directory for compiled JavaScript'], ['-p', '--print', 'print out the compiled JavaScript'], ['-r', '--require [FILE*]', 'require a library before executing your script'], ['-s', '--stdio', 'listen for and compile scripts over stdio'], ['-t', '--tokens', 'print out the tokens that the lexer/rewriter produce'], ['-v', '--version', 'display the version number'], ['-w', '--watch', 'watch scripts for changes and rerun commands']]; | ||
@@ -46,17 +51,33 @@ | ||
exports.run = function() { | ||
var source, _i, _len, _results; | ||
var literals, source, _i, _len, _results; | ||
parseOptions(); | ||
if (opts.nodejs) return forkNode(); | ||
if (opts.help) return usage(); | ||
if (opts.version) return version(); | ||
if (opts.require) loadRequires(); | ||
if (opts.interactive) return require('./repl'); | ||
if (opts.nodejs) { | ||
return forkNode(); | ||
} | ||
if (opts.help) { | ||
return usage(); | ||
} | ||
if (opts.version) { | ||
return version(); | ||
} | ||
if (opts.require) { | ||
loadRequires(); | ||
} | ||
if (opts.interactive) { | ||
return require('./repl'); | ||
} | ||
if (opts.watch && !fs.watch) { | ||
printWarn("The --watch feature depends on Node v0.6.0+. You are running " + process.version + "."); | ||
return printWarn("The --watch feature depends on Node v0.6.0+. You are running " + process.version + "."); | ||
} | ||
if (opts.stdio) return compileStdio(); | ||
if (opts.eval) return compileScript(null, sources[0]); | ||
if (!sources.length) return require('./repl'); | ||
if (opts.run) opts.literals = sources.splice(1).concat(opts.literals); | ||
process.argv = process.argv.slice(0, 2).concat(opts.literals); | ||
if (opts.stdio) { | ||
return compileStdio(); | ||
} | ||
if (opts["eval"]) { | ||
return compileScript(null, sources[0]); | ||
} | ||
if (!sources.length) { | ||
return require('./repl'); | ||
} | ||
literals = opts.run ? sources.splice(1) : []; | ||
process.argv = process.argv.slice(0, 2).concat(literals); | ||
process.argv[0] = 'coffee'; | ||
@@ -74,3 +95,5 @@ process.execPath = require.main.filename; | ||
return fs.stat(source, function(err, stats) { | ||
if (err && err.code !== 'ENOENT') throw err; | ||
if (err && err.code !== 'ENOENT') { | ||
throw err; | ||
} | ||
if ((err != null ? err.code : void 0) === 'ENOENT') { | ||
@@ -88,12 +111,23 @@ if (topLevel && source.slice(-7) !== '.coffee') { | ||
if (stats.isDirectory()) { | ||
if (opts.watch) watchDir(source, base); | ||
if (opts.watch) { | ||
watchDir(source, base); | ||
} | ||
return fs.readdir(source, function(err, files) { | ||
var file, index, _i, _len, _ref2, _results; | ||
if (err && err.code !== 'ENOENT') throw err; | ||
if ((err != null ? err.code : void 0) === 'ENOENT') return; | ||
files = files.map(function(file) { | ||
return path.join(source, file); | ||
}); | ||
var file, index, _i, _len, _ref1, _ref2, _results; | ||
if (err && err.code !== 'ENOENT') { | ||
throw err; | ||
} | ||
if ((err != null ? err.code : void 0) === 'ENOENT') { | ||
return; | ||
} | ||
index = sources.indexOf(source); | ||
[].splice.apply(sources, [index, index - index + 1].concat(files)), files; | ||
[].splice.apply(sources, [index, index - index + 1].concat(_ref1 = (function() { | ||
var _i, _len, _results; | ||
_results = []; | ||
for (_i = 0, _len = files.length; _i < _len; _i++) { | ||
file = files[_i]; | ||
_results.push(path.join(source, file)); | ||
} | ||
return _results; | ||
})())), _ref1; | ||
[].splice.apply(sourceCode, [index, index - index + 1].concat(_ref2 = files.map(function() { | ||
@@ -105,3 +139,5 @@ return null; | ||
file = files[_i]; | ||
_results.push(compilePath(file, false, base)); | ||
if (!hidden(file)) { | ||
_results.push(compilePath(path.join(source, file), false, base)); | ||
} | ||
} | ||
@@ -111,6 +147,12 @@ return _results; | ||
} else if (topLevel || path.extname(source) === '.coffee') { | ||
if (opts.watch) watch(source, base); | ||
if (opts.watch) { | ||
watch(source, base); | ||
} | ||
return fs.readFile(source, function(err, code) { | ||
if (err && err.code !== 'ENOENT') throw err; | ||
if ((err != null ? err.code : void 0) === 'ENOENT') return; | ||
if (err && err.code !== 'ENOENT') { | ||
throw err; | ||
} | ||
if ((err != null ? err.code : void 0) === 'ENOENT') { | ||
return; | ||
} | ||
return compileScript(source, code.toString(), base); | ||
@@ -158,4 +200,8 @@ }); | ||
CoffeeScript.emit('failure', err, task); | ||
if (CoffeeScript.listeners('failure').length) return; | ||
if (o.watch) return printLine(err.message); | ||
if (CoffeeScript.listeners('failure').length) { | ||
return; | ||
} | ||
if (o.watch) { | ||
return printLine(err.message + '\x07'); | ||
} | ||
printWarn(err instanceof Error && err.stack || ("ERROR: " + err)); | ||
@@ -171,3 +217,5 @@ return process.exit(1); | ||
stdin.on('data', function(buffer) { | ||
if (buffer) return code += buffer.toString(); | ||
if (buffer) { | ||
return code += buffer.toString(); | ||
} | ||
}); | ||
@@ -182,3 +230,5 @@ return stdin.on('end', function() { | ||
compileJoin = function() { | ||
if (!opts.join) return; | ||
if (!opts.join) { | ||
return; | ||
} | ||
if (!sourceCode.some(function(code) { | ||
@@ -195,8 +245,8 @@ return code === null; | ||
loadRequires = function() { | ||
var realFilename, req, _i, _len, _ref2; | ||
var realFilename, req, _i, _len, _ref1; | ||
realFilename = module.filename; | ||
module.filename = '.'; | ||
_ref2 = opts.require; | ||
for (_i = 0, _len = _ref2.length; _i < _len; _i++) { | ||
req = _ref2[_i]; | ||
_ref1 = opts.require; | ||
for (_i = 0, _len = _ref1.length; _i < _len; _i++) { | ||
req = _ref1[_i]; | ||
require(req); | ||
@@ -208,3 +258,3 @@ } | ||
watch = function(source, base) { | ||
var callback, compile, compileTimeout, prevStats, watchErr, watcher; | ||
var compile, compileTimeout, prevStats, rewatch, watchErr, watcher; | ||
prevStats = null; | ||
@@ -214,5 +264,12 @@ compileTimeout = null; | ||
if (e.code === 'ENOENT') { | ||
if (sources.indexOf(source) === -1) return; | ||
removeSource(source, base, true); | ||
return compileJoin(); | ||
if (sources.indexOf(source) === -1) { | ||
return; | ||
} | ||
try { | ||
rewatch(); | ||
return compile(); | ||
} catch (e) { | ||
removeSource(source, base, true); | ||
return compileJoin(); | ||
} | ||
} else { | ||
@@ -226,10 +283,15 @@ throw e; | ||
return fs.stat(source, function(err, stats) { | ||
if (err) return watchErr(err); | ||
if (prevStats && (stats.size === prevStats.size && stats.mtime.getTime() === prevStats.mtime.getTime())) { | ||
return; | ||
if (err) { | ||
return watchErr(err); | ||
} | ||
if (prevStats && stats.size === prevStats.size && stats.mtime.getTime() === prevStats.mtime.getTime()) { | ||
return rewatch(); | ||
} | ||
prevStats = stats; | ||
return fs.readFile(source, function(err, code) { | ||
if (err) return watchErr(err); | ||
return compileScript(source, code.toString(), base); | ||
if (err) { | ||
return watchErr(err); | ||
} | ||
compileScript(source, code.toString(), base); | ||
return rewatch(); | ||
}); | ||
@@ -239,26 +301,13 @@ }); | ||
}; | ||
watchErr = function(e) { | ||
if (e.code !== 'ENOENT') throw e; | ||
removeSource(source, base, true); | ||
return compileJoin(); | ||
}; | ||
try { | ||
return watcher = fs.watch(source, callback = function(event) { | ||
if (event === 'change') { | ||
return compile(); | ||
} else if (event === 'rename') { | ||
watcher.close(); | ||
return wait(250, function() { | ||
compile(); | ||
try { | ||
return watcher = fs.watch(source, callback); | ||
} catch (e) { | ||
return watchErr(e); | ||
} | ||
}); | ||
} | ||
}); | ||
watcher = fs.watch(source, compile); | ||
} catch (e) { | ||
return watchErr(e); | ||
watchErr(e); | ||
} | ||
return rewatch = function() { | ||
if (watcher != null) { | ||
watcher.close(); | ||
} | ||
return watcher = fs.watch(source, compile); | ||
}; | ||
}; | ||
@@ -276,13 +325,15 @@ | ||
if (err) { | ||
if (err.code !== 'ENOENT') throw err; | ||
if (err.code !== 'ENOENT') { | ||
throw err; | ||
} | ||
watcher.close(); | ||
return unwatchDir(source, base); | ||
} | ||
files = files.map(function(file) { | ||
return path.join(source, file); | ||
}); | ||
_results = []; | ||
for (_i = 0, _len = files.length; _i < _len; _i++) { | ||
file = files[_i]; | ||
if (!(!notSources[file])) continue; | ||
if (!(!hidden(file) && !notSources[file])) { | ||
continue; | ||
} | ||
file = path.join(source, file); | ||
if (sources.some(function(s) { | ||
@@ -302,3 +353,5 @@ return s.indexOf(file) >= 0; | ||
} catch (e) { | ||
if (e.code !== 'ENOENT') throw e; | ||
if (e.code !== 'ENOENT') { | ||
throw e; | ||
} | ||
} | ||
@@ -309,3 +362,3 @@ }; | ||
var file, prevSources, toRemove, _i, _len; | ||
prevSources = sources.slice(); | ||
prevSources = sources.slice(0); | ||
toRemove = (function() { | ||
@@ -316,3 +369,5 @@ var _i, _len, _results; | ||
file = sources[_i]; | ||
if (file.indexOf(source) >= 0) _results.push(file); | ||
if (file.indexOf(source) >= 0) { | ||
_results.push(file); | ||
} | ||
} | ||
@@ -343,3 +398,5 @@ return _results; | ||
return fs.unlink(jsPath, function(err) { | ||
if (err && err.code !== 'ENOENT') throw err; | ||
if (err && err.code !== 'ENOENT') { | ||
throw err; | ||
} | ||
return timeLog("removed " + source); | ||
@@ -366,3 +423,5 @@ }); | ||
compile = function() { | ||
if (js.length <= 0) js = ' '; | ||
if (js.length <= 0) { | ||
js = ' '; | ||
} | ||
return fs.writeFile(jsPath, js, function(err) { | ||
@@ -409,7 +468,7 @@ if (err) { | ||
strings = (function() { | ||
var _i, _len, _ref2, _results; | ||
var _i, _len, _ref1, _results; | ||
_results = []; | ||
for (_i = 0, _len = tokens.length; _i < _len; _i++) { | ||
token = tokens[_i]; | ||
_ref2 = [token[0], token[1].toString().replace(/\n/, '\\n')], tag = _ref2[0], value = _ref2[1]; | ||
_ref1 = [token[0], token[1].toString().replace(/\n/, '\\n')], tag = _ref1[0], value = _ref1[1]; | ||
_results.push("[" + tag + " " + value + "]"); | ||
@@ -423,3 +482,3 @@ } | ||
parseOptions = function() { | ||
var i, o, source, _len; | ||
var i, o, source, _i, _len; | ||
optionParser = new optparse.OptionParser(SWITCHES, BANNER); | ||
@@ -429,5 +488,5 @@ o = opts = optionParser.parse(process.argv.slice(2)); | ||
o.run = !(o.compile || o.print || o.lint); | ||
o.print = !!(o.print || (o.eval || o.stdio && o.compile)); | ||
sources = o.arguments; | ||
for (i = 0, _len = sources.length; i < _len; i++) { | ||
o.print = !!(o.print || (o["eval"] || o.stdio && o.compile)); | ||
sources = o["arguments"]; | ||
for (i = _i = 0, _len = sources.length; _i < _len; i = ++_i) { | ||
source = sources[i]; | ||
@@ -441,3 +500,4 @@ sourceCode[i] = null; | ||
filename: filename, | ||
bare: opts.bare | ||
bare: opts.bare, | ||
header: opts.compile | ||
}; | ||
@@ -444,0 +504,0 @@ }; |
@@ -0,1 +1,2 @@ | ||
// Generated by CoffeeScript 1.3.0 | ||
(function() { | ||
@@ -11,3 +12,5 @@ var Parser, alt, alternatives, grammar, name, o, operators, token, tokens, unwrap; | ||
patternString = patternString.replace(/\s{2,}/g, ' '); | ||
if (!action) return [patternString, '$$ = $1;', options]; | ||
if (!action) { | ||
return [patternString, '$$ = $1;', options]; | ||
} | ||
action = (match = unwrap.exec(action)) ? match[1] : "(" + action + "())"; | ||
@@ -68,3 +71,5 @@ action = action.replace(/\bnew /g, '$&yy.'); | ||
val = new Literal($1); | ||
if ($1 === 'undefined') val.isUndefined = true; | ||
if ($1 === 'undefined') { | ||
val.isUndefined = true; | ||
} | ||
return val; | ||
@@ -296,2 +301,4 @@ }) | ||
return new Range(null, $2, $1); | ||
}), o('RangeDots', function() { | ||
return new Range(null, null, $1); | ||
}) | ||
@@ -565,3 +572,3 @@ ], | ||
operators = [['left', '.', '?.', '::'], ['left', 'CALL_START', 'CALL_END'], ['nonassoc', '++', '--'], ['left', '?'], ['right', 'UNARY'], ['left', 'MATH'], ['left', '+', '-'], ['left', 'SHIFT'], ['left', 'RELATION'], ['left', 'COMPARE'], ['left', 'LOGIC'], ['nonassoc', 'INDENT', 'OUTDENT'], ['right', '=', ':', 'COMPOUND_ASSIGN', 'RETURN', 'THROW', 'EXTENDS'], ['right', 'FORIN', 'FOROF', 'BY', 'WHEN'], ['right', 'IF', 'ELSE', 'FOR', 'DO', 'WHILE', 'UNTIL', 'LOOP', 'SUPER', 'CLASS'], ['right', 'POST_IF']]; | ||
operators = [['left', '.', '?.', '::'], ['left', 'CALL_START', 'CALL_END'], ['nonassoc', '++', '--'], ['left', '?'], ['right', 'UNARY'], ['left', 'MATH'], ['left', '+', '-'], ['left', 'SHIFT'], ['left', 'RELATION'], ['left', 'COMPARE'], ['left', 'LOGIC'], ['nonassoc', 'INDENT', 'OUTDENT'], ['right', '=', ':', 'COMPOUND_ASSIGN', 'RETURN', 'THROW', 'EXTENDS'], ['right', 'FORIN', 'FOROF', 'BY', 'WHEN'], ['right', 'IF', 'ELSE', 'FOR', 'WHILE', 'UNTIL', 'LOOP', 'SUPER', 'CLASS'], ['right', 'POST_IF']]; | ||
@@ -573,3 +580,3 @@ tokens = []; | ||
grammar[name] = (function() { | ||
var _i, _j, _len, _len2, _ref, _results; | ||
var _i, _j, _len, _len1, _ref, _results; | ||
_results = []; | ||
@@ -579,7 +586,11 @@ for (_i = 0, _len = alternatives.length; _i < _len; _i++) { | ||
_ref = alt[0].split(' '); | ||
for (_j = 0, _len2 = _ref.length; _j < _len2; _j++) { | ||
for (_j = 0, _len1 = _ref.length; _j < _len1; _j++) { | ||
token = _ref[_j]; | ||
if (!grammar[token]) tokens.push(token); | ||
if (!grammar[token]) { | ||
tokens.push(token); | ||
} | ||
} | ||
if (name === 'Root') alt[1] = "return " + alt[1]; | ||
if (name === 'Root') { | ||
alt[1] = "return " + alt[1]; | ||
} | ||
_results.push(alt); | ||
@@ -586,0 +597,0 @@ } |
@@ -0,1 +1,2 @@ | ||
// Generated by CoffeeScript 1.3.0 | ||
(function() { | ||
@@ -19,3 +20,5 @@ var extend, flatten; | ||
item = array[_i]; | ||
if (item) _results.push(item); | ||
if (item) { | ||
_results.push(item); | ||
} | ||
} | ||
@@ -28,3 +31,5 @@ return _results; | ||
num = pos = 0; | ||
if (!substr.length) return 1 / 0; | ||
if (!substr.length) { | ||
return 1 / 0; | ||
} | ||
while (pos = 1 + string.indexOf(substr, pos)) { | ||
@@ -31,0 +36,0 @@ num++; |
@@ -0,1 +1,2 @@ | ||
// Generated by CoffeeScript 1.3.0 | ||
(function() { | ||
@@ -2,0 +3,0 @@ var key, val, _ref; |
@@ -0,11 +1,14 @@ | ||
// Generated by CoffeeScript 1.3.0 | ||
(function() { | ||
var BOOL, CALLABLE, CODE, COFFEE_ALIASES, COFFEE_ALIAS_MAP, COFFEE_KEYWORDS, COMMENT, COMPARE, COMPOUND_ASSIGN, HEREDOC, HEREDOC_ILLEGAL, HEREDOC_INDENT, HEREGEX, HEREGEX_OMIT, IDENTIFIER, INDEXABLE, INVERSES, JSTOKEN, JS_FORBIDDEN, JS_KEYWORDS, LINE_BREAK, LINE_CONTINUER, LOGIC, Lexer, MATH, MULTILINER, MULTI_DENT, NOT_REGEX, NOT_SPACED_REGEX, NUMBER, OPERATOR, REGEX, RELATION, RESERVED, Rewriter, SHIFT, SIMPLESTR, TRAILING_SPACES, UNARY, WHITESPACE, compact, count, key, last, starts, _ref, _ref2, | ||
__indexOf = Array.prototype.indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; }; | ||
var BOOL, CALLABLE, CODE, COFFEE_ALIASES, COFFEE_ALIAS_MAP, COFFEE_KEYWORDS, COMMENT, COMPARE, COMPOUND_ASSIGN, HEREDOC, HEREDOC_ILLEGAL, HEREDOC_INDENT, HEREGEX, HEREGEX_OMIT, IDENTIFIER, INDEXABLE, INVERSES, JSTOKEN, JS_FORBIDDEN, JS_KEYWORDS, LINE_BREAK, LINE_CONTINUER, LOGIC, Lexer, MATH, MULTILINER, MULTI_DENT, NOT_REGEX, NOT_SPACED_REGEX, NUMBER, OPERATOR, REGEX, RELATION, RESERVED, Rewriter, SHIFT, SIMPLESTR, STRICT_PROSCRIBED, TRAILING_SPACES, UNARY, WHITESPACE, compact, count, key, last, starts, _ref, _ref1, | ||
__indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; }; | ||
_ref = require('./rewriter'), Rewriter = _ref.Rewriter, INVERSES = _ref.INVERSES; | ||
_ref2 = require('./helpers'), count = _ref2.count, starts = _ref2.starts, compact = _ref2.compact, last = _ref2.last; | ||
_ref1 = require('./helpers'), count = _ref1.count, starts = _ref1.starts, compact = _ref1.compact, last = _ref1.last; | ||
exports.Lexer = Lexer = (function() { | ||
Lexer.name = 'Lexer'; | ||
function Lexer() {} | ||
@@ -15,4 +18,8 @@ | ||
var i, tag; | ||
if (opts == null) opts = {}; | ||
if (WHITESPACE.test(code)) code = "\n" + code; | ||
if (opts == null) { | ||
opts = {}; | ||
} | ||
if (WHITESPACE.test(code)) { | ||
code = "\n" + code; | ||
} | ||
code = code.replace(/\r/g, '').replace(TRAILING_SPACES, ''); | ||
@@ -32,4 +39,8 @@ this.code = code; | ||
this.closeIndentation(); | ||
if (tag = this.ends.pop()) this.error("missing " + tag); | ||
if (opts.rewrite === false) return this.tokens; | ||
if (tag = this.ends.pop()) { | ||
this.error("missing " + tag); | ||
} | ||
if (opts.rewrite === false) { | ||
return this.tokens; | ||
} | ||
return (new Rewriter).rewrite(this.tokens); | ||
@@ -39,4 +50,6 @@ }; | ||
Lexer.prototype.identifierToken = function() { | ||
var colon, forcedIdentifier, id, input, match, prev, tag, _ref3, _ref4; | ||
if (!(match = IDENTIFIER.exec(this.chunk))) return 0; | ||
var colon, forcedIdentifier, id, input, match, prev, tag, _ref2, _ref3; | ||
if (!(match = IDENTIFIER.exec(this.chunk))) { | ||
return 0; | ||
} | ||
input = match[0], id = match[1], colon = match[2]; | ||
@@ -47,7 +60,7 @@ if (id === 'own' && this.tag() === 'FOR') { | ||
} | ||
forcedIdentifier = colon || (prev = last(this.tokens)) && (((_ref3 = prev[0]) === '.' || _ref3 === '?.' || _ref3 === '::') || !prev.spaced && prev[0] === '@'); | ||
forcedIdentifier = colon || (prev = last(this.tokens)) && (((_ref2 = prev[0]) === '.' || _ref2 === '?.' || _ref2 === '::') || !prev.spaced && prev[0] === '@'); | ||
tag = 'IDENTIFIER'; | ||
if (!forcedIdentifier && (__indexOf.call(JS_KEYWORDS, id) >= 0 || __indexOf.call(COFFEE_KEYWORDS, id) >= 0)) { | ||
tag = id.toUpperCase(); | ||
if (tag === 'WHEN' && (_ref4 = this.tag(), __indexOf.call(LINE_BREAK, _ref4) >= 0)) { | ||
if (tag === 'WHEN' && (_ref3 = this.tag(), __indexOf.call(LINE_BREAK, _ref3) >= 0)) { | ||
tag = 'LEADING_WHEN'; | ||
@@ -73,3 +86,3 @@ } else if (tag === 'FOR') { | ||
} | ||
if (__indexOf.call(['eval', 'arguments'].concat(JS_FORBIDDEN), id) >= 0) { | ||
if (__indexOf.call(JS_FORBIDDEN, id) >= 0) { | ||
if (forcedIdentifier) { | ||
@@ -84,3 +97,5 @@ tag = 'IDENTIFIER'; | ||
if (!forcedIdentifier) { | ||
if (__indexOf.call(COFFEE_ALIASES, id) >= 0) id = COFFEE_ALIAS_MAP[id]; | ||
if (__indexOf.call(COFFEE_ALIASES, id) >= 0) { | ||
id = COFFEE_ALIAS_MAP[id]; | ||
} | ||
tag = (function() { | ||
@@ -110,3 +125,5 @@ switch (id) { | ||
this.token(tag, id); | ||
if (colon) this.token(':', ':'); | ||
if (colon) { | ||
this.token(':', ':'); | ||
} | ||
return input.length; | ||
@@ -116,9 +133,23 @@ }; | ||
Lexer.prototype.numberToken = function() { | ||
var binaryLiteral, lexedLength, match, number; | ||
if (!(match = NUMBER.exec(this.chunk))) return 0; | ||
var binaryLiteral, lexedLength, match, number, octalLiteral; | ||
if (!(match = NUMBER.exec(this.chunk))) { | ||
return 0; | ||
} | ||
number = match[0]; | ||
if (/^0[BOX]/.test(number)) { | ||
this.error("radix prefix '" + number + "' must be lowercase"); | ||
} else if (/E/.test(number) && !/^0x/.test(number)) { | ||
this.error("exponential notation '" + number + "' must be indicated with a lowercase 'e'"); | ||
} else if (/^0\d*[89]/.test(number)) { | ||
this.error("decimal literal '" + number + "' must not be prefixed with '0'"); | ||
} else if (/^0\d+/.test(number)) { | ||
this.error("octal literal '" + number + "' must be prefixed with '0o'"); | ||
} | ||
lexedLength = number.length; | ||
if (binaryLiteral = /0b([01]+)/.exec(number)) { | ||
number = (parseInt(binaryLiteral[1], 2)).toString(); | ||
if (octalLiteral = /^0o([0-7]+)/.exec(number)) { | ||
number = '0x' + (parseInt(octalLiteral[1], 8)).toString(16); | ||
} | ||
if (binaryLiteral = /^0b([01]+)/.exec(number)) { | ||
number = '0x' + (parseInt(binaryLiteral[1], 2)).toString(16); | ||
} | ||
this.token('NUMBER', number); | ||
@@ -129,10 +160,14 @@ return lexedLength; | ||
Lexer.prototype.stringToken = function() { | ||
var match, string; | ||
var match, octalEsc, string; | ||
switch (this.chunk.charAt(0)) { | ||
case "'": | ||
if (!(match = SIMPLESTR.exec(this.chunk))) return 0; | ||
if (!(match = SIMPLESTR.exec(this.chunk))) { | ||
return 0; | ||
} | ||
this.token('STRING', (string = match[0]).replace(MULTILINER, '\\\n')); | ||
break; | ||
case '"': | ||
if (!(string = this.balancedString(this.chunk, '"'))) return 0; | ||
if (!(string = this.balancedString(this.chunk, '"'))) { | ||
return 0; | ||
} | ||
if (0 < string.indexOf('#{', 1)) { | ||
@@ -147,2 +182,5 @@ this.interpolateString(string.slice(1, -1)); | ||
} | ||
if (octalEsc = /^(?:\\.|[^\\])*\\[0-7]/.test(string)) { | ||
this.error("octal escape sequences " + string + " are not allowed"); | ||
} | ||
this.line += count(string, '\n'); | ||
@@ -154,3 +192,5 @@ return string.length; | ||
var doc, heredoc, match, quote; | ||
if (!(match = HEREDOC.exec(this.chunk))) return 0; | ||
if (!(match = HEREDOC.exec(this.chunk))) { | ||
return 0; | ||
} | ||
heredoc = match[0]; | ||
@@ -175,3 +215,5 @@ quote = heredoc.charAt(0); | ||
var comment, here, match; | ||
if (!(match = this.chunk.match(COMMENT))) return 0; | ||
if (!(match = this.chunk.match(COMMENT))) { | ||
return 0; | ||
} | ||
comment = match[0], here = match[1]; | ||
@@ -183,3 +225,2 @@ if (here) { | ||
})); | ||
this.token('TERMINATOR', '\n'); | ||
} | ||
@@ -200,4 +241,6 @@ this.line += count(comment, '\n'); | ||
Lexer.prototype.regexToken = function() { | ||
var flags, length, match, prev, regex, _ref3, _ref4; | ||
if (this.chunk.charAt(0) !== '/') return 0; | ||
var flags, length, match, prev, regex, _ref2, _ref3; | ||
if (this.chunk.charAt(0) !== '/') { | ||
return 0; | ||
} | ||
if (match = HEREGEX.exec(this.chunk)) { | ||
@@ -209,11 +252,15 @@ length = this.heregexToken(match); | ||
prev = last(this.tokens); | ||
if (prev && (_ref3 = prev[0], __indexOf.call((prev.spaced ? NOT_REGEX : NOT_SPACED_REGEX), _ref3) >= 0)) { | ||
if (prev && (_ref2 = prev[0], __indexOf.call((prev.spaced ? NOT_REGEX : NOT_SPACED_REGEX), _ref2) >= 0)) { | ||
return 0; | ||
} | ||
if (!(match = REGEX.exec(this.chunk))) return 0; | ||
_ref4 = match, match = _ref4[0], regex = _ref4[1], flags = _ref4[2]; | ||
if (!(match = REGEX.exec(this.chunk))) { | ||
return 0; | ||
} | ||
_ref3 = match, match = _ref3[0], regex = _ref3[1], flags = _ref3[2]; | ||
if (regex.slice(0, 2) === '/*') { | ||
this.error('regular expressions cannot begin with `*`'); | ||
} | ||
if (regex === '//') regex = '/(?:)/'; | ||
if (regex === '//') { | ||
regex = '/(?:)/'; | ||
} | ||
this.token('REGEX', "" + regex + flags); | ||
@@ -224,3 +271,3 @@ return match.length; | ||
Lexer.prototype.heregexToken = function(match) { | ||
var body, flags, heregex, re, tag, tokens, value, _i, _len, _ref3, _ref4, _ref5, _ref6; | ||
var body, flags, heregex, re, tag, tokens, value, _i, _len, _ref2, _ref3, _ref4, _ref5; | ||
heregex = match[0], body = match[1], flags = match[2]; | ||
@@ -238,11 +285,13 @@ if (0 > body.indexOf('#{')) { | ||
tokens = []; | ||
_ref3 = this.interpolateString(body, { | ||
_ref2 = this.interpolateString(body, { | ||
regex: true | ||
}); | ||
for (_i = 0, _len = _ref3.length; _i < _len; _i++) { | ||
_ref4 = _ref3[_i], tag = _ref4[0], value = _ref4[1]; | ||
for (_i = 0, _len = _ref2.length; _i < _len; _i++) { | ||
_ref3 = _ref2[_i], tag = _ref3[0], value = _ref3[1]; | ||
if (tag === 'TOKENS') { | ||
tokens.push.apply(tokens, value); | ||
} else { | ||
if (!(value = value.replace(HEREGEX_OMIT, ''))) continue; | ||
if (!(value = value.replace(HEREGEX_OMIT, ''))) { | ||
continue; | ||
} | ||
value = value.replace(/\\/g, '\\\\'); | ||
@@ -254,7 +303,9 @@ tokens.push(['STRING', this.makeString(value, '"', true)]); | ||
tokens.pop(); | ||
if (((_ref5 = tokens[0]) != null ? _ref5[0] : void 0) !== 'STRING') { | ||
if (((_ref4 = tokens[0]) != null ? _ref4[0] : void 0) !== 'STRING') { | ||
this.tokens.push(['STRING', '""'], ['+', '+']); | ||
} | ||
(_ref6 = this.tokens).push.apply(_ref6, tokens); | ||
if (flags) this.tokens.push([',', ','], ['STRING', '"' + flags + '"']); | ||
(_ref5 = this.tokens).push.apply(_ref5, tokens); | ||
if (flags) { | ||
this.tokens.push([',', ','], ['STRING', '"' + flags + '"']); | ||
} | ||
this.token(')', ')'); | ||
@@ -266,3 +317,5 @@ return heregex.length; | ||
var diff, indent, match, noNewlines, prev, size; | ||
if (!(match = MULTI_DENT.exec(this.chunk))) return 0; | ||
if (!(match = MULTI_DENT.exec(this.chunk))) { | ||
return 0; | ||
} | ||
indent = match[0]; | ||
@@ -321,3 +374,5 @@ this.line += count(indent, '\n'); | ||
} | ||
if (dent) this.outdebt -= moveOut; | ||
if (dent) { | ||
this.outdebt -= moveOut; | ||
} | ||
while (this.value() === ';') { | ||
@@ -338,3 +393,5 @@ this.tokens.pop(); | ||
prev = last(this.tokens); | ||
if (prev) prev[match ? 'spaced' : 'newLine'] = true; | ||
if (prev) { | ||
prev[match ? 'spaced' : 'newLine'] = true; | ||
} | ||
if (match) { | ||
@@ -351,3 +408,5 @@ return match[0].length; | ||
} | ||
if (this.tag() !== 'TERMINATOR') this.token('TERMINATOR', '\n'); | ||
if (this.tag() !== 'TERMINATOR') { | ||
this.token('TERMINATOR', '\n'); | ||
} | ||
return this; | ||
@@ -357,3 +416,5 @@ }; | ||
Lexer.prototype.suppressNewlines = function() { | ||
if (this.value() === '\\') this.tokens.pop(); | ||
if (this.value() === '\\') { | ||
this.tokens.pop(); | ||
} | ||
return this; | ||
@@ -363,6 +424,8 @@ }; | ||
Lexer.prototype.literalToken = function() { | ||
var match, prev, tag, value, _ref3, _ref4, _ref5, _ref6; | ||
var match, prev, tag, value, _ref2, _ref3, _ref4, _ref5; | ||
if (match = OPERATOR.exec(this.chunk)) { | ||
value = match[0]; | ||
if (CODE.test(value)) this.tagParameters(); | ||
if (CODE.test(value)) { | ||
this.tagParameters(); | ||
} | ||
} else { | ||
@@ -374,6 +437,6 @@ value = this.chunk.charAt(0); | ||
if (value === '=' && prev) { | ||
if (!prev[1].reserved && (_ref3 = prev[1], __indexOf.call(JS_FORBIDDEN, _ref3) >= 0)) { | ||
if (!prev[1].reserved && (_ref2 = prev[1], __indexOf.call(JS_FORBIDDEN, _ref2) >= 0)) { | ||
this.error("reserved word \"" + (this.value()) + "\" can't be assigned"); | ||
} | ||
if ((_ref4 = prev[1]) === '||' || _ref4 === '&&') { | ||
if ((_ref3 = prev[1]) === '||' || _ref3 === '&&') { | ||
prev[0] = 'COMPOUND_ASSIGN'; | ||
@@ -400,6 +463,8 @@ prev[1] += '='; | ||
} else if (prev && !prev.spaced) { | ||
if (value === '(' && (_ref5 = prev[0], __indexOf.call(CALLABLE, _ref5) >= 0)) { | ||
if (prev[0] === '?') prev[0] = 'FUNC_EXIST'; | ||
if (value === '(' && (_ref4 = prev[0], __indexOf.call(CALLABLE, _ref4) >= 0)) { | ||
if (prev[0] === '?') { | ||
prev[0] = 'FUNC_EXIST'; | ||
} | ||
tag = 'CALL_START'; | ||
} else if (value === '[' && (_ref6 = prev[0], __indexOf.call(INDEXABLE, _ref6) >= 0)) { | ||
} else if (value === '[' && (_ref5 = prev[0], __indexOf.call(INDEXABLE, _ref5) >= 0)) { | ||
tag = 'INDEX_START'; | ||
@@ -428,3 +493,3 @@ switch (prev[0]) { | ||
Lexer.prototype.sanitizeHeredoc = function(doc, options) { | ||
var attempt, herecomment, indent, match, _ref3; | ||
var attempt, herecomment, indent, match, _ref2; | ||
indent = options.indent, herecomment = options.herecomment; | ||
@@ -435,7 +500,9 @@ if (herecomment) { | ||
} | ||
if (doc.indexOf('\n') <= 0) return doc; | ||
if (doc.indexOf('\n') <= 0) { | ||
return doc; | ||
} | ||
} else { | ||
while (match = HEREDOC_INDENT.exec(doc)) { | ||
attempt = match[1]; | ||
if (indent === null || (0 < (_ref3 = attempt.length) && _ref3 < indent.length)) { | ||
if (indent === null || (0 < (_ref2 = attempt.length) && _ref2 < indent.length)) { | ||
indent = attempt; | ||
@@ -445,4 +512,8 @@ } | ||
} | ||
if (indent) doc = doc.replace(RegExp("\\n" + indent, "g"), '\n'); | ||
if (!herecomment) doc = doc.replace(/^\n/, ''); | ||
if (indent) { | ||
doc = doc.replace(RegExp("\\n" + indent, "g"), '\n'); | ||
} | ||
if (!herecomment) { | ||
doc = doc.replace(/^\n/, ''); | ||
} | ||
return doc; | ||
@@ -453,3 +524,5 @@ }; | ||
var i, stack, tok, tokens; | ||
if (this.tag() !== ')') return this; | ||
if (this.tag() !== ')') { | ||
return this; | ||
} | ||
stack = []; | ||
@@ -484,12 +557,19 @@ tokens = this.tokens; | ||
Lexer.prototype.balancedString = function(str, end) { | ||
var i, letter, match, prev, stack, _ref3; | ||
var continueCount, i, letter, match, prev, stack, _i, _ref2; | ||
continueCount = 0; | ||
stack = [end]; | ||
for (i = 1, _ref3 = str.length; 1 <= _ref3 ? i < _ref3 : i > _ref3; 1 <= _ref3 ? i++ : i--) { | ||
for (i = _i = 1, _ref2 = str.length; 1 <= _ref2 ? _i < _ref2 : _i > _ref2; i = 1 <= _ref2 ? ++_i : --_i) { | ||
if (continueCount) { | ||
--continueCount; | ||
continue; | ||
} | ||
switch (letter = str.charAt(i)) { | ||
case '\\': | ||
i++; | ||
++continueCount; | ||
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]; | ||
@@ -501,3 +581,3 @@ continue; | ||
} else if (end === '}' && letter === '/' && (match = HEREGEX.exec(str.slice(i)) || REGEX.exec(str.slice(i)))) { | ||
i += match[0].length - 1; | ||
continueCount += match[0].length - 1; | ||
} else if (end === '}' && letter === '{') { | ||
@@ -514,4 +594,6 @@ stack.push(end = '}'); | ||
Lexer.prototype.interpolateString = function(str, options) { | ||
var expr, heredoc, i, inner, interpolated, len, letter, nested, pi, regex, tag, tokens, value, _len, _ref3, _ref4, _ref5; | ||
if (options == null) options = {}; | ||
var expr, heredoc, i, inner, interpolated, len, letter, nested, pi, regex, tag, tokens, value, _i, _len, _ref2, _ref3, _ref4; | ||
if (options == null) { | ||
options = {}; | ||
} | ||
heredoc = options.heredoc, regex = options.regex; | ||
@@ -529,3 +611,5 @@ tokens = []; | ||
} | ||
if (pi < i) tokens.push(['NEOSTRING', str.slice(pi, i)]); | ||
if (pi < i) { | ||
tokens.push(['NEOSTRING', str.slice(pi, i)]); | ||
} | ||
inner = expr.slice(1, -1); | ||
@@ -538,3 +622,3 @@ if (inner.length) { | ||
nested.pop(); | ||
if (((_ref3 = nested[0]) != null ? _ref3[0] : void 0) === 'TERMINATOR') { | ||
if (((_ref2 = nested[0]) != null ? _ref2[0] : void 0) === 'TERMINATOR') { | ||
nested.shift(); | ||
@@ -553,12 +637,24 @@ } | ||
} | ||
if ((i > pi && pi < str.length)) tokens.push(['NEOSTRING', str.slice(pi)]); | ||
if (regex) return tokens; | ||
if (!tokens.length) return this.token('STRING', '""'); | ||
if (tokens[0][0] !== 'NEOSTRING') tokens.unshift(['', '']); | ||
if (interpolated = tokens.length > 1) this.token('(', '('); | ||
for (i = 0, _len = tokens.length; i < _len; i++) { | ||
_ref4 = tokens[i], tag = _ref4[0], value = _ref4[1]; | ||
if (i) this.token('+', '+'); | ||
if ((i > pi && pi < str.length)) { | ||
tokens.push(['NEOSTRING', str.slice(pi)]); | ||
} | ||
if (regex) { | ||
return tokens; | ||
} | ||
if (!tokens.length) { | ||
return this.token('STRING', '""'); | ||
} | ||
if (tokens[0][0] !== 'NEOSTRING') { | ||
tokens.unshift(['', '']); | ||
} | ||
if (interpolated = tokens.length > 1) { | ||
this.token('(', '('); | ||
} | ||
for (i = _i = 0, _len = tokens.length; _i < _len; i = ++_i) { | ||
_ref3 = tokens[i], tag = _ref3[0], value = _ref3[1]; | ||
if (i) { | ||
this.token('+', '+'); | ||
} | ||
if (tag === 'TOKENS') { | ||
(_ref5 = this.tokens).push.apply(_ref5, value); | ||
(_ref4 = this.tokens).push.apply(_ref4, value); | ||
} else { | ||
@@ -568,3 +664,5 @@ this.token('STRING', this.makeString(value, '"', heredoc)); | ||
} | ||
if (interpolated) this.token(')', ')'); | ||
if (interpolated) { | ||
this.token(')', ')'); | ||
} | ||
return tokens; | ||
@@ -576,3 +674,5 @@ }; | ||
if (tag !== (wanted = last(this.ends))) { | ||
if ('OUTDENT' !== wanted) this.error("unmatched " + tag); | ||
if ('OUTDENT' !== wanted) { | ||
this.error("unmatched " + tag); | ||
} | ||
this.indent -= size = last(this.indents); | ||
@@ -600,4 +700,4 @@ this.outdentToken(size, true); | ||
Lexer.prototype.unfinished = function() { | ||
var _ref3; | ||
return LINE_CONTINUER.test(this.chunk) || ((_ref3 = this.tag()) === '\\' || _ref3 === '.' || _ref3 === '?.' || _ref3 === 'UNARY' || _ref3 === 'MATH' || _ref3 === '+' || _ref3 === '-' || _ref3 === 'SHIFT' || _ref3 === 'RELATION' || _ref3 === 'COMPARE' || _ref3 === 'LOGIC' || _ref3 === 'COMPOUND_ASSIGN' || _ref3 === 'THROW' || _ref3 === 'EXTENDS'); | ||
var _ref2; | ||
return LINE_CONTINUER.test(this.chunk) || ((_ref2 = this.tag()) === '\\' || _ref2 === '.' || _ref2 === '?.' || _ref2 === 'UNARY' || _ref2 === 'MATH' || _ref2 === '+' || _ref2 === '-' || _ref2 === 'SHIFT' || _ref2 === 'RELATION' || _ref2 === 'COMPARE' || _ref2 === 'LOGIC' || _ref2 === 'THROW' || _ref2 === 'EXTENDS'); | ||
}; | ||
@@ -610,3 +710,5 @@ | ||
Lexer.prototype.makeString = function(body, quote, heredoc) { | ||
if (!body) return quote + quote; | ||
if (!body) { | ||
return quote + quote; | ||
} | ||
body = body.replace(/\\([\s\S])/g, function(match, contents) { | ||
@@ -658,11 +760,15 @@ if (contents === '\n' || contents === quote) { | ||
RESERVED = ['case', 'default', 'function', 'var', 'void', 'with', 'const', 'let', 'enum', 'export', 'import', 'native', '__hasProp', '__extends', '__slice', '__bind', '__indexOf']; | ||
RESERVED = ['case', 'default', 'function', 'var', 'void', 'with', 'const', 'let', 'enum', 'export', 'import', 'native', '__hasProp', '__extends', '__slice', '__bind', '__indexOf', 'implements', 'interface', 'let', 'package', 'private', 'protected', 'public', 'static', 'yield']; | ||
JS_FORBIDDEN = JS_KEYWORDS.concat(RESERVED); | ||
STRICT_PROSCRIBED = ['arguments', 'eval']; | ||
exports.RESERVED = RESERVED.concat(JS_KEYWORDS).concat(COFFEE_KEYWORDS); | ||
JS_FORBIDDEN = JS_KEYWORDS.concat(RESERVED).concat(STRICT_PROSCRIBED); | ||
exports.RESERVED = RESERVED.concat(JS_KEYWORDS).concat(COFFEE_KEYWORDS).concat(STRICT_PROSCRIBED); | ||
exports.STRICT_PROSCRIBED = STRICT_PROSCRIBED; | ||
IDENTIFIER = /^([$A-Za-z_\x7f-\uffff][$\w\x7f-\uffff]*)([^\n\S]*:(?!:))?/; | ||
NUMBER = /^0x[\da-f]+|^0b[01]+|^\d*\.?\d+(?:e[+-]?\d+)?/i; | ||
NUMBER = /^0b[01]+|^0o[0-7]+|^0x[\da-f]+|^\d*\.?\d+(?:e[+-]?\d+)?/i; | ||
@@ -669,0 +775,0 @@ HEREDOC = /^("""|''')([\s\S]*?)(?:\n[^\n\S]*)?\1/; |
@@ -0,1 +1,2 @@ | ||
// Generated by CoffeeScript 1.3.0 | ||
(function() { | ||
@@ -6,2 +7,4 @@ var LONG_FLAG, MULTI_FLAG, OPTIONAL, OptionParser, SHORT_FLAG, buildRule, buildRules, normalizeArguments; | ||
OptionParser.name = 'OptionParser'; | ||
function OptionParser(rules, banner) { | ||
@@ -13,36 +16,45 @@ this.banner = banner; | ||
OptionParser.prototype.parse = function(args) { | ||
var arg, i, isOption, matchedRule, options, originalArgs, pos, rule, value, _i, _len, _len2, _ref; | ||
var arg, i, isOption, matchedRule, options, originalArgs, pos, rule, seenNonOptionArg, skippingArgument, value, _i, _j, _len, _len1, _ref; | ||
options = { | ||
arguments: [], | ||
literals: [] | ||
"arguments": [] | ||
}; | ||
skippingArgument = false; | ||
originalArgs = args; | ||
args = normalizeArguments(args); | ||
for (i = 0, _len = args.length; i < _len; i++) { | ||
for (i = _i = 0, _len = args.length; _i < _len; i = ++_i) { | ||
arg = args[i]; | ||
if (skippingArgument) { | ||
skippingArgument = false; | ||
continue; | ||
} | ||
if (arg === '--') { | ||
pos = originalArgs.indexOf('--'); | ||
options.arguments = [originalArgs[1 + pos]]; | ||
options.literals = originalArgs.slice(2 + pos); | ||
options["arguments"] = options["arguments"].concat(originalArgs.slice(pos + 1)); | ||
break; | ||
} | ||
isOption = !!(arg.match(LONG_FLAG) || arg.match(SHORT_FLAG)); | ||
matchedRule = false; | ||
_ref = this.rules; | ||
for (_i = 0, _len2 = _ref.length; _i < _len2; _i++) { | ||
rule = _ref[_i]; | ||
if (rule.shortFlag === arg || rule.longFlag === arg) { | ||
value = rule.hasArgument ? args[i += 1] : true; | ||
options[rule.name] = rule.isList ? (options[rule.name] || []).concat(value) : value; | ||
matchedRule = true; | ||
break; | ||
seenNonOptionArg = options["arguments"].length > 0; | ||
if (!seenNonOptionArg) { | ||
matchedRule = false; | ||
_ref = this.rules; | ||
for (_j = 0, _len1 = _ref.length; _j < _len1; _j++) { | ||
rule = _ref[_j]; | ||
if (rule.shortFlag === arg || rule.longFlag === arg) { | ||
value = true; | ||
if (rule.hasArgument) { | ||
skippingArgument = true; | ||
value = args[i + 1]; | ||
} | ||
options[rule.name] = rule.isList ? (options[rule.name] || []).concat(value) : value; | ||
matchedRule = true; | ||
break; | ||
} | ||
} | ||
if (isOption && !matchedRule) { | ||
throw new Error("unrecognized option: " + arg); | ||
} | ||
} | ||
if (isOption && !matchedRule) { | ||
throw new Error("unrecognized option: " + arg); | ||
if (seenNonOptionArg || !isOption) { | ||
options["arguments"].push(arg); | ||
} | ||
if (!isOption) { | ||
options.arguments = originalArgs.slice(originalArgs.indexOf(arg)); | ||
break; | ||
} | ||
} | ||
@@ -55,3 +67,5 @@ return options; | ||
lines = []; | ||
if (this.banner) lines.unshift("" + this.banner + "\n"); | ||
if (this.banner) { | ||
lines.unshift("" + this.banner + "\n"); | ||
} | ||
_ref = this.rules; | ||
@@ -72,5 +86,5 @@ for (_i = 0, _len = _ref.length; _i < _len; _i++) { | ||
LONG_FLAG = /^(--\w[\w\-]+)/; | ||
LONG_FLAG = /^(--\w[\w\-]*)/; | ||
SHORT_FLAG = /^(-\w)/; | ||
SHORT_FLAG = /^(-\w)$/; | ||
@@ -86,3 +100,5 @@ MULTI_FLAG = /^-(\w{2,})/; | ||
tuple = rules[_i]; | ||
if (tuple.length < 3) tuple.unshift(null); | ||
if (tuple.length < 3) { | ||
tuple.unshift(null); | ||
} | ||
_results.push(buildRule.apply(null, tuple)); | ||
@@ -95,3 +111,5 @@ } | ||
var match; | ||
if (options == null) options = {}; | ||
if (options == null) { | ||
options = {}; | ||
} | ||
match = longFlag.match(OPTIONAL); | ||
@@ -110,3 +128,3 @@ longFlag = longFlag.match(LONG_FLAG)[1]; | ||
normalizeArguments = function(args) { | ||
var arg, l, match, result, _i, _j, _len, _len2, _ref; | ||
var arg, l, match, result, _i, _j, _len, _len1, _ref; | ||
args = args.slice(0); | ||
@@ -118,3 +136,3 @@ result = []; | ||
_ref = match[1].split(''); | ||
for (_j = 0, _len2 = _ref.length; _j < _len2; _j++) { | ||
for (_j = 0, _len1 = _ref.length; _j < _len1; _j++) { | ||
l = _ref[_j]; | ||
@@ -121,0 +139,0 @@ result.push('-' + l); |
@@ -0,4 +1,9 @@ | ||
// Generated by CoffeeScript 1.3.0 | ||
(function() { | ||
var ACCESSOR, CoffeeScript, Module, REPL_PROMPT, REPL_PROMPT_CONTINUATION, SIMPLEVAR, Script, autocomplete, backlog, completeAttribute, completeVariable, enableColours, error, getCompletions, inspect, readline, repl, run, stdin, stdout; | ||
var ACCESSOR, CoffeeScript, Module, REPL_PROMPT, REPL_PROMPT_CONTINUATION, REPL_PROMPT_MULTILINE, SIMPLEVAR, Script, autocomplete, backlog, completeAttribute, completeVariable, enableColours, error, getCompletions, inspect, multilineMode, pipedInput, readline, repl, run, stdin, stdout; | ||
stdin = process.openStdin(); | ||
stdout = process.stdout; | ||
CoffeeScript = require('./coffee-script'); | ||
@@ -16,2 +21,4 @@ | ||
REPL_PROMPT_MULTILINE = '------> '; | ||
REPL_PROMPT_CONTINUATION = '......> '; | ||
@@ -25,6 +32,2 @@ | ||
stdin = process.openStdin(); | ||
stdout = process.stdout; | ||
error = function(err) { | ||
@@ -34,36 +37,5 @@ return stdout.write((err.stack || err.toString()) + '\n'); | ||
backlog = ''; | ||
run = function(buffer) { | ||
var code, returnValue, _; | ||
if (!buffer.toString().trim() && !backlog) { | ||
repl.prompt(); | ||
return; | ||
} | ||
code = backlog += buffer; | ||
if (code[code.length - 1] === '\\') { | ||
backlog = "" + backlog.slice(0, -1) + "\n"; | ||
repl.setPrompt(REPL_PROMPT_CONTINUATION); | ||
repl.prompt(); | ||
return; | ||
} | ||
repl.setPrompt(REPL_PROMPT); | ||
backlog = ''; | ||
try { | ||
_ = global._; | ||
returnValue = CoffeeScript.eval("_=(" + code + "\n)", { | ||
filename: 'repl', | ||
modulename: 'repl' | ||
}); | ||
if (returnValue === void 0) global._ = _; | ||
process.stdout.write(inspect(returnValue, false, 2, enableColours) + '\n'); | ||
} catch (err) { | ||
error(err); | ||
} | ||
return repl.prompt(); | ||
}; | ||
ACCESSOR = /\s*([\w\.]+)(?:\.(\w*))$/; | ||
SIMPLEVAR = /\s*(\w*)$/i; | ||
SIMPLEVAR = /(\w+)$/i; | ||
@@ -83,3 +55,3 @@ autocomplete = function(text) { | ||
} | ||
completions = getCompletions(prefix, Object.getOwnPropertyNames(val)); | ||
completions = getCompletions(prefix, Object.getOwnPropertyNames(Object(val))); | ||
return [completions, prefix]; | ||
@@ -92,11 +64,16 @@ } | ||
free = (_ref = text.match(SIMPLEVAR)) != null ? _ref[1] : void 0; | ||
if (text === "") { | ||
free = ""; | ||
} | ||
if (free != null) { | ||
vars = Script.runInThisContext('Object.getOwnPropertyNames(this)'); | ||
vars = Script.runInThisContext('Object.getOwnPropertyNames(Object(this))'); | ||
keywords = (function() { | ||
var _i, _len, _ref2, _results; | ||
_ref2 = CoffeeScript.RESERVED; | ||
var _i, _len, _ref1, _results; | ||
_ref1 = CoffeeScript.RESERVED; | ||
_results = []; | ||
for (_i = 0, _len = _ref2.length; _i < _len; _i++) { | ||
r = _ref2[_i]; | ||
if (r.slice(0, 2) !== '__') _results.push(r); | ||
for (_i = 0, _len = _ref1.length; _i < _len; _i++) { | ||
r = _ref1[_i]; | ||
if (r.slice(0, 2) !== '__') { | ||
_results.push(r); | ||
} | ||
} | ||
@@ -116,3 +93,5 @@ return _results; | ||
el = candidates[_i]; | ||
if (el.indexOf(prefix) === 0) _results.push(el); | ||
if (el.indexOf(prefix) === 0) { | ||
_results.push(el); | ||
} | ||
} | ||
@@ -124,15 +103,122 @@ return _results; | ||
if (readline.createInterface.length < 3) { | ||
repl = readline.createInterface(stdin, autocomplete); | ||
stdin.on('data', function(buffer) { | ||
return repl.write(buffer); | ||
backlog = ''; | ||
run = function(buffer) { | ||
var code, returnValue, _; | ||
buffer = buffer.replace(/[\r\n]+$/, ""); | ||
if (multilineMode) { | ||
backlog += "" + buffer + "\n"; | ||
repl.setPrompt(REPL_PROMPT_CONTINUATION); | ||
repl.prompt(); | ||
return; | ||
} | ||
if (!buffer.toString().trim() && !backlog) { | ||
repl.prompt(); | ||
return; | ||
} | ||
code = backlog += buffer; | ||
if (code[code.length - 1] === '\\') { | ||
backlog = "" + backlog.slice(0, -1) + "\n"; | ||
repl.setPrompt(REPL_PROMPT_CONTINUATION); | ||
repl.prompt(); | ||
return; | ||
} | ||
repl.setPrompt(REPL_PROMPT); | ||
backlog = ''; | ||
try { | ||
_ = global._; | ||
returnValue = CoffeeScript["eval"]("_=(undefined\n;" + code + "\n)", { | ||
filename: 'repl', | ||
modulename: 'repl' | ||
}); | ||
if (returnValue === void 0) { | ||
global._ = _; | ||
} | ||
repl.output.write("" + (inspect(returnValue, false, 2, enableColours)) + "\n"); | ||
} catch (err) { | ||
error(err); | ||
} | ||
return repl.prompt(); | ||
}; | ||
if (stdin.readable) { | ||
pipedInput = ''; | ||
repl = { | ||
prompt: function() { | ||
return stdout.write(this._prompt); | ||
}, | ||
setPrompt: function(p) { | ||
return this._prompt = p; | ||
}, | ||
input: stdin, | ||
output: stdout, | ||
on: function() {} | ||
}; | ||
stdin.on('data', function(chunk) { | ||
return pipedInput += chunk; | ||
}); | ||
stdin.on('end', function() { | ||
var line, _i, _len, _ref; | ||
_ref = pipedInput.trim().split("\n"); | ||
for (_i = 0, _len = _ref.length; _i < _len; _i++) { | ||
line = _ref[_i]; | ||
stdout.write("" + line + "\n"); | ||
run(line); | ||
} | ||
stdout.write('\n'); | ||
return process.exit(0); | ||
}); | ||
} else { | ||
repl = readline.createInterface(stdin, stdout, autocomplete); | ||
if (readline.createInterface.length < 3) { | ||
repl = readline.createInterface(stdin, autocomplete); | ||
stdin.on('data', function(buffer) { | ||
return repl.write(buffer); | ||
}); | ||
} else { | ||
repl = readline.createInterface(stdin, stdout, autocomplete); | ||
} | ||
} | ||
multilineMode = false; | ||
repl.input.on('keypress', function(char, key) { | ||
var cursorPos, newPrompt; | ||
if (!(key && key.ctrl && !key.meta && !key.shift && key.name === 'v')) { | ||
return; | ||
} | ||
cursorPos = repl.cursor; | ||
repl.output.cursorTo(0); | ||
repl.output.clearLine(1); | ||
multilineMode = !multilineMode; | ||
if (!multilineMode && backlog) { | ||
repl._line(); | ||
} | ||
backlog = ''; | ||
repl.setPrompt((newPrompt = multilineMode ? REPL_PROMPT_MULTILINE : REPL_PROMPT)); | ||
repl.prompt(); | ||
return repl.output.cursorTo(newPrompt.length + (repl.cursor = cursorPos)); | ||
}); | ||
repl.input.on('keypress', function(char, key) { | ||
if (!(multilineMode && repl.line)) { | ||
return; | ||
} | ||
if (!(key && key.ctrl && !key.meta && !key.shift && key.name === 'd')) { | ||
return; | ||
} | ||
multilineMode = false; | ||
return repl._line(); | ||
}); | ||
repl.on('attemptClose', function() { | ||
if (multilineMode) { | ||
multilineMode = false; | ||
repl.output.cursorTo(0); | ||
repl.output.clearLine(1); | ||
repl._onLine(repl.line); | ||
return; | ||
} | ||
if (backlog) { | ||
backlog = ''; | ||
process.stdout.write('\n'); | ||
repl.output.write('\n'); | ||
repl.setPrompt(REPL_PROMPT); | ||
@@ -146,4 +232,4 @@ return repl.prompt(); | ||
repl.on('close', function() { | ||
process.stdout.write('\n'); | ||
return stdin.destroy(); | ||
repl.output.write('\n'); | ||
return repl.input.destroy(); | ||
}); | ||
@@ -150,0 +236,0 @@ |
@@ -0,8 +1,11 @@ | ||
// Generated by CoffeeScript 1.3.0 | ||
(function() { | ||
var BALANCED_PAIRS, EXPRESSION_CLOSE, EXPRESSION_END, EXPRESSION_START, IMPLICIT_BLOCK, IMPLICIT_CALL, IMPLICIT_END, IMPLICIT_FUNC, IMPLICIT_UNSPACED_CALL, INVERSES, LINEBREAKS, SINGLE_CLOSERS, SINGLE_LINERS, left, rite, _i, _len, _ref, | ||
__indexOf = Array.prototype.indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; }, | ||
__slice = Array.prototype.slice; | ||
__indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; }, | ||
__slice = [].slice; | ||
exports.Rewriter = (function() { | ||
Rewriter.name = 'Rewriter'; | ||
function Rewriter() {} | ||
@@ -34,3 +37,3 @@ | ||
Rewriter.prototype.detectEnd = function(i, condition, action) { | ||
var levels, token, tokens, _ref, _ref2; | ||
var levels, token, tokens, _ref, _ref1; | ||
tokens = this.tokens; | ||
@@ -42,6 +45,8 @@ levels = 0; | ||
} | ||
if (!token || levels < 0) return action.call(this, token, i - 1); | ||
if (!token || levels < 0) { | ||
return action.call(this, token, i - 1); | ||
} | ||
if (_ref = token[0], __indexOf.call(EXPRESSION_START, _ref) >= 0) { | ||
levels += 1; | ||
} else if (_ref2 = token[0], __indexOf.call(EXPRESSION_END, _ref2) >= 0) { | ||
} else if (_ref1 = token[0], __indexOf.call(EXPRESSION_END, _ref1) >= 0) { | ||
levels -= 1; | ||
@@ -55,9 +60,13 @@ } | ||
Rewriter.prototype.removeLeadingNewlines = function() { | ||
var i, tag, _len, _ref; | ||
var i, tag, _i, _len, _ref; | ||
_ref = this.tokens; | ||
for (i = 0, _len = _ref.length; i < _len; i++) { | ||
for (i = _i = 0, _len = _ref.length; _i < _len; i = ++_i) { | ||
tag = _ref[i][0]; | ||
if (tag !== 'TERMINATOR') break; | ||
if (tag !== 'TERMINATOR') { | ||
break; | ||
} | ||
} | ||
if (i) return this.tokens.splice(0, i); | ||
if (i) { | ||
return this.tokens.splice(0, i); | ||
} | ||
}; | ||
@@ -86,3 +95,5 @@ | ||
return this.scanTokens(function(token, i) { | ||
if (token[0] === 'CALL_START') this.detectEnd(i + 1, condition, action); | ||
if (token[0] === 'CALL_START') { | ||
this.detectEnd(i + 1, condition, action); | ||
} | ||
return 1; | ||
@@ -102,3 +113,5 @@ }); | ||
return this.scanTokens(function(token, i) { | ||
if (token[0] === 'INDEX_START') this.detectEnd(i + 1, condition, action); | ||
if (token[0] === 'INDEX_START') { | ||
this.detectEnd(i + 1, condition, action); | ||
} | ||
return 1; | ||
@@ -116,17 +129,20 @@ }); | ||
condition = function(token, i) { | ||
var one, tag, three, two, _ref, _ref2; | ||
var one, tag, three, two, _ref, _ref1; | ||
_ref = this.tokens.slice(i + 1, (i + 3) + 1 || 9e9), one = _ref[0], two = _ref[1], three = _ref[2]; | ||
if ('HERECOMMENT' === (one != null ? one[0] : void 0)) return false; | ||
if ('HERECOMMENT' === (one != null ? one[0] : void 0)) { | ||
return false; | ||
} | ||
tag = token[0]; | ||
if (__indexOf.call(LINEBREAKS, tag) >= 0) sameLine = false; | ||
return (((tag === 'TERMINATOR' || tag === 'OUTDENT') || (__indexOf.call(IMPLICIT_END, tag) >= 0 && sameLine)) && ((!startsLine && this.tag(i - 1) !== ',') || !((two != null ? two[0] : void 0) === ':' || (one != null ? one[0] : void 0) === '@' && (three != null ? three[0] : void 0) === ':'))) || (tag === ',' && one && ((_ref2 = one[0]) !== 'IDENTIFIER' && _ref2 !== 'NUMBER' && _ref2 !== 'STRING' && _ref2 !== '@' && _ref2 !== 'TERMINATOR' && _ref2 !== 'OUTDENT')); | ||
if (__indexOf.call(LINEBREAKS, tag) >= 0) { | ||
sameLine = false; | ||
} | ||
return (((tag === 'TERMINATOR' || tag === 'OUTDENT') || (__indexOf.call(IMPLICIT_END, tag) >= 0 && sameLine)) && ((!startsLine && this.tag(i - 1) !== ',') || !((two != null ? two[0] : void 0) === ':' || (one != null ? one[0] : void 0) === '@' && (three != null ? three[0] : void 0) === ':'))) || (tag === ',' && one && ((_ref1 = one[0]) !== 'IDENTIFIER' && _ref1 !== 'NUMBER' && _ref1 !== 'STRING' && _ref1 !== '@' && _ref1 !== 'TERMINATOR' && _ref1 !== 'OUTDENT')); | ||
}; | ||
action = function(token, i) { | ||
var tok; | ||
tok = ['}', '}', token[2]]; | ||
tok.generated = true; | ||
tok = this.generate('}', '}', token[2]); | ||
return this.tokens.splice(i, 0, tok); | ||
}; | ||
return this.scanTokens(function(token, i, tokens) { | ||
var ago, idx, prevTag, tag, tok, value, _ref, _ref2; | ||
var ago, idx, prevTag, tag, tok, value, _ref, _ref1; | ||
if (_ref = (tag = token[0]), __indexOf.call(EXPRESSION_START, _ref) >= 0) { | ||
@@ -140,3 +156,3 @@ stack.push([(tag === 'INDENT' && this.tag(i - 1) === '{' ? '{' : tag), i]); | ||
} | ||
if (!(tag === ':' && ((ago = this.tag(i - 2)) === ':' || ((_ref2 = stack[stack.length - 1]) != null ? _ref2[0] : void 0) !== '{'))) { | ||
if (!(tag === ':' && ((ago = this.tag(i - 2)) === ':' || ((_ref1 = stack[stack.length - 1]) != null ? _ref1[0] : void 0) !== '{'))) { | ||
return 1; | ||
@@ -154,4 +170,3 @@ } | ||
value.generated = true; | ||
tok = ['{', value, token[2]]; | ||
tok.generated = true; | ||
tok = this.generate('{', value, token[2]); | ||
tokens.splice(idx, 0, tok); | ||
@@ -167,5 +182,7 @@ this.detectEnd(i + 2, condition, action); | ||
condition = function(token, i) { | ||
var post, tag, _ref, _ref2; | ||
var post, tag, _ref, _ref1; | ||
tag = token[0]; | ||
if (!seenSingle && token.fromThen) return true; | ||
if (!seenSingle && token.fromThen) { | ||
return true; | ||
} | ||
if (tag === 'IF' || tag === 'ELSE' || tag === 'CATCH' || tag === '->' || tag === '=>' || tag === 'CLASS') { | ||
@@ -180,24 +197,34 @@ seenSingle = true; | ||
} | ||
return !token.generated && this.tag(i - 1) !== ',' && (__indexOf.call(IMPLICIT_END, tag) >= 0 || (tag === 'INDENT' && !seenControl)) && (tag !== 'INDENT' || (((_ref = this.tag(i - 2)) !== 'CLASS' && _ref !== 'EXTENDS') && (_ref2 = this.tag(i - 1), __indexOf.call(IMPLICIT_BLOCK, _ref2) < 0) && !((post = this.tokens[i + 1]) && post.generated && post[0] === '{'))); | ||
return !token.generated && this.tag(i - 1) !== ',' && (__indexOf.call(IMPLICIT_END, tag) >= 0 || (tag === 'INDENT' && !seenControl)) && (tag !== 'INDENT' || (((_ref = this.tag(i - 2)) !== 'CLASS' && _ref !== 'EXTENDS') && (_ref1 = this.tag(i - 1), __indexOf.call(IMPLICIT_BLOCK, _ref1) < 0) && !((post = this.tokens[i + 1]) && post.generated && post[0] === '{'))); | ||
}; | ||
action = function(token, i) { | ||
return this.tokens.splice(i, 0, ['CALL_END', ')', token[2]]); | ||
return this.tokens.splice(i, 0, this.generate('CALL_END', ')', token[2])); | ||
}; | ||
return this.scanTokens(function(token, i, tokens) { | ||
var callObject, current, next, prev, tag, _ref, _ref2, _ref3; | ||
var callObject, current, next, prev, tag, _ref, _ref1, _ref2; | ||
tag = token[0]; | ||
if (tag === 'CLASS' || tag === 'IF') noCall = true; | ||
if (tag === 'CLASS' || tag === 'IF' || tag === 'FOR' || tag === 'WHILE') { | ||
noCall = true; | ||
} | ||
_ref = tokens.slice(i - 1, (i + 1) + 1 || 9e9), prev = _ref[0], current = _ref[1], next = _ref[2]; | ||
callObject = !noCall && tag === 'INDENT' && next && next.generated && next[0] === '{' && prev && (_ref2 = prev[0], __indexOf.call(IMPLICIT_FUNC, _ref2) >= 0); | ||
callObject = !noCall && tag === 'INDENT' && next && next.generated && next[0] === '{' && prev && (_ref1 = prev[0], __indexOf.call(IMPLICIT_FUNC, _ref1) >= 0); | ||
seenSingle = false; | ||
seenControl = false; | ||
if (__indexOf.call(LINEBREAKS, tag) >= 0) noCall = false; | ||
if (prev && !prev.spaced && tag === '?') token.call = true; | ||
if (token.fromThen) return 1; | ||
if (!(callObject || (prev != null ? prev.spaced : void 0) && (prev.call || (_ref3 = prev[0], __indexOf.call(IMPLICIT_FUNC, _ref3) >= 0)) && (__indexOf.call(IMPLICIT_CALL, tag) >= 0 || !(token.spaced || token.newLine) && __indexOf.call(IMPLICIT_UNSPACED_CALL, tag) >= 0))) { | ||
if (__indexOf.call(LINEBREAKS, tag) >= 0) { | ||
noCall = false; | ||
} | ||
if (prev && !prev.spaced && tag === '?') { | ||
token.call = true; | ||
} | ||
if (token.fromThen) { | ||
return 1; | ||
} | ||
tokens.splice(i, 0, ['CALL_START', '(', token[2]]); | ||
if (!(callObject || (prev != null ? prev.spaced : void 0) && (prev.call || (_ref2 = prev[0], __indexOf.call(IMPLICIT_FUNC, _ref2) >= 0)) && (__indexOf.call(IMPLICIT_CALL, tag) >= 0 || !(token.spaced || token.newLine) && __indexOf.call(IMPLICIT_UNSPACED_CALL, tag) >= 0))) { | ||
return 1; | ||
} | ||
tokens.splice(i, 0, this.generate('CALL_START', '(', token[2])); | ||
this.detectEnd(i + 1, condition, action); | ||
if (prev[0] === '?') prev[0] = 'FUNC_EXIST'; | ||
if (prev[0] === '?') { | ||
prev[0] = 'FUNC_EXIST'; | ||
} | ||
return 2; | ||
@@ -218,3 +245,3 @@ }); | ||
return this.scanTokens(function(token, i, tokens) { | ||
var tag, _ref, _ref2; | ||
var tag, _ref, _ref1; | ||
tag = token[0]; | ||
@@ -235,8 +262,11 @@ if (tag === 'TERMINATOR' && this.tag(i + 1) === 'THEN') { | ||
starter = tag; | ||
_ref2 = this.indentation(token), indent = _ref2[0], outdent = _ref2[1]; | ||
if (starter === 'THEN') indent.fromThen = true; | ||
indent.generated = outdent.generated = true; | ||
_ref1 = this.indentation(token, true), indent = _ref1[0], outdent = _ref1[1]; | ||
if (starter === 'THEN') { | ||
indent.fromThen = true; | ||
} | ||
tokens.splice(i + 1, 0, indent); | ||
this.detectEnd(i + 2, condition, action); | ||
if (tag === 'THEN') tokens.splice(i, 1); | ||
if (tag === 'THEN') { | ||
tokens.splice(i, 1); | ||
} | ||
return 1; | ||
@@ -261,3 +291,5 @@ } | ||
return this.scanTokens(function(token, i) { | ||
if (token[0] !== 'IF') return 1; | ||
if (token[0] !== 'IF') { | ||
return 1; | ||
} | ||
original = token; | ||
@@ -269,6 +301,22 @@ this.detectEnd(i + 1, condition, action); | ||
Rewriter.prototype.indentation = function(token) { | ||
return [['INDENT', 2, token[2]], ['OUTDENT', 2, token[2]]]; | ||
Rewriter.prototype.indentation = function(token, implicit) { | ||
var indent, outdent; | ||
if (implicit == null) { | ||
implicit = false; | ||
} | ||
indent = ['INDENT', 2, token[2]]; | ||
outdent = ['OUTDENT', 2, token[2]]; | ||
if (implicit) { | ||
indent.generated = outdent.generated = true; | ||
} | ||
return [indent, outdent]; | ||
}; | ||
Rewriter.prototype.generate = function(tag, value, line) { | ||
var tok; | ||
tok = [tag, value, line]; | ||
tok.generated = true; | ||
return tok; | ||
}; | ||
Rewriter.prototype.tag = function(i) { | ||
@@ -275,0 +323,0 @@ var _ref; |
@@ -0,1 +1,2 @@ | ||
// Generated by CoffeeScript 1.3.0 | ||
(function() { | ||
@@ -8,2 +9,4 @@ var Scope, extend, last, _ref; | ||
Scope.name = 'Scope'; | ||
Scope.root = null; | ||
@@ -22,7 +25,11 @@ | ||
this.positions = {}; | ||
if (!this.parent) Scope.root = this; | ||
if (!this.parent) { | ||
Scope.root = this; | ||
} | ||
} | ||
Scope.prototype.add = function(name, type, immediate) { | ||
if (this.shared && !immediate) return this.parent.add(name, type, immediate); | ||
if (this.shared && !immediate) { | ||
return this.parent.add(name, type, immediate); | ||
} | ||
if (Object.prototype.hasOwnProperty.call(this.positions, name)) { | ||
@@ -39,3 +46,5 @@ return this.variables[this.positions[name]].type = type; | ||
Scope.prototype.find = function(name, options) { | ||
if (this.check(name, options)) return true; | ||
if (this.check(name, options)) { | ||
return true; | ||
} | ||
this.add(name, 'var'); | ||
@@ -46,3 +55,5 @@ return false; | ||
Scope.prototype.parameter = function(name) { | ||
if (this.shared && this.parent.check(name, true)) return; | ||
if (this.shared && this.parent.check(name, true)) { | ||
return; | ||
} | ||
return this.add(name, 'param'); | ||
@@ -52,6 +63,8 @@ }; | ||
Scope.prototype.check = function(name, immediate) { | ||
var found, _ref2; | ||
var found, _ref1; | ||
found = !!this.type(name); | ||
if (found || immediate) return found; | ||
return !!((_ref2 = this.parent) != null ? _ref2.check(name) : void 0); | ||
if (found || immediate) { | ||
return found; | ||
} | ||
return !!((_ref1 = this.parent) != null ? _ref1.check(name) : void 0); | ||
}; | ||
@@ -61,3 +74,3 @@ | ||
if (name.length > 1) { | ||
return '_' + name + (index > 1 ? index : ''); | ||
return '_' + name + (index > 1 ? index - 1 : ''); | ||
} else { | ||
@@ -69,7 +82,9 @@ return '_' + (index + parseInt(name, 36)).toString(36).replace(/\d/g, 'a'); | ||
Scope.prototype.type = function(name) { | ||
var v, _i, _len, _ref2; | ||
_ref2 = this.variables; | ||
for (_i = 0, _len = _ref2.length; _i < _len; _i++) { | ||
v = _ref2[_i]; | ||
if (v.name === name) return v.type; | ||
var v, _i, _len, _ref1; | ||
_ref1 = this.variables; | ||
for (_i = 0, _len = _ref1.length; _i < _len; _i++) { | ||
v = _ref1[_i]; | ||
if (v.name === name) { | ||
return v.type; | ||
} | ||
} | ||
@@ -81,3 +96,5 @@ return null; | ||
var index, temp; | ||
if (reserve == null) reserve = true; | ||
if (reserve == null) { | ||
reserve = true; | ||
} | ||
index = 0; | ||
@@ -87,3 +104,5 @@ while (this.check((temp = this.temporary(name, index)))) { | ||
} | ||
if (reserve) this.add(temp, 'var', true); | ||
if (reserve) { | ||
this.add(temp, 'var', true); | ||
} | ||
return temp; | ||
@@ -105,8 +124,8 @@ }; | ||
Scope.prototype.declaredVariables = function() { | ||
var realVars, tempVars, v, _i, _len, _ref2; | ||
var realVars, tempVars, v, _i, _len, _ref1; | ||
realVars = []; | ||
tempVars = []; | ||
_ref2 = this.variables; | ||
for (_i = 0, _len = _ref2.length; _i < _len; _i++) { | ||
v = _ref2[_i]; | ||
_ref1 = this.variables; | ||
for (_i = 0, _len = _ref1.length; _i < _len; _i++) { | ||
v = _ref1[_i]; | ||
if (v.type === 'var') { | ||
@@ -120,8 +139,10 @@ (v.name.charAt(0) === '_' ? tempVars : realVars).push(v.name); | ||
Scope.prototype.assignedVariables = function() { | ||
var v, _i, _len, _ref2, _results; | ||
_ref2 = this.variables; | ||
var v, _i, _len, _ref1, _results; | ||
_ref1 = this.variables; | ||
_results = []; | ||
for (_i = 0, _len = _ref2.length; _i < _len; _i++) { | ||
v = _ref2[_i]; | ||
if (v.type.assigned) _results.push("" + v.name + " = " + v.type.value); | ||
for (_i = 0, _len = _ref1.length; _i < _len; _i++) { | ||
v = _ref1[_i]; | ||
if (v.type.assigned) { | ||
_results.push("" + v.name + " = " + v.type.value); | ||
} | ||
} | ||
@@ -128,0 +149,0 @@ return _results; |
@@ -6,3 +6,3 @@ { | ||
"author": "Jeremy Ashkenas", | ||
"version": "1.2.0", | ||
"version": "1.3.0", | ||
"licenses": [{ | ||
@@ -9,0 +9,0 @@ "type": "MIT", |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
304629
23
6462