├── .notesrc ├── Cakefile ├── README.md ├── bin └── notes ├── lib └── notes.js ├── node_modules ├── .bin │ ├── cake │ └── coffee ├── coffee-script │ ├── .npmignore │ ├── LICENSE │ ├── README │ ├── Rakefile │ ├── bin │ │ ├── cake │ │ └── coffee │ ├── lib │ │ ├── browser.js │ │ ├── cake.js │ │ ├── coffee-script.js │ │ ├── command.js │ │ ├── grammar.js │ │ ├── helpers.js │ │ ├── index.js │ │ ├── lexer.js │ │ ├── nodes.js │ │ ├── optparse.js │ │ ├── parser.js │ │ ├── repl.js │ │ ├── rewriter.js │ │ └── scope.js │ └── package.json └── colors │ ├── MIT-LICENSE.txt │ ├── ReadMe.md │ ├── colors.js │ ├── example.html │ ├── example.js │ └── package.json ├── package.json └── src └── notes.coffee /.notesrc: -------------------------------------------------------------------------------- 1 | bin 2 | src 3 | -------------------------------------------------------------------------------- /Cakefile: -------------------------------------------------------------------------------- 1 | {exec} = require 'child_process' 2 | Notes = require './lib/notes' 3 | 4 | task 'build', 'Build project from src/*.coffee to lib/*.js', -> 5 | exec 'coffee --compile --output lib/ src/', (error, stdout, stderr) -> 6 | if error 7 | console.log "build failed: #{error}" 8 | throw error 9 | console.log "build complete. #{stdout} #{stderr}" 10 | 11 | task 'notes', 'Print out notes from project', -> 12 | notes = new Notes(__dirname) 13 | notes.annotate() 14 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | node-notes is a node.js version of Rails' "rake notes" functionality. It allows you 2 | to put comments in your code and then have them annotated across your whole project. 3 | 4 | ### Installation: 5 | 6 | 7 | npm install notes -g 8 | 9 | ### Usage: 10 | 11 | $ notes # will search for notes in cwd 12 | $ notes lib/ test/ # will search only in lib and test 13 | 14 | ### What It Does: 15 | 16 | For example, if a file contained these lines somewhere in it: 17 | 18 | code... 19 | # NOTE: This line should get annoated by Notes. 20 | # OPTIMIZE Make things faster! 21 | 22 | more code... 23 | # TODO: Annotate your tasks. 24 | 25 | yet more code... 26 | # FIXME: Keep up with things to fix. 27 | 28 | Those comments would be annotated as: 29 | 30 | * /path/to/my/file 31 | Line 8: ✐ NOTE This line should get annoated by Notes. 32 | Line 9: ↘ OPTIMIZE Make things faster! 33 | Line 10: ✓ TODO Annotate your tasks. 34 | Line 11: ☂ FIXME Keep up with things to fix. 35 | -------------------------------------------------------------------------------- /bin/notes: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | /** 4 | * Core dependencies. 5 | */ 6 | var fs = require('fs'); 7 | var path = require('path'); 8 | 9 | /** 10 | * Notes. 11 | * 12 | * @type {Function} 13 | */ 14 | var Notes = require('../lib/notes'); 15 | 16 | /** 17 | * Argv. 18 | * 19 | * @type {Array} 20 | */ 21 | var argv = process.argv.slice(2, process.argv.length); 22 | 23 | /** 24 | * Current working directory. 25 | * 26 | * @type {String} 27 | */ 28 | var cwd = process.cwd(); 29 | 30 | /** 31 | * Runtime configurations path. 32 | * 33 | * @type {String} 34 | */ 35 | var rc = path.join(cwd, '.notesrc'); 36 | 37 | if (0 !== argv.length) { 38 | return argv.forEach(function(arg) { 39 | new Notes(arg).annotate(); 40 | }); 41 | } 42 | 43 | if (!fs.existsSync(rc)) { 44 | return new Notes(cwd).annotate(); 45 | } 46 | 47 | fs.readFileSync(rc, 'utf8').trim().split(/\s+/).forEach(function(directory) { 48 | new Notes(directory).annotate(); 49 | }); 50 | -------------------------------------------------------------------------------- /lib/notes.js: -------------------------------------------------------------------------------- 1 | // Generated by CoffeeScript 1.10.0 2 | (function() { 3 | var Notes, colors, fs; 4 | 5 | fs = require('fs'); 6 | 7 | colors = require('colors'); 8 | 9 | Notes = (function() { 10 | var eachLineIn, filesUnderDirectory; 11 | 12 | Notes.patterns = { 13 | todo: { 14 | regexp: /^.*(#|\/\/|\/\*)\s*TODO\W*/i, 15 | label: "✓ TODO".underline.magenta 16 | }, 17 | note: { 18 | regexp: /^.*(#|\/\/|\/\*)\s*NOTE\W*/i, 19 | label: "✐ NOTE".underline.blue 20 | }, 21 | optimize: { 22 | regexp: /^.*(#|\/\/|\/\*)\s*OPTIMIZE\W*/i, 23 | label: "↘ OPTIMIZE".underline.yellow 24 | }, 25 | fixme: { 26 | regexp: /^.*(#|\/\/|\/\*)\s*FIXME\W*/i, 27 | label: "☂ FIXME".underline.red 28 | } 29 | }; 30 | 31 | Notes.filterExtensions = ["\\.jpg", "\\.jpeg", "\\.mov", "\\.mp3", "\\.gif", "\\.png", "\\.log", "\\.bin", "\\.psd", "\\.swf", "\\.fla", "\\.ico"]; 32 | 33 | Notes.filterDirectories = ["node_modules"]; 34 | 35 | Notes.skipHidden = true; 36 | 37 | Notes.concurrentFiles = 30; 38 | 39 | function Notes(rootDir) { 40 | this.rootDir = rootDir; 41 | if (!this.rootDir) { 42 | throw "Root directory is required."; 43 | } 44 | } 45 | 46 | Notes.prototype.annotate = function() { 47 | var concurrency, files, output, run; 48 | files = []; 49 | filesUnderDirectory(this.rootDir, function(file) { 50 | return files.push(file); 51 | }); 52 | concurrency = 0; 53 | output = {}; 54 | run = function() { 55 | var file, onCompletion, onLine, results; 56 | results = []; 57 | while (files.length > 0 && concurrency < Notes.concurrentFiles) { 58 | onLine = function(line, lineNum, filePath) { 59 | var j, key, len, lineNumStr, n, pattern, ref, ref1, results1, spaces; 60 | ref = Notes.patterns; 61 | results1 = []; 62 | for (key in ref) { 63 | pattern = ref[key]; 64 | if (line.match(pattern.regexp) != null) { 65 | if (output[filePath] == null) { 66 | output[filePath] = ("* " + (filePath.replace('//', '/')) + "\n").green; 67 | } 68 | line = line.replace(pattern.regexp, ''); 69 | spaces = ' '; 70 | ref1 = (lineNum + 1).toString(); 71 | for (j = 0, len = ref1.length; j < len; j++) { 72 | n = ref1[j]; 73 | spaces = spaces.substring(0, spaces.length - 1); 74 | } 75 | lineNumStr = ("Line " + lineNum + ":").grey; 76 | results1.push(output[filePath] += " " + lineNumStr + spaces + pattern.label + " " + line + "\n"); 77 | } else { 78 | results1.push(void 0); 79 | } 80 | } 81 | return results1; 82 | }; 83 | onCompletion = function(filePath) { 84 | if (output[filePath] != null) { 85 | console.log(output[filePath]); 86 | } 87 | concurrency--; 88 | return run(); 89 | }; 90 | file = files.shift(); 91 | eachLineIn(file, onLine, onCompletion); 92 | results.push(concurrency++); 93 | } 94 | return results; 95 | }; 96 | return run(); 97 | }; 98 | 99 | filesUnderDirectory = function(dir, fileCallback) { 100 | var error, error1, f, files, filter, j, len, results; 101 | try { 102 | files = fs.readdirSync(dir); 103 | if (files != null) { 104 | if (Notes.skipHidden) { 105 | files = (function() { 106 | var j, len, results; 107 | results = []; 108 | for (j = 0, len = files.length; j < len; j++) { 109 | f = files[j]; 110 | if (!f.match(/^\./)) { 111 | results.push(f); 112 | } 113 | } 114 | return results; 115 | })(); 116 | } 117 | files = (function() { 118 | var j, len, results; 119 | results = []; 120 | for (j = 0, len = files.length; j < len; j++) { 121 | f = files[j]; 122 | if (Notes.filterDirectories.indexOf(f) < 0) { 123 | results.push(f); 124 | } 125 | } 126 | return results; 127 | })(); 128 | results = []; 129 | for (j = 0, len = files.length; j < len; j++) { 130 | f = files[j]; 131 | results.push(filesUnderDirectory(dir + "/" + f, fileCallback)); 132 | } 133 | return results; 134 | } 135 | } catch (error1) { 136 | error = error1; 137 | if (error.code === "ENOTDIR") { 138 | filter = RegExp("(" + (Notes.filterExtensions.join('|')) + ")$"); 139 | if (!dir.match(filter)) { 140 | return fileCallback(dir); 141 | } 142 | } else if (error.code === "ELOOP") { 143 | return console.log(error + "... continuing."); 144 | } else { 145 | throw error; 146 | } 147 | } 148 | }; 149 | 150 | eachLineIn = function(filePath, onLine, onCompletion) { 151 | return fs.readFile(filePath, function(err, data) { 152 | var i, j, len, line, lines; 153 | if (err != null) { 154 | throw err; 155 | } 156 | lines = data.toString('utf-8').split("\n"); 157 | for (i = j = 0, len = lines.length; j < len; i = ++j) { 158 | line = lines[i]; 159 | onLine(line, i + 1, filePath); 160 | } 161 | return onCompletion(filePath); 162 | }); 163 | }; 164 | 165 | return Notes; 166 | 167 | })(); 168 | 169 | module.exports = Notes; 170 | 171 | }).call(this); 172 | -------------------------------------------------------------------------------- /node_modules/.bin/cake: -------------------------------------------------------------------------------- 1 | ../coffee-script/bin/cake -------------------------------------------------------------------------------- /node_modules/.bin/coffee: -------------------------------------------------------------------------------- 1 | ../coffee-script/bin/coffee -------------------------------------------------------------------------------- /node_modules/coffee-script/.npmignore: -------------------------------------------------------------------------------- 1 | *.coffee 2 | *.html 3 | .DS_Store 4 | .git* 5 | Cakefile 6 | documentation/ 7 | examples/ 8 | extras/ 9 | raw/ 10 | src/ 11 | test/ 12 | -------------------------------------------------------------------------------- /node_modules/coffee-script/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2011 Jeremy Ashkenas 2 | 3 | Permission is hereby granted, free of charge, to any person 4 | obtaining a copy of this software and associated documentation 5 | files (the "Software"), to deal in the Software without 6 | restriction, including without limitation the rights to use, 7 | copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the 9 | Software is furnished to do so, subject to the following 10 | conditions: 11 | 12 | The above copyright notice and this permission notice shall be 13 | included in all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 17 | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 19 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 20 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 21 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 22 | OTHER DEALINGS IN THE SOFTWARE. -------------------------------------------------------------------------------- /node_modules/coffee-script/README: -------------------------------------------------------------------------------- 1 | = 2 | { 3 | } } { 4 | { { } } 5 | } }{ { 6 | { }{ } } _____ __ __ 7 | ( }{ }{ { ) / ____| / _|/ _| 8 | .- { { } { }} -. | | ___ | |_| |_ ___ ___ 9 | ( ( } { } { } } ) | | / _ \| _| _/ _ \/ _ \ 10 | |`-..________ ..-'| | |___| (_) | | | || __/ __/ 11 | | | \_____\___/|_| |_| \___|\___| 12 | | ;--. 13 | | (__ \ _____ _ _ 14 | | | ) ) / ____| (_) | | 15 | | |/ / | (___ ___ _ __ _ _ __ | |_ 16 | | ( / \___ \ / __| '__| | '_ \| __| 17 | | |/ ____) | (__| | | | |_) | |_ 18 | | | |_____/ \___|_| |_| .__/ \__| 19 | `-.._________..-' | | 20 | |_| 21 | 22 | 23 | CoffeeScript is a little language that compiles into JavaScript. 24 | 25 | Install Node.js, and then the CoffeeScript compiler: 26 | sudo bin/cake install 27 | 28 | Or, if you have the Node Package Manager installed: 29 | npm install -g coffee-script 30 | (Leave off the -g if you don't wish to install globally.) 31 | 32 | Compile a script: 33 | coffee /path/to/script.coffee 34 | 35 | For documentation, usage, and examples, see: 36 | http://coffeescript.org/ 37 | 38 | To suggest a feature, report a bug, or general discussion: 39 | http://github.com/jashkenas/coffee-script/issues/ 40 | 41 | If you'd like to chat, drop by #coffeescript on Freenode IRC, 42 | or on webchat.freenode.net. 43 | 44 | The source repository: 45 | git://github.com/jashkenas/coffee-script.git 46 | 47 | All contributors are listed here: 48 | http://github.com/jashkenas/coffee-script/contributors 49 | -------------------------------------------------------------------------------- /node_modules/coffee-script/Rakefile: -------------------------------------------------------------------------------- 1 | require 'rubygems' 2 | require 'erb' 3 | require 'fileutils' 4 | require 'rake/testtask' 5 | require 'json' 6 | 7 | desc "Build the documentation page" 8 | task :doc do 9 | source = 'documentation/index.html.erb' 10 | child = fork { exec "bin/coffee -bcw -o documentation/js documentation/coffee/*.coffee" } 11 | at_exit { Process.kill("INT", child) } 12 | Signal.trap("INT") { exit } 13 | loop do 14 | mtime = File.stat(source).mtime 15 | if !@mtime || mtime > @mtime 16 | rendered = ERB.new(File.read(source)).result(binding) 17 | File.open('index.html', 'w+') {|f| f.write(rendered) } 18 | end 19 | @mtime = mtime 20 | sleep 1 21 | end 22 | end 23 | 24 | desc "Build coffee-script-source gem" 25 | task :gem do 26 | require 'rubygems' 27 | require 'rubygems/package' 28 | 29 | gemspec = Gem::Specification.new do |s| 30 | s.name = 'coffee-script-source' 31 | s.version = JSON.parse(File.read('package.json'))["version"] 32 | s.date = Time.now.strftime("%Y-%m-%d") 33 | 34 | s.homepage = "http://jashkenas.github.com/coffee-script/" 35 | s.summary = "The CoffeeScript Compiler" 36 | s.description = <<-EOS 37 | CoffeeScript is a little language that compiles into JavaScript. 38 | Underneath all of those embarrassing braces and semicolons, 39 | JavaScript has always had a gorgeous object model at its heart. 40 | CoffeeScript is an attempt to expose the good parts of JavaScript 41 | in a simple way. 42 | EOS 43 | 44 | s.files = [ 45 | 'lib/coffee_script/coffee-script.js', 46 | 'lib/coffee_script/source.rb' 47 | ] 48 | 49 | s.authors = ['Jeremy Ashkenas'] 50 | s.email = 'jashkenas@gmail.com' 51 | s.rubyforge_project = 'coffee-script-source' 52 | end 53 | 54 | file = File.open("coffee-script-source.gem", "w") 55 | Gem::Package.open(file, 'w') do |pkg| 56 | pkg.metadata = gemspec.to_yaml 57 | 58 | path = "lib/coffee_script/source.rb" 59 | contents = <<-ERUBY 60 | module CoffeeScript 61 | module Source 62 | def self.bundled_path 63 | File.expand_path("../coffee-script.js", __FILE__) 64 | end 65 | end 66 | end 67 | ERUBY 68 | pkg.add_file_simple(path, 0644, contents.size) do |tar_io| 69 | tar_io.write(contents) 70 | end 71 | 72 | contents = File.read("extras/coffee-script.js") 73 | path = "lib/coffee_script/coffee-script.js" 74 | pkg.add_file_simple(path, 0644, contents.size) do |tar_io| 75 | tar_io.write(contents) 76 | end 77 | end 78 | end 79 | -------------------------------------------------------------------------------- /node_modules/coffee-script/bin/cake: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | var path = require('path'); 4 | var fs = require('fs'); 5 | var lib = path.join(path.dirname(fs.realpathSync(__filename)), '../lib'); 6 | 7 | require(lib + '/cake').run(); 8 | -------------------------------------------------------------------------------- /node_modules/coffee-script/bin/coffee: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | var path = require('path'); 4 | var fs = require('fs'); 5 | var lib = path.join(path.dirname(fs.realpathSync(__filename)), '../lib'); 6 | 7 | require(lib + '/command').run(); 8 | -------------------------------------------------------------------------------- /node_modules/coffee-script/lib/browser.js: -------------------------------------------------------------------------------- 1 | (function() { 2 | var CoffeeScript, runScripts; 3 | CoffeeScript = require('./coffee-script'); 4 | CoffeeScript.require = require; 5 | CoffeeScript.eval = function(code, options) { 6 | return eval(CoffeeScript.compile(code, options)); 7 | }; 8 | CoffeeScript.run = function(code, options) { 9 | if (options == null) { 10 | options = {}; 11 | } 12 | options.bare = true; 13 | return Function(CoffeeScript.compile(code, options))(); 14 | }; 15 | if (typeof window === "undefined" || window === null) { 16 | return; 17 | } 18 | CoffeeScript.load = function(url, callback) { 19 | var xhr; 20 | xhr = new (window.ActiveXObject || XMLHttpRequest)('Microsoft.XMLHTTP'); 21 | xhr.open('GET', url, true); 22 | if ('overrideMimeType' in xhr) { 23 | xhr.overrideMimeType('text/plain'); 24 | } 25 | xhr.onreadystatechange = function() { 26 | var _ref; 27 | if (xhr.readyState === 4) { 28 | if ((_ref = xhr.status) === 0 || _ref === 200) { 29 | CoffeeScript.run(xhr.responseText); 30 | } else { 31 | throw new Error("Could not load " + url); 32 | } 33 | if (callback) { 34 | return callback(); 35 | } 36 | } 37 | }; 38 | return xhr.send(null); 39 | }; 40 | runScripts = function() { 41 | var coffees, execute, index, length, s, scripts; 42 | scripts = document.getElementsByTagName('script'); 43 | coffees = (function() { 44 | var _i, _len, _results; 45 | _results = []; 46 | for (_i = 0, _len = scripts.length; _i < _len; _i++) { 47 | s = scripts[_i]; 48 | if (s.type === 'text/coffeescript') { 49 | _results.push(s); 50 | } 51 | } 52 | return _results; 53 | })(); 54 | index = 0; 55 | length = coffees.length; 56 | (execute = function() { 57 | var script; 58 | script = coffees[index++]; 59 | if ((script != null ? script.type : void 0) === 'text/coffeescript') { 60 | if (script.src) { 61 | return CoffeeScript.load(script.src, execute); 62 | } else { 63 | CoffeeScript.run(script.innerHTML); 64 | return execute(); 65 | } 66 | } 67 | })(); 68 | return null; 69 | }; 70 | if (window.addEventListener) { 71 | addEventListener('DOMContentLoaded', runScripts, false); 72 | } else { 73 | attachEvent('onload', runScripts); 74 | } 75 | }).call(this); 76 | -------------------------------------------------------------------------------- /node_modules/coffee-script/lib/cake.js: -------------------------------------------------------------------------------- 1 | (function() { 2 | var CoffeeScript, fs, helpers, missingTask, oparse, options, optparse, path, printTasks, switches, tasks; 3 | fs = require('fs'); 4 | path = require('path'); 5 | helpers = require('./helpers'); 6 | optparse = require('./optparse'); 7 | CoffeeScript = require('./coffee-script'); 8 | tasks = {}; 9 | options = {}; 10 | switches = []; 11 | oparse = null; 12 | helpers.extend(global, { 13 | task: function(name, description, action) { 14 | var _ref; 15 | if (!action) { 16 | _ref = [description, action], action = _ref[0], description = _ref[1]; 17 | } 18 | return tasks[name] = { 19 | name: name, 20 | description: description, 21 | action: action 22 | }; 23 | }, 24 | option: function(letter, flag, description) { 25 | return switches.push([letter, flag, description]); 26 | }, 27 | invoke: function(name) { 28 | if (!tasks[name]) { 29 | missingTask(name); 30 | } 31 | return tasks[name].action(options); 32 | } 33 | }); 34 | exports.run = function() { 35 | return path.exists('Cakefile', function(exists) { 36 | var arg, args, _i, _len, _ref, _results; 37 | if (!exists) { 38 | throw new Error("Cakefile not found in " + (process.cwd())); 39 | } 40 | args = process.argv.slice(2); 41 | CoffeeScript.run(fs.readFileSync('Cakefile').toString(), { 42 | filename: 'Cakefile' 43 | }); 44 | oparse = new optparse.OptionParser(switches); 45 | if (!args.length) { 46 | return printTasks(); 47 | } 48 | options = oparse.parse(args); 49 | _ref = options.arguments; 50 | _results = []; 51 | for (_i = 0, _len = _ref.length; _i < _len; _i++) { 52 | arg = _ref[_i]; 53 | _results.push(invoke(arg)); 54 | } 55 | return _results; 56 | }); 57 | }; 58 | printTasks = function() { 59 | var desc, name, spaces, task; 60 | console.log(''); 61 | for (name in tasks) { 62 | task = tasks[name]; 63 | spaces = 20 - name.length; 64 | spaces = spaces > 0 ? Array(spaces + 1).join(' ') : ''; 65 | desc = task.description ? "# " + task.description : ''; 66 | console.log("cake " + name + spaces + " " + desc); 67 | } 68 | if (switches.length) { 69 | return console.log(oparse.help()); 70 | } 71 | }; 72 | missingTask = function(task) { 73 | console.log("No such task: \"" + task + "\""); 74 | return process.exit(1); 75 | }; 76 | }).call(this); 77 | -------------------------------------------------------------------------------- /node_modules/coffee-script/lib/coffee-script.js: -------------------------------------------------------------------------------- 1 | (function() { 2 | var Lexer, RESERVED, compile, fs, lexer, parser, path, vm, _ref; 3 | fs = require('fs'); 4 | path = require('path'); 5 | vm = require('vm'); 6 | _ref = require('./lexer'), Lexer = _ref.Lexer, RESERVED = _ref.RESERVED; 7 | parser = require('./parser').parser; 8 | if (require.extensions) { 9 | require.extensions['.coffee'] = function(module, filename) { 10 | var content; 11 | content = compile(fs.readFileSync(filename, 'utf8'), { 12 | filename: filename 13 | }); 14 | return module._compile(content, filename); 15 | }; 16 | } else if (require.registerExtension) { 17 | require.registerExtension('.coffee', function(content) { 18 | return compile(content); 19 | }); 20 | } 21 | exports.VERSION = '1.1.1'; 22 | exports.RESERVED = RESERVED; 23 | exports.helpers = require('./helpers'); 24 | exports.compile = compile = function(code, options) { 25 | if (options == null) { 26 | options = {}; 27 | } 28 | try { 29 | return (parser.parse(lexer.tokenize(code))).compile(options); 30 | } catch (err) { 31 | if (options.filename) { 32 | err.message = "In " + options.filename + ", " + err.message; 33 | } 34 | throw err; 35 | } 36 | }; 37 | exports.tokens = function(code, options) { 38 | return lexer.tokenize(code, options); 39 | }; 40 | exports.nodes = function(source, options) { 41 | if (typeof source === 'string') { 42 | return parser.parse(lexer.tokenize(source, options)); 43 | } else { 44 | return parser.parse(source); 45 | } 46 | }; 47 | exports.run = function(code, options) { 48 | var Module, root; 49 | root = module; 50 | while (root.parent) { 51 | root = root.parent; 52 | } 53 | root.filename = process.argv[1] = options.filename ? fs.realpathSync(options.filename) : '.'; 54 | if (root.moduleCache) { 55 | root.moduleCache = {}; 56 | } 57 | if (process.binding('natives').module) { 58 | Module = require('module').Module; 59 | root.paths = Module._nodeModulePaths(path.dirname(options.filename)); 60 | } 61 | if (path.extname(root.filename) !== '.coffee' || require.extensions) { 62 | return root._compile(compile(code, options), root.filename); 63 | } else { 64 | return root._compile(code, root.filename); 65 | } 66 | }; 67 | exports.eval = function(code, options) { 68 | var g, js, sandbox; 69 | if (options == null) { 70 | options = {}; 71 | } 72 | sandbox = options.sandbox; 73 | if (!sandbox) { 74 | sandbox = { 75 | require: require, 76 | module: { 77 | exports: {} 78 | } 79 | }; 80 | for (g in global) { 81 | sandbox[g] = global[g]; 82 | } 83 | sandbox.global = sandbox; 84 | sandbox.global.global = sandbox.global.root = sandbox.global.GLOBAL = sandbox; 85 | } 86 | sandbox.__filename = options.filename || 'eval'; 87 | sandbox.__dirname = path.dirname(sandbox.__filename); 88 | js = compile("_=(" + (code.trim()) + ")", options); 89 | return vm.runInNewContext(js, sandbox, sandbox.__filename); 90 | }; 91 | lexer = new Lexer; 92 | parser.lexer = { 93 | lex: function() { 94 | var tag, _ref2; 95 | _ref2 = this.tokens[this.pos++] || [''], tag = _ref2[0], this.yytext = _ref2[1], this.yylineno = _ref2[2]; 96 | return tag; 97 | }, 98 | setInput: function(tokens) { 99 | this.tokens = tokens; 100 | return this.pos = 0; 101 | }, 102 | upcomingInput: function() { 103 | return ""; 104 | } 105 | }; 106 | parser.yy = require('./nodes'); 107 | }).call(this); 108 | -------------------------------------------------------------------------------- /node_modules/coffee-script/lib/command.js: -------------------------------------------------------------------------------- 1 | (function() { 2 | var BANNER, CoffeeScript, EventEmitter, SWITCHES, compileJoin, compileOptions, compileScript, compileScripts, compileStdio, contents, exec, forkNode, fs, helpers, lint, loadRequires, optionParser, optparse, opts, parseOptions, path, printLine, printTokens, printWarn, sources, spawn, usage, version, watch, writeJs, _ref; 3 | fs = require('fs'); 4 | path = require('path'); 5 | helpers = require('./helpers'); 6 | optparse = require('./optparse'); 7 | CoffeeScript = require('./coffee-script'); 8 | _ref = require('child_process'), spawn = _ref.spawn, exec = _ref.exec; 9 | EventEmitter = require('events').EventEmitter; 10 | helpers.extend(CoffeeScript, new EventEmitter); 11 | printLine = function(line) { 12 | return process.stdout.write(line + '\n'); 13 | }; 14 | printWarn = function(line) { 15 | return process.binding('stdio').writeError(line + '\n'); 16 | }; 17 | BANNER = 'Usage: coffee [options] path/to/script.coffee'; 18 | SWITCHES = [['-c', '--compile', 'compile to JavaScript and save as .js files'], ['-i', '--interactive', 'run an interactive CoffeeScript REPL'], ['-o', '--output [DIR]', 'set the directory for compiled JavaScript'], ['-j', '--join [FILE]', 'concatenate the scripts before compiling'], ['-w', '--watch', 'watch scripts for changes, and recompile'], ['-p', '--print', 'print the compiled JavaScript to stdout'], ['-l', '--lint', 'pipe the compiled JavaScript through JavaScript Lint'], ['-s', '--stdio', 'listen for and compile scripts over stdio'], ['-e', '--eval', 'compile a string from the command line'], ['-r', '--require [FILE*]', 'require a library before executing your script'], ['-b', '--bare', 'compile without the top-level function wrapper'], ['-t', '--tokens', 'print the tokens that the lexer produces'], ['-n', '--nodes', 'print the parse tree that Jison produces'], ['--nodejs [ARGS]', 'pass options through to the "node" binary'], ['-v', '--version', 'display CoffeeScript version'], ['-h', '--help', 'display this help message']]; 19 | opts = {}; 20 | sources = []; 21 | contents = []; 22 | optionParser = null; 23 | exports.run = function() { 24 | parseOptions(); 25 | if (opts.nodejs) { 26 | return forkNode(); 27 | } 28 | if (opts.help) { 29 | return usage(); 30 | } 31 | if (opts.version) { 32 | return version(); 33 | } 34 | if (opts.require) { 35 | loadRequires(); 36 | } 37 | if (opts.interactive) { 38 | return require('./repl'); 39 | } 40 | if (opts.stdio) { 41 | return compileStdio(); 42 | } 43 | if (opts.eval) { 44 | return compileScript(null, sources[0]); 45 | } 46 | if (!sources.length) { 47 | return require('./repl'); 48 | } 49 | if (opts.run) { 50 | opts.literals = sources.splice(1).concat(opts.literals); 51 | } 52 | process.ARGV = process.argv = process.argv.slice(0, 2).concat(opts.literals); 53 | process.argv[0] = 'coffee'; 54 | process.execPath = require.main.filename; 55 | return compileScripts(); 56 | }; 57 | compileScripts = function() { 58 | var base, compile, source, _i, _len, _results; 59 | _results = []; 60 | for (_i = 0, _len = sources.length; _i < _len; _i++) { 61 | source = sources[_i]; 62 | base = path.join(source); 63 | compile = function(source, topLevel) { 64 | return path.exists(source, function(exists) { 65 | if (topLevel && !exists) { 66 | throw new Error("File not found: " + source); 67 | } 68 | return fs.stat(source, function(err, stats) { 69 | if (err) { 70 | throw err; 71 | } 72 | if (stats.isDirectory()) { 73 | return fs.readdir(source, function(err, files) { 74 | var file, _j, _len2, _results2; 75 | _results2 = []; 76 | for (_j = 0, _len2 = files.length; _j < _len2; _j++) { 77 | file = files[_j]; 78 | _results2.push(compile(path.join(source, file))); 79 | } 80 | return _results2; 81 | }); 82 | } else if (topLevel || path.extname(source) === '.coffee') { 83 | fs.readFile(source, function(err, code) { 84 | if (opts.join) { 85 | contents[sources.indexOf(source)] = code.toString(); 86 | if (helpers.compact(contents).length > 0) { 87 | return compileJoin(); 88 | } 89 | } else { 90 | return compileScript(source, code.toString(), base); 91 | } 92 | }); 93 | if (opts.watch && !opts.join) { 94 | return watch(source, base); 95 | } 96 | } 97 | }); 98 | }); 99 | }; 100 | _results.push(compile(source, true)); 101 | } 102 | return _results; 103 | }; 104 | compileScript = function(file, input, base) { 105 | var o, options, t, task; 106 | o = opts; 107 | options = compileOptions(file); 108 | try { 109 | t = task = { 110 | file: file, 111 | input: input, 112 | options: options 113 | }; 114 | CoffeeScript.emit('compile', task); 115 | if (o.tokens) { 116 | return printTokens(CoffeeScript.tokens(t.input)); 117 | } else if (o.nodes) { 118 | return printLine(CoffeeScript.nodes(t.input).toString().trim()); 119 | } else if (o.run) { 120 | return CoffeeScript.run(t.input, t.options); 121 | } else { 122 | t.output = CoffeeScript.compile(t.input, t.options); 123 | CoffeeScript.emit('success', task); 124 | if (o.print) { 125 | return printLine(t.output.trim()); 126 | } else if (o.compile) { 127 | return writeJs(t.file, t.output, base); 128 | } else if (o.lint) { 129 | return lint(t.file, t.output); 130 | } 131 | } 132 | } catch (err) { 133 | CoffeeScript.emit('failure', err, task); 134 | if (CoffeeScript.listeners('failure').length) { 135 | return; 136 | } 137 | if (o.watch) { 138 | return printLine(err.message); 139 | } 140 | printWarn(err.stack); 141 | return process.exit(1); 142 | } 143 | }; 144 | compileStdio = function() { 145 | var code, stdin; 146 | code = ''; 147 | stdin = process.openStdin(); 148 | stdin.on('data', function(buffer) { 149 | if (buffer) { 150 | return code += buffer.toString(); 151 | } 152 | }); 153 | return stdin.on('end', function() { 154 | return compileScript(null, code); 155 | }); 156 | }; 157 | compileJoin = function() { 158 | var code; 159 | code = contents.join('\n'); 160 | return compileScript(opts.join, code, opts.join); 161 | }; 162 | loadRequires = function() { 163 | var realFilename, req, _i, _len, _ref2; 164 | realFilename = module.filename; 165 | module.filename = '.'; 166 | _ref2 = opts.require; 167 | for (_i = 0, _len = _ref2.length; _i < _len; _i++) { 168 | req = _ref2[_i]; 169 | require(req); 170 | } 171 | return module.filename = realFilename; 172 | }; 173 | watch = function(source, base) { 174 | return fs.watchFile(source, { 175 | persistent: true, 176 | interval: 500 177 | }, function(curr, prev) { 178 | if (curr.size === prev.size && curr.mtime.getTime() === prev.mtime.getTime()) { 179 | return; 180 | } 181 | return fs.readFile(source, function(err, code) { 182 | if (err) { 183 | throw err; 184 | } 185 | return compileScript(source, code.toString(), base); 186 | }); 187 | }); 188 | }; 189 | writeJs = function(source, js, base) { 190 | var baseDir, compile, dir, filename, jsPath, srcDir; 191 | filename = path.basename(source, path.extname(source)) + '.js'; 192 | srcDir = path.dirname(source); 193 | baseDir = base === '.' ? srcDir : srcDir.substring(base.length); 194 | dir = opts.output ? path.join(opts.output, baseDir) : srcDir; 195 | jsPath = path.join(dir, filename); 196 | compile = function() { 197 | if (js.length <= 0) { 198 | js = ' '; 199 | } 200 | return fs.writeFile(jsPath, js, function(err) { 201 | if (err) { 202 | return printLine(err.message); 203 | } else if (opts.compile && opts.watch) { 204 | return console.log("" + ((new Date).toLocaleTimeString()) + " - compiled " + source); 205 | } 206 | }); 207 | }; 208 | return path.exists(dir, function(exists) { 209 | if (exists) { 210 | return compile(); 211 | } else { 212 | return exec("mkdir -p " + dir, compile); 213 | } 214 | }); 215 | }; 216 | lint = function(file, js) { 217 | var conf, jsl, printIt; 218 | printIt = function(buffer) { 219 | return printLine(file + ':\t' + buffer.toString().trim()); 220 | }; 221 | conf = __dirname + '/../extras/jsl.conf'; 222 | jsl = spawn('jsl', ['-nologo', '-stdin', '-conf', conf]); 223 | jsl.stdout.on('data', printIt); 224 | jsl.stderr.on('data', printIt); 225 | jsl.stdin.write(js); 226 | return jsl.stdin.end(); 227 | }; 228 | printTokens = function(tokens) { 229 | var strings, tag, token, value; 230 | strings = (function() { 231 | var _i, _len, _ref2, _results; 232 | _results = []; 233 | for (_i = 0, _len = tokens.length; _i < _len; _i++) { 234 | token = tokens[_i]; 235 | _ref2 = [token[0], token[1].toString().replace(/\n/, '\\n')], tag = _ref2[0], value = _ref2[1]; 236 | _results.push("[" + tag + " " + value + "]"); 237 | } 238 | return _results; 239 | })(); 240 | return printLine(strings.join(' ')); 241 | }; 242 | parseOptions = function() { 243 | var o; 244 | optionParser = new optparse.OptionParser(SWITCHES, BANNER); 245 | o = opts = optionParser.parse(process.argv.slice(2)); 246 | o.compile || (o.compile = !!o.output); 247 | o.run = !(o.compile || o.print || o.lint); 248 | o.print = !!(o.print || (o.eval || o.stdio && o.compile)); 249 | return sources = o.arguments; 250 | }; 251 | compileOptions = function(filename) { 252 | return { 253 | filename: filename, 254 | bare: opts.bare 255 | }; 256 | }; 257 | forkNode = function() { 258 | var args, nodeArgs; 259 | nodeArgs = opts.nodejs.split(/\s+/); 260 | args = process.argv.slice(1); 261 | args.splice(args.indexOf('--nodejs'), 2); 262 | return spawn(process.execPath, nodeArgs.concat(args), { 263 | cwd: process.cwd(), 264 | env: process.env, 265 | customFds: [0, 1, 2] 266 | }); 267 | }; 268 | usage = function() { 269 | return printLine((new optparse.OptionParser(SWITCHES, BANNER)).help()); 270 | }; 271 | version = function() { 272 | return printLine("CoffeeScript version " + CoffeeScript.VERSION); 273 | }; 274 | }).call(this); 275 | -------------------------------------------------------------------------------- /node_modules/coffee-script/lib/grammar.js: -------------------------------------------------------------------------------- 1 | (function() { 2 | var Parser, alt, alternatives, grammar, name, o, operators, token, tokens, unwrap; 3 | Parser = require('jison').Parser; 4 | unwrap = /^function\s*\(\)\s*\{\s*return\s*([\s\S]*);\s*\}/; 5 | o = function(patternString, action, options) { 6 | var match; 7 | patternString = patternString.replace(/\s{2,}/g, ' '); 8 | if (!action) { 9 | return [patternString, '$$ = $1;', options]; 10 | } 11 | action = (match = unwrap.exec(action)) ? match[1] : "(" + action + "())"; 12 | action = action.replace(/\bnew /g, '$&yy.'); 13 | action = action.replace(/\b(?:Block\.wrap|extend)\b/g, 'yy.$&'); 14 | return [patternString, "$$ = " + action + ";", options]; 15 | }; 16 | grammar = { 17 | Root: [ 18 | o('', function() { 19 | return new Block; 20 | }), o('Body'), o('Block TERMINATOR') 21 | ], 22 | Body: [ 23 | o('Line', function() { 24 | return Block.wrap([$1]); 25 | }), o('Body TERMINATOR Line', function() { 26 | return $1.push($3); 27 | }), o('Body TERMINATOR') 28 | ], 29 | Line: [o('Expression'), o('Statement')], 30 | Statement: [ 31 | o('Return'), o('Throw'), o('Comment'), o('STATEMENT', function() { 32 | return new Literal($1); 33 | }) 34 | ], 35 | Expression: [o('Value'), o('Invocation'), o('Code'), o('Operation'), o('Assign'), o('If'), o('Try'), o('While'), o('For'), o('Switch'), o('Class')], 36 | Block: [ 37 | o('INDENT OUTDENT', function() { 38 | return new Block; 39 | }), o('INDENT Body OUTDENT', function() { 40 | return $2; 41 | }) 42 | ], 43 | Identifier: [ 44 | o('IDENTIFIER', function() { 45 | return new Literal($1); 46 | }) 47 | ], 48 | AlphaNumeric: [ 49 | o('NUMBER', function() { 50 | return new Literal($1); 51 | }), o('STRING', function() { 52 | return new Literal($1); 53 | }) 54 | ], 55 | Literal: [ 56 | o('AlphaNumeric'), o('JS', function() { 57 | return new Literal($1); 58 | }), o('REGEX', function() { 59 | return new Literal($1); 60 | }), o('BOOL', function() { 61 | var val; 62 | val = new Literal($1); 63 | if ($1 === 'undefined') { 64 | val.isUndefined = true; 65 | } 66 | return val; 67 | }) 68 | ], 69 | Assign: [ 70 | o('Assignable = Expression', function() { 71 | return new Assign($1, $3); 72 | }), o('Assignable = INDENT Expression OUTDENT', function() { 73 | return new Assign($1, $4); 74 | }) 75 | ], 76 | AssignObj: [ 77 | o('ObjAssignable', function() { 78 | return new Value($1); 79 | }), o('ObjAssignable : Expression', function() { 80 | return new Assign(new Value($1), $3, 'object'); 81 | }), o('ObjAssignable :\ 82 | INDENT Expression OUTDENT', function() { 83 | return new Assign(new Value($1), $4, 'object'); 84 | }), o('Comment') 85 | ], 86 | ObjAssignable: [o('Identifier'), o('AlphaNumeric'), o('ThisProperty')], 87 | Return: [ 88 | o('RETURN Expression', function() { 89 | return new Return($2); 90 | }), o('RETURN', function() { 91 | return new Return; 92 | }) 93 | ], 94 | Comment: [ 95 | o('HERECOMMENT', function() { 96 | return new Comment($1); 97 | }) 98 | ], 99 | Code: [ 100 | o('PARAM_START ParamList PARAM_END FuncGlyph Block', function() { 101 | return new Code($2, $5, $4); 102 | }), o('FuncGlyph Block', function() { 103 | return new Code([], $2, $1); 104 | }) 105 | ], 106 | FuncGlyph: [ 107 | o('->', function() { 108 | return 'func'; 109 | }), o('=>', function() { 110 | return 'boundfunc'; 111 | }) 112 | ], 113 | OptComma: [o(''), o(',')], 114 | ParamList: [ 115 | o('', function() { 116 | return []; 117 | }), o('Param', function() { 118 | return [$1]; 119 | }), o('ParamList , Param', function() { 120 | return $1.concat($3); 121 | }) 122 | ], 123 | Param: [ 124 | o('ParamVar', function() { 125 | return new Param($1); 126 | }), o('ParamVar ...', function() { 127 | return new Param($1, null, true); 128 | }), o('ParamVar = Expression', function() { 129 | return new Param($1, $3); 130 | }) 131 | ], 132 | ParamVar: [o('Identifier'), o('ThisProperty'), o('Array'), o('Object')], 133 | Splat: [ 134 | o('Expression ...', function() { 135 | return new Splat($1); 136 | }) 137 | ], 138 | SimpleAssignable: [ 139 | o('Identifier', function() { 140 | return new Value($1); 141 | }), o('Value Accessor', function() { 142 | return $1.push($2); 143 | }), o('Invocation Accessor', function() { 144 | return new Value($1, [$2]); 145 | }), o('ThisProperty') 146 | ], 147 | Assignable: [ 148 | o('SimpleAssignable'), o('Array', function() { 149 | return new Value($1); 150 | }), o('Object', function() { 151 | return new Value($1); 152 | }) 153 | ], 154 | Value: [ 155 | o('Assignable'), o('Literal', function() { 156 | return new Value($1); 157 | }), o('Parenthetical', function() { 158 | return new Value($1); 159 | }), o('Range', function() { 160 | return new Value($1); 161 | }), o('This') 162 | ], 163 | Accessor: [ 164 | o('. Identifier', function() { 165 | return new Access($2); 166 | }), o('?. Identifier', function() { 167 | return new Access($2, 'soak'); 168 | }), o(':: Identifier', function() { 169 | return new Access($2, 'proto'); 170 | }), o('::', function() { 171 | return new Access(new Literal('prototype')); 172 | }), o('Index') 173 | ], 174 | Index: [ 175 | o('INDEX_START IndexValue INDEX_END', function() { 176 | return $2; 177 | }), o('INDEX_SOAK Index', function() { 178 | return extend($2, { 179 | soak: true 180 | }); 181 | }), o('INDEX_PROTO Index', function() { 182 | return extend($2, { 183 | proto: true 184 | }); 185 | }) 186 | ], 187 | IndexValue: [ 188 | o('Expression', function() { 189 | return new Index($1); 190 | }), o('Slice', function() { 191 | return new Slice($1); 192 | }) 193 | ], 194 | Object: [ 195 | o('{ AssignList OptComma }', function() { 196 | return new Obj($2, $1.generated); 197 | }) 198 | ], 199 | AssignList: [ 200 | o('', function() { 201 | return []; 202 | }), o('AssignObj', function() { 203 | return [$1]; 204 | }), o('AssignList , AssignObj', function() { 205 | return $1.concat($3); 206 | }), o('AssignList OptComma TERMINATOR AssignObj', function() { 207 | return $1.concat($4); 208 | }), o('AssignList OptComma INDENT AssignList OptComma OUTDENT', function() { 209 | return $1.concat($4); 210 | }) 211 | ], 212 | Class: [ 213 | o('CLASS', function() { 214 | return new Class; 215 | }), o('CLASS Block', function() { 216 | return new Class(null, null, $2); 217 | }), o('CLASS EXTENDS Value', function() { 218 | return new Class(null, $3); 219 | }), o('CLASS EXTENDS Value Block', function() { 220 | return new Class(null, $3, $4); 221 | }), o('CLASS SimpleAssignable', function() { 222 | return new Class($2); 223 | }), o('CLASS SimpleAssignable Block', function() { 224 | return new Class($2, null, $3); 225 | }), o('CLASS SimpleAssignable EXTENDS Value', function() { 226 | return new Class($2, $4); 227 | }), o('CLASS SimpleAssignable EXTENDS Value Block', function() { 228 | return new Class($2, $4, $5); 229 | }) 230 | ], 231 | Invocation: [ 232 | o('Value OptFuncExist Arguments', function() { 233 | return new Call($1, $3, $2); 234 | }), o('Invocation OptFuncExist Arguments', function() { 235 | return new Call($1, $3, $2); 236 | }), o('SUPER', function() { 237 | return new Call('super', [new Splat(new Literal('arguments'))]); 238 | }), o('SUPER Arguments', function() { 239 | return new Call('super', $2); 240 | }) 241 | ], 242 | OptFuncExist: [ 243 | o('', function() { 244 | return false; 245 | }), o('FUNC_EXIST', function() { 246 | return true; 247 | }) 248 | ], 249 | Arguments: [ 250 | o('CALL_START CALL_END', function() { 251 | return []; 252 | }), o('CALL_START ArgList OptComma CALL_END', function() { 253 | return $2; 254 | }) 255 | ], 256 | This: [ 257 | o('THIS', function() { 258 | return new Value(new Literal('this')); 259 | }), o('@', function() { 260 | return new Value(new Literal('this')); 261 | }) 262 | ], 263 | ThisProperty: [ 264 | o('@ Identifier', function() { 265 | return new Value(new Literal('this'), [new Access($2)], 'this'); 266 | }) 267 | ], 268 | Array: [ 269 | o('[ ]', function() { 270 | return new Arr([]); 271 | }), o('[ ArgList OptComma ]', function() { 272 | return new Arr($2); 273 | }) 274 | ], 275 | RangeDots: [ 276 | o('..', function() { 277 | return 'inclusive'; 278 | }), o('...', function() { 279 | return 'exclusive'; 280 | }) 281 | ], 282 | Range: [ 283 | o('[ Expression RangeDots Expression ]', function() { 284 | return new Range($2, $4, $3); 285 | }) 286 | ], 287 | Slice: [ 288 | o('Expression RangeDots Expression', function() { 289 | return new Range($1, $3, $2); 290 | }), o('Expression RangeDots', function() { 291 | return new Range($1, null, $2); 292 | }), o('RangeDots Expression', function() { 293 | return new Range(null, $2, $1); 294 | }) 295 | ], 296 | ArgList: [ 297 | o('Arg', function() { 298 | return [$1]; 299 | }), o('ArgList , Arg', function() { 300 | return $1.concat($3); 301 | }), o('ArgList OptComma TERMINATOR Arg', function() { 302 | return $1.concat($4); 303 | }), o('INDENT ArgList OptComma OUTDENT', function() { 304 | return $2; 305 | }), o('ArgList OptComma INDENT ArgList OptComma OUTDENT', function() { 306 | return $1.concat($4); 307 | }) 308 | ], 309 | Arg: [o('Expression'), o('Splat')], 310 | SimpleArgs: [ 311 | o('Expression'), o('SimpleArgs , Expression', function() { 312 | return [].concat($1, $3); 313 | }) 314 | ], 315 | Try: [ 316 | o('TRY Block', function() { 317 | return new Try($2); 318 | }), o('TRY Block Catch', function() { 319 | return new Try($2, $3[0], $3[1]); 320 | }), o('TRY Block FINALLY Block', function() { 321 | return new Try($2, null, null, $4); 322 | }), o('TRY Block Catch FINALLY Block', function() { 323 | return new Try($2, $3[0], $3[1], $5); 324 | }) 325 | ], 326 | Catch: [ 327 | o('CATCH Identifier Block', function() { 328 | return [$2, $3]; 329 | }) 330 | ], 331 | Throw: [ 332 | o('THROW Expression', function() { 333 | return new Throw($2); 334 | }) 335 | ], 336 | Parenthetical: [ 337 | o('( Body )', function() { 338 | return new Parens($2); 339 | }), o('( INDENT Body OUTDENT )', function() { 340 | return new Parens($3); 341 | }) 342 | ], 343 | WhileSource: [ 344 | o('WHILE Expression', function() { 345 | return new While($2); 346 | }), o('WHILE Expression WHEN Expression', function() { 347 | return new While($2, { 348 | guard: $4 349 | }); 350 | }), o('UNTIL Expression', function() { 351 | return new While($2, { 352 | invert: true 353 | }); 354 | }), o('UNTIL Expression WHEN Expression', function() { 355 | return new While($2, { 356 | invert: true, 357 | guard: $4 358 | }); 359 | }) 360 | ], 361 | While: [ 362 | o('WhileSource Block', function() { 363 | return $1.addBody($2); 364 | }), o('Statement WhileSource', function() { 365 | return $2.addBody(Block.wrap([$1])); 366 | }), o('Expression WhileSource', function() { 367 | return $2.addBody(Block.wrap([$1])); 368 | }), o('Loop', function() { 369 | return $1; 370 | }) 371 | ], 372 | Loop: [ 373 | o('LOOP Block', function() { 374 | return new While(new Literal('true')).addBody($2); 375 | }), o('LOOP Expression', function() { 376 | return new While(new Literal('true')).addBody(Block.wrap([$2])); 377 | }) 378 | ], 379 | For: [ 380 | o('Statement ForBody', function() { 381 | return new For($1, $2); 382 | }), o('Expression ForBody', function() { 383 | return new For($1, $2); 384 | }), o('ForBody Block', function() { 385 | return new For($2, $1); 386 | }) 387 | ], 388 | ForBody: [ 389 | o('FOR Range', function() { 390 | return { 391 | source: new Value($2) 392 | }; 393 | }), o('ForStart ForSource', function() { 394 | $2.own = $1.own; 395 | $2.name = $1[0]; 396 | $2.index = $1[1]; 397 | return $2; 398 | }) 399 | ], 400 | ForStart: [ 401 | o('FOR ForVariables', function() { 402 | return $2; 403 | }), o('FOR OWN ForVariables', function() { 404 | $3.own = true; 405 | return $3; 406 | }) 407 | ], 408 | ForValue: [ 409 | o('Identifier'), o('Array', function() { 410 | return new Value($1); 411 | }), o('Object', function() { 412 | return new Value($1); 413 | }) 414 | ], 415 | ForVariables: [ 416 | o('ForValue', function() { 417 | return [$1]; 418 | }), o('ForValue , ForValue', function() { 419 | return [$1, $3]; 420 | }) 421 | ], 422 | ForSource: [ 423 | o('FORIN Expression', function() { 424 | return { 425 | source: $2 426 | }; 427 | }), o('FOROF Expression', function() { 428 | return { 429 | source: $2, 430 | object: true 431 | }; 432 | }), o('FORIN Expression WHEN Expression', function() { 433 | return { 434 | source: $2, 435 | guard: $4 436 | }; 437 | }), o('FOROF Expression WHEN Expression', function() { 438 | return { 439 | source: $2, 440 | guard: $4, 441 | object: true 442 | }; 443 | }), o('FORIN Expression BY Expression', function() { 444 | return { 445 | source: $2, 446 | step: $4 447 | }; 448 | }), o('FORIN Expression WHEN Expression BY Expression', function() { 449 | return { 450 | source: $2, 451 | guard: $4, 452 | step: $6 453 | }; 454 | }), o('FORIN Expression BY Expression WHEN Expression', function() { 455 | return { 456 | source: $2, 457 | step: $4, 458 | guard: $6 459 | }; 460 | }) 461 | ], 462 | Switch: [ 463 | o('SWITCH Expression INDENT Whens OUTDENT', function() { 464 | return new Switch($2, $4); 465 | }), o('SWITCH Expression INDENT Whens ELSE Block OUTDENT', function() { 466 | return new Switch($2, $4, $6); 467 | }), o('SWITCH INDENT Whens OUTDENT', function() { 468 | return new Switch(null, $3); 469 | }), o('SWITCH INDENT Whens ELSE Block OUTDENT', function() { 470 | return new Switch(null, $3, $5); 471 | }) 472 | ], 473 | Whens: [ 474 | o('When'), o('Whens When', function() { 475 | return $1.concat($2); 476 | }) 477 | ], 478 | When: [ 479 | o('LEADING_WHEN SimpleArgs Block', function() { 480 | return [[$2, $3]]; 481 | }), o('LEADING_WHEN SimpleArgs Block TERMINATOR', function() { 482 | return [[$2, $3]]; 483 | }) 484 | ], 485 | IfBlock: [ 486 | o('IF Expression Block', function() { 487 | return new If($2, $3, { 488 | type: $1 489 | }); 490 | }), o('IfBlock ELSE IF Expression Block', function() { 491 | return $1.addElse(new If($4, $5, { 492 | type: $3 493 | })); 494 | }) 495 | ], 496 | If: [ 497 | o('IfBlock'), o('IfBlock ELSE Block', function() { 498 | return $1.addElse($3); 499 | }), o('Statement POST_IF Expression', function() { 500 | return new If($3, Block.wrap([$1]), { 501 | type: $2, 502 | statement: true 503 | }); 504 | }), o('Expression POST_IF Expression', function() { 505 | return new If($3, Block.wrap([$1]), { 506 | type: $2, 507 | statement: true 508 | }); 509 | }) 510 | ], 511 | Operation: [ 512 | o('UNARY Expression', function() { 513 | return new Op($1, $2); 514 | }), o('- Expression', (function() { 515 | return new Op('-', $2); 516 | }), { 517 | prec: 'UNARY' 518 | }), o('+ Expression', (function() { 519 | return new Op('+', $2); 520 | }), { 521 | prec: 'UNARY' 522 | }), o('-- SimpleAssignable', function() { 523 | return new Op('--', $2); 524 | }), o('++ SimpleAssignable', function() { 525 | return new Op('++', $2); 526 | }), o('SimpleAssignable --', function() { 527 | return new Op('--', $1, null, true); 528 | }), o('SimpleAssignable ++', function() { 529 | return new Op('++', $1, null, true); 530 | }), o('Expression ?', function() { 531 | return new Existence($1); 532 | }), o('Expression + Expression', function() { 533 | return new Op('+', $1, $3); 534 | }), o('Expression - Expression', function() { 535 | return new Op('-', $1, $3); 536 | }), o('Expression MATH Expression', function() { 537 | return new Op($2, $1, $3); 538 | }), o('Expression SHIFT Expression', function() { 539 | return new Op($2, $1, $3); 540 | }), o('Expression COMPARE Expression', function() { 541 | return new Op($2, $1, $3); 542 | }), o('Expression LOGIC Expression', function() { 543 | return new Op($2, $1, $3); 544 | }), o('Expression RELATION Expression', function() { 545 | if ($2.charAt(0) === '!') { 546 | return new Op($2.slice(1), $1, $3).invert(); 547 | } else { 548 | return new Op($2, $1, $3); 549 | } 550 | }), o('SimpleAssignable COMPOUND_ASSIGN\ 551 | Expression', function() { 552 | return new Assign($1, $3, $2); 553 | }), o('SimpleAssignable COMPOUND_ASSIGN\ 554 | INDENT Expression OUTDENT', function() { 555 | return new Assign($1, $4, $2); 556 | }), o('SimpleAssignable EXTENDS Expression', function() { 557 | return new Extends($1, $3); 558 | }) 559 | ] 560 | }; 561 | 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']]; 562 | tokens = []; 563 | for (name in grammar) { 564 | alternatives = grammar[name]; 565 | grammar[name] = (function() { 566 | var _i, _j, _len, _len2, _ref, _results; 567 | _results = []; 568 | for (_i = 0, _len = alternatives.length; _i < _len; _i++) { 569 | alt = alternatives[_i]; 570 | _ref = alt[0].split(' '); 571 | for (_j = 0, _len2 = _ref.length; _j < _len2; _j++) { 572 | token = _ref[_j]; 573 | if (!grammar[token]) { 574 | tokens.push(token); 575 | } 576 | } 577 | if (name === 'Root') { 578 | alt[1] = "return " + alt[1]; 579 | } 580 | _results.push(alt); 581 | } 582 | return _results; 583 | })(); 584 | } 585 | exports.parser = new Parser({ 586 | tokens: tokens.join(' '), 587 | bnf: grammar, 588 | operators: operators.reverse(), 589 | startSymbol: 'Root' 590 | }); 591 | }).call(this); 592 | -------------------------------------------------------------------------------- /node_modules/coffee-script/lib/helpers.js: -------------------------------------------------------------------------------- 1 | (function() { 2 | var extend, flatten; 3 | exports.starts = function(string, literal, start) { 4 | return literal === string.substr(start, literal.length); 5 | }; 6 | exports.ends = function(string, literal, back) { 7 | var len; 8 | len = literal.length; 9 | return literal === string.substr(string.length - len - (back || 0), len); 10 | }; 11 | exports.compact = function(array) { 12 | var item, _i, _len, _results; 13 | _results = []; 14 | for (_i = 0, _len = array.length; _i < _len; _i++) { 15 | item = array[_i]; 16 | if (item) { 17 | _results.push(item); 18 | } 19 | } 20 | return _results; 21 | }; 22 | exports.count = function(string, substr) { 23 | var num, pos; 24 | num = pos = 0; 25 | if (!substr.length) { 26 | return 1 / 0; 27 | } 28 | while (pos = 1 + string.indexOf(substr, pos)) { 29 | num++; 30 | } 31 | return num; 32 | }; 33 | exports.merge = function(options, overrides) { 34 | return extend(extend({}, options), overrides); 35 | }; 36 | extend = exports.extend = function(object, properties) { 37 | var key, val; 38 | for (key in properties) { 39 | val = properties[key]; 40 | object[key] = val; 41 | } 42 | return object; 43 | }; 44 | exports.flatten = flatten = function(array) { 45 | var element, flattened, _i, _len; 46 | flattened = []; 47 | for (_i = 0, _len = array.length; _i < _len; _i++) { 48 | element = array[_i]; 49 | if (element instanceof Array) { 50 | flattened = flattened.concat(flatten(element)); 51 | } else { 52 | flattened.push(element); 53 | } 54 | } 55 | return flattened; 56 | }; 57 | exports.del = function(obj, key) { 58 | var val; 59 | val = obj[key]; 60 | delete obj[key]; 61 | return val; 62 | }; 63 | exports.last = function(array, back) { 64 | return array[array.length - (back || 0) - 1]; 65 | }; 66 | }).call(this); 67 | -------------------------------------------------------------------------------- /node_modules/coffee-script/lib/index.js: -------------------------------------------------------------------------------- 1 | (function() { 2 | var key, val, _ref; 3 | _ref = require('./coffee-script'); 4 | for (key in _ref) { 5 | val = _ref[key]; 6 | exports[key] = val; 7 | } 8 | }).call(this); 9 | -------------------------------------------------------------------------------- /node_modules/coffee-script/lib/lexer.js: -------------------------------------------------------------------------------- 1 | (function() { 2 | var ASSIGNED, BOOL, CALLABLE, CODE, COFFEE_ALIASES, COFFEE_ALIAS_MAP, COFFEE_KEYWORDS, COMMENT, COMPARE, COMPOUND_ASSIGN, HEREDOC, HEREDOC_ILLEGAL, HEREDOC_INDENT, HEREGEX, HEREGEX_OMIT, IDENTIFIER, INDEXABLE, JSTOKEN, JS_FORBIDDEN, JS_KEYWORDS, LINE_BREAK, LINE_CONTINUER, LOGIC, Lexer, MATH, MULTILINER, MULTI_DENT, NOT_REGEX, NOT_SPACED_REGEX, NO_NEWLINE, NUMBER, OPERATOR, REGEX, RELATION, RESERVED, Rewriter, SHIFT, SIMPLESTR, TRAILING_SPACES, UNARY, WHITESPACE, compact, count, key, last, starts, _ref; 3 | var __indexOf = Array.prototype.indexOf || function(item) { 4 | for (var i = 0, l = this.length; i < l; i++) { 5 | if (this[i] === item) return i; 6 | } 7 | return -1; 8 | }; 9 | Rewriter = require('./rewriter').Rewriter; 10 | _ref = require('./helpers'), count = _ref.count, starts = _ref.starts, compact = _ref.compact, last = _ref.last; 11 | exports.Lexer = Lexer = (function() { 12 | function Lexer() {} 13 | Lexer.prototype.tokenize = function(code, opts) { 14 | var i; 15 | if (opts == null) { 16 | opts = {}; 17 | } 18 | if (WHITESPACE.test(code)) { 19 | code = "\n" + code; 20 | } 21 | code = code.replace(/\r/g, '').replace(TRAILING_SPACES, ''); 22 | this.code = code; 23 | this.line = opts.line || 0; 24 | this.indent = 0; 25 | this.indebt = 0; 26 | this.outdebt = 0; 27 | this.indents = []; 28 | this.tokens = []; 29 | i = 0; 30 | while (this.chunk = code.slice(i)) { 31 | i += this.identifierToken() || this.commentToken() || this.whitespaceToken() || this.lineToken() || this.heredocToken() || this.stringToken() || this.numberToken() || this.regexToken() || this.jsToken() || this.literalToken(); 32 | } 33 | this.closeIndentation(); 34 | if (opts.rewrite === false) { 35 | return this.tokens; 36 | } 37 | return (new Rewriter).rewrite(this.tokens); 38 | }; 39 | Lexer.prototype.identifierToken = function() { 40 | var colon, forcedIdentifier, id, input, match, prev, tag, _ref2, _ref3; 41 | if (!(match = IDENTIFIER.exec(this.chunk))) { 42 | return 0; 43 | } 44 | input = match[0], id = match[1], colon = match[2]; 45 | if (id === 'own' && this.tag() === 'FOR') { 46 | this.token('OWN', id); 47 | return id.length; 48 | } 49 | forcedIdentifier = colon || (prev = last(this.tokens)) && (((_ref2 = prev[0]) === '.' || _ref2 === '?.' || _ref2 === '::') || !prev.spaced && prev[0] === '@'); 50 | tag = 'IDENTIFIER'; 51 | if (__indexOf.call(JS_KEYWORDS, id) >= 0 || !forcedIdentifier && __indexOf.call(COFFEE_KEYWORDS, id) >= 0) { 52 | tag = id.toUpperCase(); 53 | if (tag === 'WHEN' && (_ref3 = this.tag(), __indexOf.call(LINE_BREAK, _ref3) >= 0)) { 54 | tag = 'LEADING_WHEN'; 55 | } else if (tag === 'FOR') { 56 | this.seenFor = true; 57 | } else if (tag === 'UNLESS') { 58 | tag = 'IF'; 59 | } else if (__indexOf.call(UNARY, tag) >= 0) { 60 | tag = 'UNARY'; 61 | } else if (__indexOf.call(RELATION, tag) >= 0) { 62 | if (tag !== 'INSTANCEOF' && this.seenFor) { 63 | tag = 'FOR' + tag; 64 | this.seenFor = false; 65 | } else { 66 | tag = 'RELATION'; 67 | if (this.value() === '!') { 68 | this.tokens.pop(); 69 | id = '!' + id; 70 | } 71 | } 72 | } 73 | } 74 | if (__indexOf.call(JS_FORBIDDEN, id) >= 0) { 75 | if (forcedIdentifier) { 76 | tag = 'IDENTIFIER'; 77 | id = new String(id); 78 | id.reserved = true; 79 | } else if (__indexOf.call(RESERVED, id) >= 0) { 80 | this.identifierError(id); 81 | } 82 | } 83 | if (!forcedIdentifier) { 84 | if (__indexOf.call(COFFEE_ALIASES, id) >= 0) { 85 | id = COFFEE_ALIAS_MAP[id]; 86 | } 87 | tag = (function() { 88 | switch (id) { 89 | case '!': 90 | return 'UNARY'; 91 | case '==': 92 | case '!=': 93 | return 'COMPARE'; 94 | case '&&': 95 | case '||': 96 | return 'LOGIC'; 97 | case 'true': 98 | case 'false': 99 | case 'null': 100 | case 'undefined': 101 | return 'BOOL'; 102 | case 'break': 103 | case 'continue': 104 | case 'debugger': 105 | return 'STATEMENT'; 106 | default: 107 | return tag; 108 | } 109 | })(); 110 | } 111 | this.token(tag, id); 112 | if (colon) { 113 | this.token(':', ':'); 114 | } 115 | return input.length; 116 | }; 117 | Lexer.prototype.numberToken = function() { 118 | var match, number; 119 | if (!(match = NUMBER.exec(this.chunk))) { 120 | return 0; 121 | } 122 | number = match[0]; 123 | this.token('NUMBER', number); 124 | return number.length; 125 | }; 126 | Lexer.prototype.stringToken = function() { 127 | var match, string; 128 | switch (this.chunk.charAt(0)) { 129 | case "'": 130 | if (!(match = SIMPLESTR.exec(this.chunk))) { 131 | return 0; 132 | } 133 | this.token('STRING', (string = match[0]).replace(MULTILINER, '\\\n')); 134 | break; 135 | case '"': 136 | if (!(string = this.balancedString(this.chunk, '"'))) { 137 | return 0; 138 | } 139 | if (0 < string.indexOf('#{', 1)) { 140 | this.interpolateString(string.slice(1, -1)); 141 | } else { 142 | this.token('STRING', this.escapeLines(string)); 143 | } 144 | break; 145 | default: 146 | return 0; 147 | } 148 | this.line += count(string, '\n'); 149 | return string.length; 150 | }; 151 | Lexer.prototype.heredocToken = function() { 152 | var doc, heredoc, match, quote; 153 | if (!(match = HEREDOC.exec(this.chunk))) { 154 | return 0; 155 | } 156 | heredoc = match[0]; 157 | quote = heredoc.charAt(0); 158 | doc = this.sanitizeHeredoc(match[2], { 159 | quote: quote, 160 | indent: null 161 | }); 162 | if (quote === '"' && 0 <= doc.indexOf('#{')) { 163 | this.interpolateString(doc, { 164 | heredoc: true 165 | }); 166 | } else { 167 | this.token('STRING', this.makeString(doc, quote, true)); 168 | } 169 | this.line += count(heredoc, '\n'); 170 | return heredoc.length; 171 | }; 172 | Lexer.prototype.commentToken = function() { 173 | var comment, here, match; 174 | if (!(match = this.chunk.match(COMMENT))) { 175 | return 0; 176 | } 177 | comment = match[0], here = match[1]; 178 | if (here) { 179 | this.token('HERECOMMENT', this.sanitizeHeredoc(here, { 180 | herecomment: true, 181 | indent: Array(this.indent + 1).join(' ') 182 | })); 183 | this.token('TERMINATOR', '\n'); 184 | } 185 | this.line += count(comment, '\n'); 186 | return comment.length; 187 | }; 188 | Lexer.prototype.jsToken = function() { 189 | var match, script; 190 | if (!(this.chunk.charAt(0) === '`' && (match = JSTOKEN.exec(this.chunk)))) { 191 | return 0; 192 | } 193 | this.token('JS', (script = match[0]).slice(1, -1)); 194 | return script.length; 195 | }; 196 | Lexer.prototype.regexToken = function() { 197 | var match, prev, regex, _ref2; 198 | if (this.chunk.charAt(0) !== '/') { 199 | return 0; 200 | } 201 | if (match = HEREGEX.exec(this.chunk)) { 202 | return this.heregexToken(match); 203 | } 204 | prev = last(this.tokens); 205 | if (prev && (_ref2 = prev[0], __indexOf.call((prev.spaced ? NOT_REGEX : NOT_SPACED_REGEX), _ref2) >= 0)) { 206 | return 0; 207 | } 208 | if (!(match = REGEX.exec(this.chunk))) { 209 | return 0; 210 | } 211 | regex = match[0]; 212 | this.token('REGEX', regex === '//' ? '/(?:)/' : regex); 213 | return regex.length; 214 | }; 215 | Lexer.prototype.heregexToken = function(match) { 216 | var body, flags, heregex, re, tag, tokens, value, _i, _len, _ref2, _ref3, _ref4, _ref5; 217 | heregex = match[0], body = match[1], flags = match[2]; 218 | if (0 > body.indexOf('#{')) { 219 | re = body.replace(HEREGEX_OMIT, '').replace(/\//g, '\\/'); 220 | this.token('REGEX', "/" + (re || '(?:)') + "/" + flags); 221 | return heregex.length; 222 | } 223 | this.token('IDENTIFIER', 'RegExp'); 224 | this.tokens.push(['CALL_START', '(']); 225 | tokens = []; 226 | _ref2 = this.interpolateString(body, { 227 | regex: true 228 | }); 229 | for (_i = 0, _len = _ref2.length; _i < _len; _i++) { 230 | _ref3 = _ref2[_i], tag = _ref3[0], value = _ref3[1]; 231 | if (tag === 'TOKENS') { 232 | tokens.push.apply(tokens, value); 233 | } else { 234 | if (!(value = value.replace(HEREGEX_OMIT, ''))) { 235 | continue; 236 | } 237 | value = value.replace(/\\/g, '\\\\'); 238 | tokens.push(['STRING', this.makeString(value, '"', true)]); 239 | } 240 | tokens.push(['+', '+']); 241 | } 242 | tokens.pop(); 243 | if (((_ref4 = tokens[0]) != null ? _ref4[0] : void 0) !== 'STRING') { 244 | this.tokens.push(['STRING', '""'], ['+', '+']); 245 | } 246 | (_ref5 = this.tokens).push.apply(_ref5, tokens); 247 | if (flags) { 248 | this.tokens.push([',', ','], ['STRING', '"' + flags + '"']); 249 | } 250 | this.token(')', ')'); 251 | return heregex.length; 252 | }; 253 | Lexer.prototype.lineToken = function() { 254 | var diff, indent, match, noNewlines, prev, size; 255 | if (!(match = MULTI_DENT.exec(this.chunk))) { 256 | return 0; 257 | } 258 | indent = match[0]; 259 | this.line += count(indent, '\n'); 260 | prev = last(this.tokens, 1); 261 | size = indent.length - 1 - indent.lastIndexOf('\n'); 262 | noNewlines = this.unfinished(); 263 | if (size - this.indebt === this.indent) { 264 | if (noNewlines) { 265 | this.suppressNewlines(); 266 | } else { 267 | this.newlineToken(); 268 | } 269 | return indent.length; 270 | } 271 | if (size > this.indent) { 272 | if (noNewlines) { 273 | this.indebt = size - this.indent; 274 | this.suppressNewlines(); 275 | return indent.length; 276 | } 277 | diff = size - this.indent + this.outdebt; 278 | this.token('INDENT', diff); 279 | this.indents.push(diff); 280 | this.outdebt = this.indebt = 0; 281 | } else { 282 | this.indebt = 0; 283 | this.outdentToken(this.indent - size, noNewlines); 284 | } 285 | this.indent = size; 286 | return indent.length; 287 | }; 288 | Lexer.prototype.outdentToken = function(moveOut, noNewlines, close) { 289 | var dent, len; 290 | while (moveOut > 0) { 291 | len = this.indents.length - 1; 292 | if (this.indents[len] === void 0) { 293 | moveOut = 0; 294 | } else if (this.indents[len] === this.outdebt) { 295 | moveOut -= this.outdebt; 296 | this.outdebt = 0; 297 | } else if (this.indents[len] < this.outdebt) { 298 | this.outdebt -= this.indents[len]; 299 | moveOut -= this.indents[len]; 300 | } else { 301 | dent = this.indents.pop() - this.outdebt; 302 | moveOut -= dent; 303 | this.outdebt = 0; 304 | this.token('OUTDENT', dent); 305 | } 306 | } 307 | if (dent) { 308 | this.outdebt -= moveOut; 309 | } 310 | if (!(this.tag() === 'TERMINATOR' || noNewlines)) { 311 | this.token('TERMINATOR', '\n'); 312 | } 313 | return this; 314 | }; 315 | Lexer.prototype.whitespaceToken = function() { 316 | var match, nline, prev; 317 | if (!((match = WHITESPACE.exec(this.chunk)) || (nline = this.chunk.charAt(0) === '\n'))) { 318 | return 0; 319 | } 320 | prev = last(this.tokens); 321 | if (prev) { 322 | prev[match ? 'spaced' : 'newLine'] = true; 323 | } 324 | if (match) { 325 | return match[0].length; 326 | } else { 327 | return 0; 328 | } 329 | }; 330 | Lexer.prototype.newlineToken = function() { 331 | if (this.tag() !== 'TERMINATOR') { 332 | this.token('TERMINATOR', '\n'); 333 | } 334 | return this; 335 | }; 336 | Lexer.prototype.suppressNewlines = function() { 337 | if (this.value() === '\\') { 338 | this.tokens.pop(); 339 | } 340 | return this; 341 | }; 342 | Lexer.prototype.literalToken = function() { 343 | var match, prev, tag, value, _ref2, _ref3, _ref4, _ref5; 344 | if (match = OPERATOR.exec(this.chunk)) { 345 | value = match[0]; 346 | if (CODE.test(value)) { 347 | this.tagParameters(); 348 | } 349 | } else { 350 | value = this.chunk.charAt(0); 351 | } 352 | tag = value; 353 | prev = last(this.tokens); 354 | if (value === '=' && prev) { 355 | if (!prev[1].reserved && (_ref2 = prev[1], __indexOf.call(JS_FORBIDDEN, _ref2) >= 0)) { 356 | this.assignmentError(); 357 | } 358 | if ((_ref3 = prev[1]) === '||' || _ref3 === '&&') { 359 | prev[0] = 'COMPOUND_ASSIGN'; 360 | prev[1] += '='; 361 | return value.length; 362 | } 363 | } 364 | if (value === ';') { 365 | tag = 'TERMINATOR'; 366 | } else if (__indexOf.call(MATH, value) >= 0) { 367 | tag = 'MATH'; 368 | } else if (__indexOf.call(COMPARE, value) >= 0) { 369 | tag = 'COMPARE'; 370 | } else if (__indexOf.call(COMPOUND_ASSIGN, value) >= 0) { 371 | tag = 'COMPOUND_ASSIGN'; 372 | } else if (__indexOf.call(UNARY, value) >= 0) { 373 | tag = 'UNARY'; 374 | } else if (__indexOf.call(SHIFT, value) >= 0) { 375 | tag = 'SHIFT'; 376 | } else if (__indexOf.call(LOGIC, value) >= 0 || value === '?' && (prev != null ? prev.spaced : void 0)) { 377 | tag = 'LOGIC'; 378 | } else if (prev && !prev.spaced) { 379 | if (value === '(' && (_ref4 = prev[0], __indexOf.call(CALLABLE, _ref4) >= 0)) { 380 | if (prev[0] === '?') { 381 | prev[0] = 'FUNC_EXIST'; 382 | } 383 | tag = 'CALL_START'; 384 | } else if (value === '[' && (_ref5 = prev[0], __indexOf.call(INDEXABLE, _ref5) >= 0)) { 385 | tag = 'INDEX_START'; 386 | switch (prev[0]) { 387 | case '?': 388 | prev[0] = 'INDEX_SOAK'; 389 | break; 390 | case '::': 391 | prev[0] = 'INDEX_PROTO'; 392 | } 393 | } 394 | } 395 | this.token(tag, value); 396 | return value.length; 397 | }; 398 | Lexer.prototype.sanitizeHeredoc = function(doc, options) { 399 | var attempt, herecomment, indent, match, _ref2; 400 | indent = options.indent, herecomment = options.herecomment; 401 | if (herecomment) { 402 | if (HEREDOC_ILLEGAL.test(doc)) { 403 | throw new Error("block comment cannot contain \"*/\", starting on line " + (this.line + 1)); 404 | } 405 | if (doc.indexOf('\n') <= 0) { 406 | return doc; 407 | } 408 | } else { 409 | while (match = HEREDOC_INDENT.exec(doc)) { 410 | attempt = match[1]; 411 | if (indent === null || (0 < (_ref2 = attempt.length) && _ref2 < indent.length)) { 412 | indent = attempt; 413 | } 414 | } 415 | } 416 | if (indent) { 417 | doc = doc.replace(RegExp("\\n" + indent, "g"), '\n'); 418 | } 419 | if (!herecomment) { 420 | doc = doc.replace(/^\n/, ''); 421 | } 422 | return doc; 423 | }; 424 | Lexer.prototype.tagParameters = function() { 425 | var i, stack, tok, tokens; 426 | if (this.tag() !== ')') { 427 | return this; 428 | } 429 | stack = []; 430 | tokens = this.tokens; 431 | i = tokens.length; 432 | tokens[--i][0] = 'PARAM_END'; 433 | while (tok = tokens[--i]) { 434 | switch (tok[0]) { 435 | case ')': 436 | stack.push(tok); 437 | break; 438 | case '(': 439 | case 'CALL_START': 440 | if (stack.length) { 441 | stack.pop(); 442 | } else if (tok[0] === '(') { 443 | tok[0] = 'PARAM_START'; 444 | return this; 445 | } 446 | } 447 | } 448 | return this; 449 | }; 450 | Lexer.prototype.closeIndentation = function() { 451 | return this.outdentToken(this.indent); 452 | }; 453 | Lexer.prototype.identifierError = function(word) { 454 | throw SyntaxError("Reserved word \"" + word + "\" on line " + (this.line + 1)); 455 | }; 456 | Lexer.prototype.assignmentError = function() { 457 | throw SyntaxError("Reserved word \"" + (this.value()) + "\" on line " + (this.line + 1) + " can't be assigned"); 458 | }; 459 | Lexer.prototype.balancedString = function(str, end) { 460 | var i, letter, prev, stack, _ref2; 461 | stack = [end]; 462 | for (i = 1, _ref2 = str.length; 1 <= _ref2 ? i < _ref2 : i > _ref2; 1 <= _ref2 ? i++ : i--) { 463 | switch (letter = str.charAt(i)) { 464 | case '\\': 465 | i++; 466 | continue; 467 | case end: 468 | stack.pop(); 469 | if (!stack.length) { 470 | return str.slice(0, i + 1); 471 | } 472 | end = stack[stack.length - 1]; 473 | continue; 474 | } 475 | if (end === '}' && (letter === '"' || letter === "'")) { 476 | stack.push(end = letter); 477 | } else if (end === '}' && letter === '{') { 478 | stack.push(end = '}'); 479 | } else if (end === '"' && prev === '#' && letter === '{') { 480 | stack.push(end = '}'); 481 | } 482 | prev = letter; 483 | } 484 | throw new Error("missing " + (stack.pop()) + ", starting on line " + (this.line + 1)); 485 | }; 486 | Lexer.prototype.interpolateString = function(str, options) { 487 | var expr, heredoc, i, inner, interpolated, len, letter, nested, pi, regex, tag, tokens, value, _len, _ref2, _ref3, _ref4; 488 | if (options == null) { 489 | options = {}; 490 | } 491 | heredoc = options.heredoc, regex = options.regex; 492 | tokens = []; 493 | pi = 0; 494 | i = -1; 495 | while (letter = str.charAt(i += 1)) { 496 | if (letter === '\\') { 497 | i += 1; 498 | continue; 499 | } 500 | if (!(letter === '#' && str.charAt(i + 1) === '{' && (expr = this.balancedString(str.slice(i + 1), '}')))) { 501 | continue; 502 | } 503 | if (pi < i) { 504 | tokens.push(['NEOSTRING', str.slice(pi, i)]); 505 | } 506 | inner = expr.slice(1, -1); 507 | if (inner.length) { 508 | nested = new Lexer().tokenize(inner, { 509 | line: this.line, 510 | rewrite: false 511 | }); 512 | nested.pop(); 513 | if (((_ref2 = nested[0]) != null ? _ref2[0] : void 0) === 'TERMINATOR') { 514 | nested.shift(); 515 | } 516 | if (len = nested.length) { 517 | if (len > 1) { 518 | nested.unshift(['(', '(']); 519 | nested.push([')', ')']); 520 | } 521 | tokens.push(['TOKENS', nested]); 522 | } 523 | } 524 | i += expr.length; 525 | pi = i + 1; 526 | } 527 | if ((i > pi && pi < str.length)) { 528 | tokens.push(['NEOSTRING', str.slice(pi)]); 529 | } 530 | if (regex) { 531 | return tokens; 532 | } 533 | if (!tokens.length) { 534 | return this.token('STRING', '""'); 535 | } 536 | if (tokens[0][0] !== 'NEOSTRING') { 537 | tokens.unshift(['', '']); 538 | } 539 | if (interpolated = tokens.length > 1) { 540 | this.token('(', '('); 541 | } 542 | for (i = 0, _len = tokens.length; i < _len; i++) { 543 | _ref3 = tokens[i], tag = _ref3[0], value = _ref3[1]; 544 | if (i) { 545 | this.token('+', '+'); 546 | } 547 | if (tag === 'TOKENS') { 548 | (_ref4 = this.tokens).push.apply(_ref4, value); 549 | } else { 550 | this.token('STRING', this.makeString(value, '"', heredoc)); 551 | } 552 | } 553 | if (interpolated) { 554 | this.token(')', ')'); 555 | } 556 | return tokens; 557 | }; 558 | Lexer.prototype.token = function(tag, value) { 559 | return this.tokens.push([tag, value, this.line]); 560 | }; 561 | Lexer.prototype.tag = function(index, tag) { 562 | var tok; 563 | return (tok = last(this.tokens, index)) && (tag ? tok[0] = tag : tok[0]); 564 | }; 565 | Lexer.prototype.value = function(index, val) { 566 | var tok; 567 | return (tok = last(this.tokens, index)) && (val ? tok[1] = val : tok[1]); 568 | }; 569 | Lexer.prototype.unfinished = function() { 570 | var prev, value; 571 | return LINE_CONTINUER.test(this.chunk) || (prev = last(this.tokens, 1)) && prev[0] !== '.' && (value = this.value()) && !value.reserved && NO_NEWLINE.test(value) && !CODE.test(value) && !ASSIGNED.test(this.chunk); 572 | }; 573 | Lexer.prototype.escapeLines = function(str, heredoc) { 574 | return str.replace(MULTILINER, heredoc ? '\\n' : ''); 575 | }; 576 | Lexer.prototype.makeString = function(body, quote, heredoc) { 577 | if (!body) { 578 | return quote + quote; 579 | } 580 | body = body.replace(/\\([\s\S])/g, function(match, contents) { 581 | if (contents === '\n' || contents === quote) { 582 | return contents; 583 | } else { 584 | return match; 585 | } 586 | }); 587 | body = body.replace(RegExp("" + quote, "g"), '\\$&'); 588 | return quote + this.escapeLines(body, heredoc) + quote; 589 | }; 590 | return Lexer; 591 | })(); 592 | JS_KEYWORDS = ['true', 'false', 'null', 'this', 'new', 'delete', 'typeof', 'in', 'instanceof', 'return', 'throw', 'break', 'continue', 'debugger', 'if', 'else', 'switch', 'for', 'while', 'do', 'try', 'catch', 'finally', 'class', 'extends', 'super']; 593 | COFFEE_KEYWORDS = ['undefined', 'then', 'unless', 'until', 'loop', 'of', 'by', 'when']; 594 | COFFEE_ALIAS_MAP = { 595 | and: '&&', 596 | or: '||', 597 | is: '==', 598 | isnt: '!=', 599 | not: '!', 600 | yes: 'true', 601 | no: 'false', 602 | on: 'true', 603 | off: 'false' 604 | }; 605 | COFFEE_ALIASES = (function() { 606 | var _results; 607 | _results = []; 608 | for (key in COFFEE_ALIAS_MAP) { 609 | _results.push(key); 610 | } 611 | return _results; 612 | })(); 613 | COFFEE_KEYWORDS = COFFEE_KEYWORDS.concat(COFFEE_ALIASES); 614 | RESERVED = ['case', 'default', 'function', 'var', 'void', 'with', 'const', 'let', 'enum', 'export', 'import', 'native', '__hasProp', '__extends', '__slice', '__bind', '__indexOf']; 615 | JS_FORBIDDEN = JS_KEYWORDS.concat(RESERVED); 616 | exports.RESERVED = RESERVED.concat(JS_KEYWORDS).concat(COFFEE_KEYWORDS); 617 | IDENTIFIER = /^([$A-Za-z_\x7f-\uffff][$\w\x7f-\uffff]*)([^\n\S]*:(?!:))?/; 618 | NUMBER = /^0x[\da-f]+|^(?:\d+(\.\d+)?|\.\d+)(?:e[+-]?\d+)?/i; 619 | HEREDOC = /^("""|''')([\s\S]*?)(?:\n[^\n\S]*)?\1/; 620 | OPERATOR = /^(?:[-=]>|[-+*\/%<>&|^!?=]=|>>>=?|([-+:])\1|([&|<>])\2=?|\?\.|\.{2,3})/; 621 | WHITESPACE = /^[^\n\S]+/; 622 | COMMENT = /^###([^#][\s\S]*?)(?:###[^\n\S]*|(?:###)?$)|^(?:\s*#(?!##[^#]).*)+/; 623 | CODE = /^[-=]>/; 624 | MULTI_DENT = /^(?:\n[^\n\S]*)+/; 625 | SIMPLESTR = /^'[^\\']*(?:\\.[^\\']*)*'/; 626 | JSTOKEN = /^`[^\\`]*(?:\\.[^\\`]*)*`/; 627 | REGEX = /^\/(?![\s=])[^[\/\n\\]*(?:(?:\\[\s\S]|\[[^\]\n\\]*(?:\\[\s\S][^\]\n\\]*)*])[^[\/\n\\]*)*\/[imgy]{0,4}(?!\w)/; 628 | HEREGEX = /^\/{3}([\s\S]+?)\/{3}([imgy]{0,4})(?!\w)/; 629 | HEREGEX_OMIT = /\s+(?:#.*)?/g; 630 | MULTILINER = /\n/g; 631 | HEREDOC_INDENT = /\n+([^\n\S]*)/g; 632 | HEREDOC_ILLEGAL = /\*\//; 633 | ASSIGNED = /^\s*@?([$A-Za-z_][$\w\x7f-\uffff]*|['"].*['"])[^\n\S]*?[:=][^:=>]/; 634 | LINE_CONTINUER = /^\s*(?:,|\??\.(?![.\d])|::)/; 635 | TRAILING_SPACES = /\s+$/; 636 | NO_NEWLINE = /^(?:[-+*&|\/%=<>!.\\][<>=&|]*|and|or|is(?:nt)?|n(?:ot|ew)|delete|typeof|instanceof)$/; 637 | COMPOUND_ASSIGN = ['-=', '+=', '/=', '*=', '%=', '||=', '&&=', '?=', '<<=', '>>=', '>>>=', '&=', '^=', '|=']; 638 | UNARY = ['!', '~', 'NEW', 'TYPEOF', 'DELETE', 'DO']; 639 | LOGIC = ['&&', '||', '&', '|', '^']; 640 | SHIFT = ['<<', '>>', '>>>']; 641 | COMPARE = ['==', '!=', '<', '>', '<=', '>=']; 642 | MATH = ['*', '/', '%']; 643 | RELATION = ['IN', 'OF', 'INSTANCEOF']; 644 | BOOL = ['TRUE', 'FALSE', 'NULL', 'UNDEFINED']; 645 | NOT_REGEX = ['NUMBER', 'REGEX', 'BOOL', '++', '--', ']']; 646 | NOT_SPACED_REGEX = NOT_REGEX.concat(')', '}', 'THIS', 'IDENTIFIER', 'STRING'); 647 | CALLABLE = ['IDENTIFIER', 'STRING', 'REGEX', ')', ']', '}', '?', '::', '@', 'THIS', 'SUPER']; 648 | INDEXABLE = CALLABLE.concat('NUMBER', 'BOOL'); 649 | LINE_BREAK = ['INDENT', 'OUTDENT', 'TERMINATOR']; 650 | }).call(this); 651 | -------------------------------------------------------------------------------- /node_modules/coffee-script/lib/nodes.js: -------------------------------------------------------------------------------- 1 | (function() { 2 | var Access, Arr, Assign, Base, Block, Call, Class, Closure, Code, Comment, Existence, Extends, For, IDENTIFIER, IS_STRING, If, In, Index, LEVEL_ACCESS, LEVEL_COND, LEVEL_LIST, LEVEL_OP, LEVEL_PAREN, LEVEL_TOP, Literal, NEGATE, NO, Obj, Op, Param, Parens, Push, Range, Return, SIMPLENUM, Scope, Slice, Splat, Switch, TAB, THIS, Throw, Try, UTILITIES, Value, While, YES, compact, del, ends, extend, flatten, last, merge, multident, starts, unfoldSoak, utility, _ref; 3 | var __hasProp = Object.prototype.hasOwnProperty, __extends = function(child, parent) { 4 | for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } 5 | function ctor() { this.constructor = child; } 6 | ctor.prototype = parent.prototype; 7 | child.prototype = new ctor; 8 | child.__super__ = parent.prototype; 9 | return child; 10 | }, __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }; 11 | Scope = require('./scope').Scope; 12 | _ref = require('./helpers'), compact = _ref.compact, flatten = _ref.flatten, extend = _ref.extend, merge = _ref.merge, del = _ref.del, starts = _ref.starts, ends = _ref.ends, last = _ref.last; 13 | exports.extend = extend; 14 | YES = function() { 15 | return true; 16 | }; 17 | NO = function() { 18 | return false; 19 | }; 20 | THIS = function() { 21 | return this; 22 | }; 23 | NEGATE = function() { 24 | this.negated = !this.negated; 25 | return this; 26 | }; 27 | exports.Base = Base = (function() { 28 | function Base() {} 29 | Base.prototype.compile = function(o, lvl) { 30 | var node; 31 | o = extend({}, o); 32 | if (lvl) { 33 | o.level = lvl; 34 | } 35 | node = this.unfoldSoak(o) || this; 36 | node.tab = o.indent; 37 | if (o.level === LEVEL_TOP || !node.isStatement(o)) { 38 | return node.compileNode(o); 39 | } else { 40 | return node.compileClosure(o); 41 | } 42 | }; 43 | Base.prototype.compileClosure = function(o) { 44 | if (this.jumps() || this instanceof Throw) { 45 | throw SyntaxError('cannot use a pure statement in an expression.'); 46 | } 47 | o.sharedScope = true; 48 | return Closure.wrap(this).compileNode(o); 49 | }; 50 | Base.prototype.cache = function(o, level, reused) { 51 | var ref, sub; 52 | if (!this.isComplex()) { 53 | ref = level ? this.compile(o, level) : this; 54 | return [ref, ref]; 55 | } else { 56 | ref = new Literal(reused || o.scope.freeVariable('ref')); 57 | sub = new Assign(ref, this); 58 | if (level) { 59 | return [sub.compile(o, level), ref.value]; 60 | } else { 61 | return [sub, ref]; 62 | } 63 | } 64 | }; 65 | Base.prototype.compileLoopReference = function(o, name) { 66 | var src, tmp, _ref2; 67 | src = tmp = this.compile(o, LEVEL_LIST); 68 | if (!((-Infinity < (_ref2 = +src) && _ref2 < Infinity) || IDENTIFIER.test(src) && o.scope.check(src, true))) { 69 | src = "" + (tmp = o.scope.freeVariable(name)) + " = " + src; 70 | } 71 | return [src, tmp]; 72 | }; 73 | Base.prototype.makeReturn = function() { 74 | return new Return(this); 75 | }; 76 | Base.prototype.contains = function(pred) { 77 | var contains; 78 | contains = false; 79 | this.traverseChildren(false, function(node) { 80 | if (pred(node)) { 81 | contains = true; 82 | return false; 83 | } 84 | }); 85 | return contains; 86 | }; 87 | Base.prototype.containsType = function(type) { 88 | return this instanceof type || this.contains(function(node) { 89 | return node instanceof type; 90 | }); 91 | }; 92 | Base.prototype.lastNonComment = function(list) { 93 | var i; 94 | i = list.length; 95 | while (i--) { 96 | if (!(list[i] instanceof Comment)) { 97 | return list[i]; 98 | } 99 | } 100 | return null; 101 | }; 102 | Base.prototype.toString = function(idt, name) { 103 | var tree; 104 | if (idt == null) { 105 | idt = ''; 106 | } 107 | if (name == null) { 108 | name = this.constructor.name; 109 | } 110 | tree = '\n' + idt + name; 111 | if (this.soak) { 112 | tree += '?'; 113 | } 114 | this.eachChild(function(node) { 115 | return tree += node.toString(idt + TAB); 116 | }); 117 | return tree; 118 | }; 119 | Base.prototype.eachChild = function(func) { 120 | var attr, child, _i, _j, _len, _len2, _ref2, _ref3; 121 | if (!this.children) { 122 | return this; 123 | } 124 | _ref2 = this.children; 125 | for (_i = 0, _len = _ref2.length; _i < _len; _i++) { 126 | attr = _ref2[_i]; 127 | if (this[attr]) { 128 | _ref3 = flatten([this[attr]]); 129 | for (_j = 0, _len2 = _ref3.length; _j < _len2; _j++) { 130 | child = _ref3[_j]; 131 | if (func(child) === false) { 132 | return this; 133 | } 134 | } 135 | } 136 | } 137 | return this; 138 | }; 139 | Base.prototype.traverseChildren = function(crossScope, func) { 140 | return this.eachChild(function(child) { 141 | if (func(child) === false) { 142 | return false; 143 | } 144 | return child.traverseChildren(crossScope, func); 145 | }); 146 | }; 147 | Base.prototype.invert = function() { 148 | return new Op('!', this); 149 | }; 150 | Base.prototype.unwrapAll = function() { 151 | var node; 152 | node = this; 153 | while (node !== (node = node.unwrap())) { 154 | continue; 155 | } 156 | return node; 157 | }; 158 | Base.prototype.children = []; 159 | Base.prototype.isStatement = NO; 160 | Base.prototype.jumps = NO; 161 | Base.prototype.isComplex = YES; 162 | Base.prototype.isChainable = NO; 163 | Base.prototype.isAssignable = NO; 164 | Base.prototype.unwrap = THIS; 165 | Base.prototype.unfoldSoak = NO; 166 | Base.prototype.assigns = NO; 167 | return Base; 168 | })(); 169 | exports.Block = Block = (function() { 170 | __extends(Block, Base); 171 | function Block(nodes) { 172 | this.expressions = compact(flatten(nodes || [])); 173 | } 174 | Block.prototype.children = ['expressions']; 175 | Block.prototype.push = function(node) { 176 | this.expressions.push(node); 177 | return this; 178 | }; 179 | Block.prototype.pop = function() { 180 | return this.expressions.pop(); 181 | }; 182 | Block.prototype.unshift = function(node) { 183 | this.expressions.unshift(node); 184 | return this; 185 | }; 186 | Block.prototype.unwrap = function() { 187 | if (this.expressions.length === 1) { 188 | return this.expressions[0]; 189 | } else { 190 | return this; 191 | } 192 | }; 193 | Block.prototype.isEmpty = function() { 194 | return !this.expressions.length; 195 | }; 196 | Block.prototype.isStatement = function(o) { 197 | var exp, _i, _len, _ref2; 198 | _ref2 = this.expressions; 199 | for (_i = 0, _len = _ref2.length; _i < _len; _i++) { 200 | exp = _ref2[_i]; 201 | if (exp.isStatement(o)) { 202 | return true; 203 | } 204 | } 205 | return false; 206 | }; 207 | Block.prototype.jumps = function(o) { 208 | var exp, _i, _len, _ref2; 209 | _ref2 = this.expressions; 210 | for (_i = 0, _len = _ref2.length; _i < _len; _i++) { 211 | exp = _ref2[_i]; 212 | if (exp.jumps(o)) { 213 | return exp; 214 | } 215 | } 216 | }; 217 | Block.prototype.makeReturn = function() { 218 | var expr, len; 219 | len = this.expressions.length; 220 | while (len--) { 221 | expr = this.expressions[len]; 222 | if (!(expr instanceof Comment)) { 223 | this.expressions[len] = expr.makeReturn(); 224 | if (expr instanceof Return && !expr.expression) { 225 | this.expressions.splice(len, 1); 226 | } 227 | break; 228 | } 229 | } 230 | return this; 231 | }; 232 | Block.prototype.compile = function(o, level) { 233 | if (o == null) { 234 | o = {}; 235 | } 236 | if (o.scope) { 237 | return Block.__super__.compile.call(this, o, level); 238 | } else { 239 | return this.compileRoot(o); 240 | } 241 | }; 242 | Block.prototype.compileNode = function(o) { 243 | var code, codes, node, top, _i, _len, _ref2; 244 | this.tab = o.indent; 245 | top = o.level === LEVEL_TOP; 246 | codes = []; 247 | _ref2 = this.expressions; 248 | for (_i = 0, _len = _ref2.length; _i < _len; _i++) { 249 | node = _ref2[_i]; 250 | node = node.unwrapAll(); 251 | node = node.unfoldSoak(o) || node; 252 | if (top) { 253 | node.front = true; 254 | code = node.compile(o); 255 | codes.push(node.isStatement(o) ? code : this.tab + code + ';'); 256 | } else { 257 | codes.push(node.compile(o, LEVEL_LIST)); 258 | } 259 | } 260 | if (top) { 261 | return codes.join('\n'); 262 | } 263 | code = codes.join(', ') || 'void 0'; 264 | if (codes.length > 1 && o.level >= LEVEL_LIST) { 265 | return "(" + code + ")"; 266 | } else { 267 | return code; 268 | } 269 | }; 270 | Block.prototype.compileRoot = function(o) { 271 | var code; 272 | o.indent = this.tab = o.bare ? '' : TAB; 273 | o.scope = new Scope(null, this, null); 274 | o.level = LEVEL_TOP; 275 | code = this.compileWithDeclarations(o); 276 | if (o.bare) { 277 | return code; 278 | } else { 279 | return "(function() {\n" + code + "\n}).call(this);\n"; 280 | } 281 | }; 282 | Block.prototype.compileWithDeclarations = function(o) { 283 | var code, exp, i, post, rest, scope, _len, _ref2; 284 | code = post = ''; 285 | _ref2 = this.expressions; 286 | for (i = 0, _len = _ref2.length; i < _len; i++) { 287 | exp = _ref2[i]; 288 | exp = exp.unwrap(); 289 | if (!(exp instanceof Comment || exp instanceof Literal)) { 290 | break; 291 | } 292 | } 293 | o = merge(o, { 294 | level: LEVEL_TOP 295 | }); 296 | if (i) { 297 | rest = this.expressions.splice(i, this.expressions.length); 298 | code = this.compileNode(o); 299 | this.expressions = rest; 300 | } 301 | post = this.compileNode(o); 302 | scope = o.scope; 303 | if (scope.expressions === this) { 304 | if (o.scope.hasDeclarations()) { 305 | code += "" + this.tab + "var " + (scope.declaredVariables().join(', ')) + ";\n"; 306 | } 307 | if (scope.hasAssignments) { 308 | code += "" + this.tab + "var " + (multident(scope.assignedVariables().join(', '), this.tab)) + ";\n"; 309 | } 310 | } 311 | return code + post; 312 | }; 313 | Block.wrap = function(nodes) { 314 | if (nodes.length === 1 && nodes[0] instanceof Block) { 315 | return nodes[0]; 316 | } 317 | return new Block(nodes); 318 | }; 319 | return Block; 320 | })(); 321 | exports.Literal = Literal = (function() { 322 | __extends(Literal, Base); 323 | function Literal(value) { 324 | this.value = value; 325 | } 326 | Literal.prototype.makeReturn = function() { 327 | if (this.isStatement()) { 328 | return this; 329 | } else { 330 | return new Return(this); 331 | } 332 | }; 333 | Literal.prototype.isAssignable = function() { 334 | return IDENTIFIER.test(this.value); 335 | }; 336 | Literal.prototype.isStatement = function() { 337 | var _ref2; 338 | return (_ref2 = this.value) === 'break' || _ref2 === 'continue' || _ref2 === 'debugger'; 339 | }; 340 | Literal.prototype.isComplex = NO; 341 | Literal.prototype.assigns = function(name) { 342 | return name === this.value; 343 | }; 344 | Literal.prototype.jumps = function(o) { 345 | if (!this.isStatement()) { 346 | return false; 347 | } 348 | if (!(o && (o.loop || o.block && (this.value !== 'continue')))) { 349 | return this; 350 | } else { 351 | return false; 352 | } 353 | }; 354 | Literal.prototype.compileNode = function(o) { 355 | var code; 356 | code = this.isUndefined ? o.level >= LEVEL_ACCESS ? '(void 0)' : 'void 0' : this.value.reserved ? "\"" + this.value + "\"" : this.value; 357 | if (this.isStatement()) { 358 | return "" + this.tab + code + ";"; 359 | } else { 360 | return code; 361 | } 362 | }; 363 | Literal.prototype.toString = function() { 364 | return ' "' + this.value + '"'; 365 | }; 366 | return Literal; 367 | })(); 368 | exports.Return = Return = (function() { 369 | __extends(Return, Base); 370 | function Return(expr) { 371 | if (expr && !expr.unwrap().isUndefined) { 372 | this.expression = expr; 373 | } 374 | } 375 | Return.prototype.children = ['expression']; 376 | Return.prototype.isStatement = YES; 377 | Return.prototype.makeReturn = THIS; 378 | Return.prototype.jumps = THIS; 379 | Return.prototype.compile = function(o, level) { 380 | var expr, _ref2; 381 | expr = (_ref2 = this.expression) != null ? _ref2.makeReturn() : void 0; 382 | if (expr && !(expr instanceof Return)) { 383 | return expr.compile(o, level); 384 | } else { 385 | return Return.__super__.compile.call(this, o, level); 386 | } 387 | }; 388 | Return.prototype.compileNode = function(o) { 389 | return this.tab + ("return" + (this.expression ? ' ' + this.expression.compile(o, LEVEL_PAREN) : '') + ";"); 390 | }; 391 | return Return; 392 | })(); 393 | exports.Value = Value = (function() { 394 | __extends(Value, Base); 395 | function Value(base, props, tag) { 396 | if (!props && base instanceof Value) { 397 | return base; 398 | } 399 | this.base = base; 400 | this.properties = props || []; 401 | if (tag) { 402 | this[tag] = true; 403 | } 404 | return this; 405 | } 406 | Value.prototype.children = ['base', 'properties']; 407 | Value.prototype.push = function(prop) { 408 | this.properties.push(prop); 409 | return this; 410 | }; 411 | Value.prototype.hasProperties = function() { 412 | return !!this.properties.length; 413 | }; 414 | Value.prototype.isArray = function() { 415 | return !this.properties.length && this.base instanceof Arr; 416 | }; 417 | Value.prototype.isComplex = function() { 418 | return this.hasProperties() || this.base.isComplex(); 419 | }; 420 | Value.prototype.isAssignable = function() { 421 | return this.hasProperties() || this.base.isAssignable(); 422 | }; 423 | Value.prototype.isSimpleNumber = function() { 424 | return this.base instanceof Literal && SIMPLENUM.test(this.base.value); 425 | }; 426 | Value.prototype.isAtomic = function() { 427 | var node, _i, _len, _ref2; 428 | _ref2 = this.properties.concat(this.base); 429 | for (_i = 0, _len = _ref2.length; _i < _len; _i++) { 430 | node = _ref2[_i]; 431 | if (node.soak || node instanceof Call) { 432 | return false; 433 | } 434 | } 435 | return true; 436 | }; 437 | Value.prototype.isStatement = function(o) { 438 | return !this.properties.length && this.base.isStatement(o); 439 | }; 440 | Value.prototype.assigns = function(name) { 441 | return !this.properties.length && this.base.assigns(name); 442 | }; 443 | Value.prototype.jumps = function(o) { 444 | return !this.properties.length && this.base.jumps(o); 445 | }; 446 | Value.prototype.isObject = function(onlyGenerated) { 447 | if (this.properties.length) { 448 | return false; 449 | } 450 | return (this.base instanceof Obj) && (!onlyGenerated || this.base.generated); 451 | }; 452 | Value.prototype.isSplice = function() { 453 | return last(this.properties) instanceof Slice; 454 | }; 455 | Value.prototype.makeReturn = function() { 456 | if (this.properties.length) { 457 | return Value.__super__.makeReturn.call(this); 458 | } else { 459 | return this.base.makeReturn(); 460 | } 461 | }; 462 | Value.prototype.unwrap = function() { 463 | if (this.properties.length) { 464 | return this; 465 | } else { 466 | return this.base; 467 | } 468 | }; 469 | Value.prototype.cacheReference = function(o) { 470 | var base, bref, name, nref; 471 | name = last(this.properties); 472 | if (this.properties.length < 2 && !this.base.isComplex() && !(name != null ? name.isComplex() : void 0)) { 473 | return [this, this]; 474 | } 475 | base = new Value(this.base, this.properties.slice(0, -1)); 476 | if (base.isComplex()) { 477 | bref = new Literal(o.scope.freeVariable('base')); 478 | base = new Value(new Parens(new Assign(bref, base))); 479 | } 480 | if (!name) { 481 | return [base, bref]; 482 | } 483 | if (name.isComplex()) { 484 | nref = new Literal(o.scope.freeVariable('name')); 485 | name = new Index(new Assign(nref, name.index)); 486 | nref = new Index(nref); 487 | } 488 | return [base.push(name), new Value(bref || base.base, [nref || name])]; 489 | }; 490 | Value.prototype.compileNode = function(o) { 491 | var code, prop, props, _i, _len; 492 | this.base.front = this.front; 493 | props = this.properties; 494 | code = this.base.compile(o, props.length ? LEVEL_ACCESS : null); 495 | if (props[0] instanceof Access && this.isSimpleNumber()) { 496 | code = "(" + code + ")"; 497 | } 498 | for (_i = 0, _len = props.length; _i < _len; _i++) { 499 | prop = props[_i]; 500 | code += prop.compile(o); 501 | } 502 | return code; 503 | }; 504 | Value.prototype.unfoldSoak = function(o) { 505 | var result; 506 | if (this.unfoldedSoak != null) { 507 | return this.unfoldedSoak; 508 | } 509 | result = __bind(function() { 510 | var fst, i, ifn, prop, ref, snd, _len, _ref2; 511 | if (ifn = this.base.unfoldSoak(o)) { 512 | Array.prototype.push.apply(ifn.body.properties, this.properties); 513 | return ifn; 514 | } 515 | _ref2 = this.properties; 516 | for (i = 0, _len = _ref2.length; i < _len; i++) { 517 | prop = _ref2[i]; 518 | if (prop.soak) { 519 | prop.soak = false; 520 | fst = new Value(this.base, this.properties.slice(0, i)); 521 | snd = new Value(this.base, this.properties.slice(i)); 522 | if (fst.isComplex()) { 523 | ref = new Literal(o.scope.freeVariable('ref')); 524 | fst = new Parens(new Assign(ref, fst)); 525 | snd.base = ref; 526 | } 527 | return new If(new Existence(fst), snd, { 528 | soak: true 529 | }); 530 | } 531 | } 532 | return null; 533 | }, this)(); 534 | return this.unfoldedSoak = result || false; 535 | }; 536 | return Value; 537 | })(); 538 | exports.Comment = Comment = (function() { 539 | __extends(Comment, Base); 540 | function Comment(comment) { 541 | this.comment = comment; 542 | } 543 | Comment.prototype.isStatement = YES; 544 | Comment.prototype.makeReturn = THIS; 545 | Comment.prototype.compileNode = function(o, level) { 546 | var code; 547 | code = '/*' + multident(this.comment, this.tab) + '*/'; 548 | if ((level || o.level) === LEVEL_TOP) { 549 | code = o.indent + code; 550 | } 551 | return code; 552 | }; 553 | return Comment; 554 | })(); 555 | exports.Call = Call = (function() { 556 | __extends(Call, Base); 557 | function Call(variable, args, soak) { 558 | this.args = args != null ? args : []; 559 | this.soak = soak; 560 | this.isNew = false; 561 | this.isSuper = variable === 'super'; 562 | this.variable = this.isSuper ? null : variable; 563 | } 564 | Call.prototype.children = ['variable', 'args']; 565 | Call.prototype.newInstance = function() { 566 | var base; 567 | base = this.variable.base || this.variable; 568 | if (base instanceof Call) { 569 | base.newInstance(); 570 | } else { 571 | this.isNew = true; 572 | } 573 | return this; 574 | }; 575 | Call.prototype.superReference = function(o) { 576 | var method, name; 577 | method = o.scope.method; 578 | if (!method) { 579 | throw SyntaxError('cannot call super outside of a function.'); 580 | } 581 | name = method.name; 582 | if (!name) { 583 | throw SyntaxError('cannot call super on an anonymous function.'); 584 | } 585 | if (method.klass) { 586 | return "" + method.klass + ".__super__." + name; 587 | } else { 588 | return "" + name + ".__super__.constructor"; 589 | } 590 | }; 591 | Call.prototype.unfoldSoak = function(o) { 592 | var call, ifn, left, list, rite, _i, _len, _ref2, _ref3; 593 | if (this.soak) { 594 | if (this.variable) { 595 | if (ifn = unfoldSoak(o, this, 'variable')) { 596 | return ifn; 597 | } 598 | _ref2 = new Value(this.variable).cacheReference(o), left = _ref2[0], rite = _ref2[1]; 599 | } else { 600 | left = new Literal(this.superReference(o)); 601 | rite = new Value(left); 602 | } 603 | rite = new Call(rite, this.args); 604 | rite.isNew = this.isNew; 605 | left = new Literal("typeof " + (left.compile(o)) + " === \"function\""); 606 | return new If(left, new Value(rite), { 607 | soak: true 608 | }); 609 | } 610 | call = this; 611 | list = []; 612 | while (true) { 613 | if (call.variable instanceof Call) { 614 | list.push(call); 615 | call = call.variable; 616 | continue; 617 | } 618 | if (!(call.variable instanceof Value)) { 619 | break; 620 | } 621 | list.push(call); 622 | if (!((call = call.variable.base) instanceof Call)) { 623 | break; 624 | } 625 | } 626 | _ref3 = list.reverse(); 627 | for (_i = 0, _len = _ref3.length; _i < _len; _i++) { 628 | call = _ref3[_i]; 629 | if (ifn) { 630 | if (call.variable instanceof Call) { 631 | call.variable = ifn; 632 | } else { 633 | call.variable.base = ifn; 634 | } 635 | } 636 | ifn = unfoldSoak(o, call, 'variable'); 637 | } 638 | return ifn; 639 | }; 640 | Call.prototype.filterImplicitObjects = function(list) { 641 | var node, nodes, obj, prop, properties, _i, _j, _len, _len2, _ref2; 642 | nodes = []; 643 | for (_i = 0, _len = list.length; _i < _len; _i++) { 644 | node = list[_i]; 645 | if (!((typeof node.isObject === "function" ? node.isObject() : void 0) && node.base.generated)) { 646 | nodes.push(node); 647 | continue; 648 | } 649 | obj = null; 650 | _ref2 = node.base.properties; 651 | for (_j = 0, _len2 = _ref2.length; _j < _len2; _j++) { 652 | prop = _ref2[_j]; 653 | if (prop instanceof Assign) { 654 | if (!obj) { 655 | nodes.push(obj = new Obj(properties = [], true)); 656 | } 657 | properties.push(prop); 658 | } else { 659 | nodes.push(prop); 660 | obj = null; 661 | } 662 | } 663 | } 664 | return nodes; 665 | }; 666 | Call.prototype.compileNode = function(o) { 667 | var arg, args, code, _ref2; 668 | if ((_ref2 = this.variable) != null) { 669 | _ref2.front = this.front; 670 | } 671 | if (code = Splat.compileSplattedArray(o, this.args, true)) { 672 | return this.compileSplat(o, code); 673 | } 674 | args = this.filterImplicitObjects(this.args); 675 | args = ((function() { 676 | var _i, _len, _results; 677 | _results = []; 678 | for (_i = 0, _len = args.length; _i < _len; _i++) { 679 | arg = args[_i]; 680 | _results.push(arg.compile(o, LEVEL_LIST)); 681 | } 682 | return _results; 683 | })()).join(', '); 684 | if (this.isSuper) { 685 | return this.superReference(o) + (".call(this" + (args && ', ' + args) + ")"); 686 | } else { 687 | return (this.isNew ? 'new ' : '') + this.variable.compile(o, LEVEL_ACCESS) + ("(" + args + ")"); 688 | } 689 | }; 690 | Call.prototype.compileSuper = function(args, o) { 691 | return "" + (this.superReference(o)) + ".call(this" + (args.length ? ', ' : '') + args + ")"; 692 | }; 693 | Call.prototype.compileSplat = function(o, splatArgs) { 694 | var base, fun, idt, name, ref; 695 | if (this.isSuper) { 696 | return "" + (this.superReference(o)) + ".apply(this, " + splatArgs + ")"; 697 | } 698 | if (this.isNew) { 699 | idt = this.tab + TAB; 700 | return "(function(func, args, ctor) {\n" + idt + "ctor.prototype = func.prototype;\n" + idt + "var child = new ctor, result = func.apply(child, args);\n" + idt + "return typeof result === \"object\" ? result : child;\n" + this.tab + "})(" + (this.variable.compile(o, LEVEL_LIST)) + ", " + splatArgs + ", function() {})"; 701 | } 702 | base = new Value(this.variable); 703 | if ((name = base.properties.pop()) && base.isComplex()) { 704 | ref = o.scope.freeVariable('ref'); 705 | fun = "(" + ref + " = " + (base.compile(o, LEVEL_LIST)) + ")" + (name.compile(o)); 706 | } else { 707 | fun = base.compile(o, LEVEL_ACCESS); 708 | if (SIMPLENUM.test(fun)) { 709 | fun = "(" + fun + ")"; 710 | } 711 | if (name) { 712 | ref = fun; 713 | fun += name.compile(o); 714 | } else { 715 | ref = 'null'; 716 | } 717 | } 718 | return "" + fun + ".apply(" + ref + ", " + splatArgs + ")"; 719 | }; 720 | return Call; 721 | })(); 722 | exports.Extends = Extends = (function() { 723 | __extends(Extends, Base); 724 | function Extends(child, parent) { 725 | this.child = child; 726 | this.parent = parent; 727 | } 728 | Extends.prototype.children = ['child', 'parent']; 729 | Extends.prototype.compile = function(o) { 730 | utility('hasProp'); 731 | return new Call(new Value(new Literal(utility('extends'))), [this.child, this.parent]).compile(o); 732 | }; 733 | return Extends; 734 | })(); 735 | exports.Access = Access = (function() { 736 | __extends(Access, Base); 737 | function Access(name, tag) { 738 | this.name = name; 739 | this.name.asKey = true; 740 | this.proto = tag === 'proto' ? '.prototype' : ''; 741 | this.soak = tag === 'soak'; 742 | } 743 | Access.prototype.children = ['name']; 744 | Access.prototype.compile = function(o) { 745 | var name; 746 | name = this.name.compile(o); 747 | return this.proto + (IS_STRING.test(name) ? "[" + name + "]" : "." + name); 748 | }; 749 | Access.prototype.isComplex = NO; 750 | return Access; 751 | })(); 752 | exports.Index = Index = (function() { 753 | __extends(Index, Base); 754 | function Index(index) { 755 | this.index = index; 756 | } 757 | Index.prototype.children = ['index']; 758 | Index.prototype.compile = function(o) { 759 | return (this.proto ? '.prototype' : '') + ("[" + (this.index.compile(o, LEVEL_PAREN)) + "]"); 760 | }; 761 | Index.prototype.isComplex = function() { 762 | return this.index.isComplex(); 763 | }; 764 | return Index; 765 | })(); 766 | exports.Range = Range = (function() { 767 | __extends(Range, Base); 768 | Range.prototype.children = ['from', 'to']; 769 | function Range(from, to, tag) { 770 | this.from = from; 771 | this.to = to; 772 | this.exclusive = tag === 'exclusive'; 773 | this.equals = this.exclusive ? '' : '='; 774 | } 775 | Range.prototype.compileVariables = function(o) { 776 | var parts, _ref2, _ref3, _ref4; 777 | o = merge(o, { 778 | top: true 779 | }); 780 | _ref2 = this.from.cache(o, LEVEL_LIST), this.from = _ref2[0], this.fromVar = _ref2[1]; 781 | _ref3 = this.to.cache(o, LEVEL_LIST), this.to = _ref3[0], this.toVar = _ref3[1]; 782 | _ref4 = [this.fromVar.match(SIMPLENUM), this.toVar.match(SIMPLENUM)], this.fromNum = _ref4[0], this.toNum = _ref4[1]; 783 | parts = []; 784 | if (this.from !== this.fromVar) { 785 | parts.push(this.from); 786 | } 787 | if (this.to !== this.toVar) { 788 | return parts.push(this.to); 789 | } 790 | }; 791 | Range.prototype.compileNode = function(o) { 792 | var cond, condPart, idx, step, stepPart, stepvar, varPart; 793 | this.compileVariables(o); 794 | if (!o.index) { 795 | return this.compileArray(o); 796 | } 797 | if (this.fromNum && this.toNum) { 798 | return this.compileSimple(o); 799 | } 800 | idx = del(o, 'index'); 801 | step = del(o, 'step'); 802 | if (step) { 803 | stepvar = o.scope.freeVariable("step"); 804 | } 805 | varPart = ("" + idx + " = " + this.from) + (this.to !== this.toVar ? ", " + this.to : '') + (step ? ", " + stepvar + " = " + (step.compile(o)) : ''); 806 | cond = "" + this.fromVar + " <= " + this.toVar; 807 | condPart = "" + cond + " ? " + idx + " <" + this.equals + " " + this.toVar + " : " + idx + " >" + this.equals + " " + this.toVar; 808 | stepPart = step ? "" + idx + " += " + stepvar : "" + cond + " ? " + idx + "++ : " + idx + "--"; 809 | return "" + varPart + "; " + condPart + "; " + stepPart; 810 | }; 811 | Range.prototype.compileSimple = function(o) { 812 | var condPart, from, idx, step, stepPart, stepvar, to, varPart, _ref2; 813 | _ref2 = [+this.fromNum, +this.toNum], from = _ref2[0], to = _ref2[1]; 814 | idx = del(o, 'index'); 815 | step = del(o, 'step'); 816 | if (step) { 817 | stepvar = o.scope.freeVariable("step"); 818 | } 819 | varPart = "" + idx + " = " + from; 820 | if (step) { 821 | varPart += ", " + stepvar + " = " + (step.compile(o)); 822 | } 823 | condPart = from <= to ? "" + idx + " <" + this.equals + " " + to : "" + idx + " >" + this.equals + " " + to; 824 | if (step) { 825 | stepPart = "" + idx + " += " + stepvar; 826 | } 827 | if (!step) { 828 | stepPart = (from <= to ? "" + idx + "++" : "" + idx + "--"); 829 | } 830 | return "" + varPart + "; " + condPart + "; " + stepPart; 831 | }; 832 | Range.prototype.compileArray = function(o) { 833 | var body, cond, i, idt, post, pre, range, result, vars, _i, _ref2, _ref3, _results; 834 | if (this.fromNum && this.toNum && Math.abs(this.fromNum - this.toNum) <= 20) { 835 | range = (function() { 836 | _results = []; 837 | for (var _i = _ref2 = +this.fromNum, _ref3 = +this.toNum; _ref2 <= _ref3 ? _i <= _ref3 : _i >= _ref3; _ref2 <= _ref3 ? _i++ : _i--){ _results.push(_i); } 838 | return _results; 839 | }).apply(this, arguments); 840 | if (this.exclusive) { 841 | range.pop(); 842 | } 843 | return "[" + (range.join(', ')) + "]"; 844 | } 845 | idt = this.tab + TAB; 846 | i = o.scope.freeVariable('i'); 847 | result = o.scope.freeVariable('results'); 848 | pre = "\n" + idt + result + " = [];"; 849 | if (this.fromNum && this.toNum) { 850 | o.index = i; 851 | body = this.compileSimple(o); 852 | } else { 853 | vars = ("" + i + " = " + this.from) + (this.to !== this.toVar ? ", " + this.to : ''); 854 | cond = "" + this.fromVar + " <= " + this.toVar; 855 | body = "var " + vars + "; " + cond + " ? " + i + " <" + this.equals + " " + this.toVar + " : " + i + " >" + this.equals + " " + this.toVar + "; " + cond + " ? " + i + "++ : " + i + "--"; 856 | } 857 | post = "{ " + result + ".push(" + i + "); }\n" + idt + "return " + result + ";\n" + o.indent; 858 | return "(function() {" + pre + "\n" + idt + "for (" + body + ")" + post + "}).apply(this, arguments)"; 859 | }; 860 | return Range; 861 | })(); 862 | exports.Slice = Slice = (function() { 863 | __extends(Slice, Base); 864 | Slice.prototype.children = ['range']; 865 | function Slice(range) { 866 | this.range = range; 867 | Slice.__super__.constructor.call(this); 868 | } 869 | Slice.prototype.compileNode = function(o) { 870 | var compiled, from, fromStr, to, toStr, _ref2; 871 | _ref2 = this.range, to = _ref2.to, from = _ref2.from; 872 | fromStr = from && from.compile(o, LEVEL_PAREN) || '0'; 873 | compiled = to && to.compile(o, LEVEL_PAREN); 874 | if (to && !(!this.range.exclusive && +compiled === -1)) { 875 | toStr = ', ' + (this.range.exclusive ? compiled : SIMPLENUM.test(compiled) ? (+compiled + 1).toString() : "(" + compiled + " + 1) || 9e9"); 876 | } 877 | return ".slice(" + fromStr + (toStr || '') + ")"; 878 | }; 879 | return Slice; 880 | })(); 881 | exports.Obj = Obj = (function() { 882 | __extends(Obj, Base); 883 | function Obj(props, generated) { 884 | this.generated = generated != null ? generated : false; 885 | this.objects = this.properties = props || []; 886 | } 887 | Obj.prototype.children = ['properties']; 888 | Obj.prototype.compileNode = function(o) { 889 | var i, idt, indent, join, lastNoncom, node, obj, prop, props, _i, _len; 890 | props = this.properties; 891 | if (!props.length) { 892 | if (this.front) { 893 | return '({})'; 894 | } else { 895 | return '{}'; 896 | } 897 | } 898 | if (this.generated) { 899 | for (_i = 0, _len = props.length; _i < _len; _i++) { 900 | node = props[_i]; 901 | if (node instanceof Value) { 902 | throw new Error('cannot have an implicit value in an implicit object'); 903 | } 904 | } 905 | } 906 | idt = o.indent += TAB; 907 | lastNoncom = this.lastNonComment(this.properties); 908 | props = (function() { 909 | var _len2, _results; 910 | _results = []; 911 | for (i = 0, _len2 = props.length; i < _len2; i++) { 912 | prop = props[i]; 913 | join = i === props.length - 1 ? '' : prop === lastNoncom || prop instanceof Comment ? '\n' : ',\n'; 914 | indent = prop instanceof Comment ? '' : idt; 915 | if (prop instanceof Value && prop["this"]) { 916 | prop = new Assign(prop.properties[0].name, prop, 'object'); 917 | } 918 | if (!(prop instanceof Comment)) { 919 | if (!(prop instanceof Assign)) { 920 | prop = new Assign(prop, prop, 'object'); 921 | } 922 | (prop.variable.base || prop.variable).asKey = true; 923 | } 924 | _results.push(indent + prop.compile(o, LEVEL_TOP) + join); 925 | } 926 | return _results; 927 | })(); 928 | props = props.join(''); 929 | obj = "{" + (props && '\n' + props + '\n' + this.tab) + "}"; 930 | if (this.front) { 931 | return "(" + obj + ")"; 932 | } else { 933 | return obj; 934 | } 935 | }; 936 | Obj.prototype.assigns = function(name) { 937 | var prop, _i, _len, _ref2; 938 | _ref2 = this.properties; 939 | for (_i = 0, _len = _ref2.length; _i < _len; _i++) { 940 | prop = _ref2[_i]; 941 | if (prop.assigns(name)) { 942 | return true; 943 | } 944 | } 945 | return false; 946 | }; 947 | return Obj; 948 | })(); 949 | exports.Arr = Arr = (function() { 950 | __extends(Arr, Base); 951 | function Arr(objs) { 952 | this.objects = objs || []; 953 | } 954 | Arr.prototype.children = ['objects']; 955 | Arr.prototype.filterImplicitObjects = Call.prototype.filterImplicitObjects; 956 | Arr.prototype.compileNode = function(o) { 957 | var code, obj, objs; 958 | if (!this.objects.length) { 959 | return '[]'; 960 | } 961 | o.indent += TAB; 962 | objs = this.filterImplicitObjects(this.objects); 963 | if (code = Splat.compileSplattedArray(o, objs)) { 964 | return code; 965 | } 966 | code = ((function() { 967 | var _i, _len, _results; 968 | _results = []; 969 | for (_i = 0, _len = objs.length; _i < _len; _i++) { 970 | obj = objs[_i]; 971 | _results.push(obj.compile(o, LEVEL_LIST)); 972 | } 973 | return _results; 974 | })()).join(', '); 975 | if (code.indexOf('\n') >= 0) { 976 | return "[\n" + o.indent + code + "\n" + this.tab + "]"; 977 | } else { 978 | return "[" + code + "]"; 979 | } 980 | }; 981 | Arr.prototype.assigns = function(name) { 982 | var obj, _i, _len, _ref2; 983 | _ref2 = this.objects; 984 | for (_i = 0, _len = _ref2.length; _i < _len; _i++) { 985 | obj = _ref2[_i]; 986 | if (obj.assigns(name)) { 987 | return true; 988 | } 989 | } 990 | return false; 991 | }; 992 | return Arr; 993 | })(); 994 | exports.Class = Class = (function() { 995 | __extends(Class, Base); 996 | function Class(variable, parent, body) { 997 | this.variable = variable; 998 | this.parent = parent; 999 | this.body = body != null ? body : new Block; 1000 | this.boundFuncs = []; 1001 | this.body.classBody = true; 1002 | } 1003 | Class.prototype.children = ['variable', 'parent', 'body']; 1004 | Class.prototype.determineName = function() { 1005 | var decl, tail; 1006 | if (!this.variable) { 1007 | return null; 1008 | } 1009 | decl = (tail = last(this.variable.properties)) ? tail instanceof Access && tail.name.value : this.variable.base.value; 1010 | return decl && (decl = IDENTIFIER.test(decl) && decl); 1011 | }; 1012 | Class.prototype.setContext = function(name) { 1013 | return this.body.traverseChildren(false, function(node) { 1014 | if (node.classBody) { 1015 | return false; 1016 | } 1017 | if (node instanceof Literal && node.value === 'this') { 1018 | return node.value = name; 1019 | } else if (node instanceof Code) { 1020 | node.klass = name; 1021 | if (node.bound) { 1022 | return node.context = name; 1023 | } 1024 | } 1025 | }); 1026 | }; 1027 | Class.prototype.addBoundFunctions = function(o) { 1028 | var bname, bvar, _i, _len, _ref2, _results; 1029 | if (this.boundFuncs.length) { 1030 | _ref2 = this.boundFuncs; 1031 | _results = []; 1032 | for (_i = 0, _len = _ref2.length; _i < _len; _i++) { 1033 | bvar = _ref2[_i]; 1034 | bname = bvar.compile(o); 1035 | _results.push(this.ctor.body.unshift(new Literal("this." + bname + " = " + (utility('bind')) + "(this." + bname + ", this)"))); 1036 | } 1037 | return _results; 1038 | } 1039 | }; 1040 | Class.prototype.addProperties = function(node, name, o) { 1041 | var assign, base, exprs, func, props; 1042 | props = node.base.properties.slice(0); 1043 | exprs = (function() { 1044 | var _results; 1045 | _results = []; 1046 | while (assign = props.shift()) { 1047 | if (assign instanceof Assign) { 1048 | base = assign.variable.base; 1049 | delete assign.context; 1050 | func = assign.value; 1051 | if (base.value === 'constructor') { 1052 | if (this.ctor) { 1053 | throw new Error('cannot define more than one constructor in a class'); 1054 | } 1055 | if (func.bound) { 1056 | throw new Error('cannot define a constructor as a bound function'); 1057 | } 1058 | if (func instanceof Code) { 1059 | assign = this.ctor = func; 1060 | } else { 1061 | this.externalCtor = o.scope.freeVariable('class'); 1062 | assign = new Assign(new Literal(this.externalCtor), func); 1063 | } 1064 | } else { 1065 | if (!assign.variable["this"]) { 1066 | assign.variable = new Value(new Literal(name), [new Access(base, 'proto')]); 1067 | } 1068 | if (func instanceof Code && func.bound) { 1069 | this.boundFuncs.push(base); 1070 | func.bound = false; 1071 | } 1072 | } 1073 | } 1074 | _results.push(assign); 1075 | } 1076 | return _results; 1077 | }).call(this); 1078 | return compact(exprs); 1079 | }; 1080 | Class.prototype.walkBody = function(name, o) { 1081 | return this.traverseChildren(false, __bind(function(child) { 1082 | var exps, i, node, _len, _ref2; 1083 | if (child instanceof Class) { 1084 | return false; 1085 | } 1086 | if (child instanceof Block) { 1087 | _ref2 = exps = child.expressions; 1088 | for (i = 0, _len = _ref2.length; i < _len; i++) { 1089 | node = _ref2[i]; 1090 | if (node instanceof Value && node.isObject(true)) { 1091 | exps[i] = this.addProperties(node, name, o); 1092 | } 1093 | } 1094 | return child.expressions = exps = flatten(exps); 1095 | } 1096 | }, this)); 1097 | }; 1098 | Class.prototype.ensureConstructor = function(name) { 1099 | if (!this.ctor) { 1100 | this.ctor = new Code; 1101 | if (this.parent) { 1102 | this.ctor.body.push(new Literal("" + name + ".__super__.constructor.apply(this, arguments)")); 1103 | } 1104 | if (this.externalCtor) { 1105 | this.ctor.body.push(new Literal("" + this.externalCtor + ".apply(this, arguments)")); 1106 | } 1107 | this.body.expressions.unshift(this.ctor); 1108 | } 1109 | this.ctor.ctor = this.ctor.name = name; 1110 | this.ctor.klass = null; 1111 | return this.ctor.noReturn = true; 1112 | }; 1113 | Class.prototype.compileNode = function(o) { 1114 | var decl, klass, lname, name; 1115 | decl = this.determineName(); 1116 | name = decl || this.name || '_Class'; 1117 | lname = new Literal(name); 1118 | this.setContext(name); 1119 | this.walkBody(name, o); 1120 | this.ensureConstructor(name); 1121 | if (this.parent) { 1122 | this.body.expressions.unshift(new Extends(lname, this.parent)); 1123 | } 1124 | if (!(this.ctor instanceof Code)) { 1125 | this.body.expressions.unshift(this.ctor); 1126 | } 1127 | this.body.expressions.push(lname); 1128 | this.addBoundFunctions(o); 1129 | klass = new Parens(Closure.wrap(this.body), true); 1130 | if (this.variable) { 1131 | klass = new Assign(this.variable, klass); 1132 | } 1133 | return klass.compile(o); 1134 | }; 1135 | return Class; 1136 | })(); 1137 | exports.Assign = Assign = (function() { 1138 | __extends(Assign, Base); 1139 | function Assign(variable, value, context, options) { 1140 | this.variable = variable; 1141 | this.value = value; 1142 | this.context = context; 1143 | this.param = options && options.param; 1144 | } 1145 | Assign.prototype.METHOD_DEF = /^(?:(\S+)\.prototype\.|\S+?)?\b([$A-Za-z_][$\w\x7f-\uffff]*)$/; 1146 | Assign.prototype.children = ['variable', 'value']; 1147 | Assign.prototype.assigns = function(name) { 1148 | return this[this.context === 'object' ? 'value' : 'variable'].assigns(name); 1149 | }; 1150 | Assign.prototype.unfoldSoak = function(o) { 1151 | return unfoldSoak(o, this, 'variable'); 1152 | }; 1153 | Assign.prototype.compileNode = function(o) { 1154 | var isValue, match, name, val, _ref2; 1155 | if (isValue = this.variable instanceof Value) { 1156 | if (this.variable.isArray() || this.variable.isObject()) { 1157 | return this.compilePatternMatch(o); 1158 | } 1159 | if (this.variable.isSplice()) { 1160 | return this.compileSplice(o); 1161 | } 1162 | if ((_ref2 = this.context) === '||=' || _ref2 === '&&=' || _ref2 === '?=') { 1163 | return this.compileConditional(o); 1164 | } 1165 | } 1166 | name = this.variable.compile(o, LEVEL_LIST); 1167 | if (!(this.context || this.variable.isAssignable())) { 1168 | throw SyntaxError("\"" + (this.variable.compile(o)) + "\" cannot be assigned."); 1169 | } 1170 | if (!(this.context || isValue && (this.variable.namespaced || this.variable.hasProperties()))) { 1171 | if (this.param) { 1172 | o.scope.add(name, 'var'); 1173 | } else { 1174 | o.scope.find(name); 1175 | } 1176 | } 1177 | if (this.value instanceof Code && (match = this.METHOD_DEF.exec(name))) { 1178 | this.value.name = match[2]; 1179 | if (match[1]) { 1180 | this.value.klass = match[1]; 1181 | } 1182 | } 1183 | val = this.value.compile(o, LEVEL_LIST); 1184 | if (this.context === 'object') { 1185 | return "" + name + ": " + val; 1186 | } 1187 | val = name + (" " + (this.context || '=') + " ") + val; 1188 | if (o.level <= LEVEL_LIST) { 1189 | return val; 1190 | } else { 1191 | return "(" + val + ")"; 1192 | } 1193 | }; 1194 | Assign.prototype.compilePatternMatch = function(o) { 1195 | var acc, assigns, code, i, idx, isObject, ivar, obj, objects, olen, ref, rest, splat, top, val, value, vvar, _len, _ref2, _ref3, _ref4, _ref5; 1196 | top = o.level === LEVEL_TOP; 1197 | value = this.value; 1198 | objects = this.variable.base.objects; 1199 | if (!(olen = objects.length)) { 1200 | code = value.compile(o); 1201 | if (o.level >= LEVEL_OP) { 1202 | return "(" + code + ")"; 1203 | } else { 1204 | return code; 1205 | } 1206 | } 1207 | isObject = this.variable.isObject(); 1208 | if (top && olen === 1 && !((obj = objects[0]) instanceof Splat)) { 1209 | if (obj instanceof Assign) { 1210 | _ref2 = obj, idx = _ref2.variable.base, obj = _ref2.value; 1211 | } else { 1212 | if (obj.base instanceof Parens) { 1213 | _ref3 = new Value(obj.unwrapAll()).cacheReference(o), obj = _ref3[0], idx = _ref3[1]; 1214 | } else { 1215 | idx = isObject ? obj["this"] ? obj.properties[0].name : obj : new Literal(0); 1216 | } 1217 | } 1218 | acc = IDENTIFIER.test(idx.unwrap().value || 0); 1219 | value = new Value(value); 1220 | value.properties.push(new (acc ? Access : Index)(idx)); 1221 | return new Assign(obj, value).compile(o); 1222 | } 1223 | vvar = value.compile(o, LEVEL_LIST); 1224 | assigns = []; 1225 | splat = false; 1226 | if (!IDENTIFIER.test(vvar) || this.variable.assigns(vvar)) { 1227 | assigns.push("" + (ref = o.scope.freeVariable('ref')) + " = " + vvar); 1228 | vvar = ref; 1229 | } 1230 | for (i = 0, _len = objects.length; i < _len; i++) { 1231 | obj = objects[i]; 1232 | idx = i; 1233 | if (isObject) { 1234 | if (obj instanceof Assign) { 1235 | _ref4 = obj, idx = _ref4.variable.base, obj = _ref4.value; 1236 | } else { 1237 | if (obj.base instanceof Parens) { 1238 | _ref5 = new Value(obj.unwrapAll()).cacheReference(o), obj = _ref5[0], idx = _ref5[1]; 1239 | } else { 1240 | idx = obj["this"] ? obj.properties[0].name : obj; 1241 | } 1242 | } 1243 | } 1244 | if (!splat && obj instanceof Splat) { 1245 | val = "" + olen + " <= " + vvar + ".length ? " + (utility('slice')) + ".call(" + vvar + ", " + i; 1246 | if (rest = olen - i - 1) { 1247 | ivar = o.scope.freeVariable('i'); 1248 | val += ", " + ivar + " = " + vvar + ".length - " + rest + ") : (" + ivar + " = " + i + ", [])"; 1249 | } else { 1250 | val += ") : []"; 1251 | } 1252 | val = new Literal(val); 1253 | splat = "" + ivar + "++"; 1254 | } else { 1255 | if (obj instanceof Splat) { 1256 | obj = obj.name.compile(o); 1257 | throw SyntaxError("multiple splats are disallowed in an assignment: " + obj + " ..."); 1258 | } 1259 | if (typeof idx === 'number') { 1260 | idx = new Literal(splat || idx); 1261 | acc = false; 1262 | } else { 1263 | acc = isObject && IDENTIFIER.test(idx.unwrap().value || 0); 1264 | } 1265 | val = new Value(new Literal(vvar), [new (acc ? Access : Index)(idx)]); 1266 | } 1267 | assigns.push(new Assign(obj, val, null, { 1268 | param: this.param 1269 | }).compile(o, LEVEL_TOP)); 1270 | } 1271 | if (!top) { 1272 | assigns.push(vvar); 1273 | } 1274 | code = assigns.join(', '); 1275 | if (o.level < LEVEL_LIST) { 1276 | return code; 1277 | } else { 1278 | return "(" + code + ")"; 1279 | } 1280 | }; 1281 | Assign.prototype.compileConditional = function(o) { 1282 | var left, rite, _ref2; 1283 | _ref2 = this.variable.cacheReference(o), left = _ref2[0], rite = _ref2[1]; 1284 | return new Op(this.context.slice(0, -1), left, new Assign(rite, this.value, '=')).compile(o); 1285 | }; 1286 | Assign.prototype.compileSplice = function(o) { 1287 | var code, exclusive, from, fromDecl, fromRef, name, to, valDef, valRef, _ref2, _ref3, _ref4; 1288 | _ref2 = this.variable.properties.pop().range, from = _ref2.from, to = _ref2.to, exclusive = _ref2.exclusive; 1289 | name = this.variable.compile(o); 1290 | _ref3 = (from != null ? from.cache(o, LEVEL_OP) : void 0) || ['0', '0'], fromDecl = _ref3[0], fromRef = _ref3[1]; 1291 | if (to) { 1292 | if ((from != null ? from.isSimpleNumber() : void 0) && to.isSimpleNumber()) { 1293 | to = +to.compile(o) - +fromRef; 1294 | if (!exclusive) { 1295 | to += 1; 1296 | } 1297 | } else { 1298 | to = to.compile(o) + ' - ' + fromRef; 1299 | if (!exclusive) { 1300 | to += ' + 1'; 1301 | } 1302 | } 1303 | } else { 1304 | to = "9e9"; 1305 | } 1306 | _ref4 = this.value.cache(o, LEVEL_LIST), valDef = _ref4[0], valRef = _ref4[1]; 1307 | code = "[].splice.apply(" + name + ", [" + fromDecl + ", " + to + "].concat(" + valDef + ")), " + valRef; 1308 | if (o.level > LEVEL_TOP) { 1309 | return "(" + code + ")"; 1310 | } else { 1311 | return code; 1312 | } 1313 | }; 1314 | return Assign; 1315 | })(); 1316 | exports.Code = Code = (function() { 1317 | __extends(Code, Base); 1318 | function Code(params, body, tag) { 1319 | this.params = params || []; 1320 | this.body = body || new Block; 1321 | this.bound = tag === 'boundfunc'; 1322 | if (this.bound) { 1323 | this.context = 'this'; 1324 | } 1325 | } 1326 | Code.prototype.children = ['params', 'body']; 1327 | Code.prototype.isStatement = function() { 1328 | return !!this.ctor; 1329 | }; 1330 | Code.prototype.jumps = NO; 1331 | Code.prototype.compileNode = function(o) { 1332 | var code, exprs, i, idt, lit, p, param, ref, splats, v, val, vars, wasEmpty, _i, _j, _len, _len2, _len3, _ref2, _ref3, _ref4; 1333 | o.scope = new Scope(o.scope, this.body, this); 1334 | o.scope.shared = del(o, 'sharedScope'); 1335 | o.indent += TAB; 1336 | delete o.bare; 1337 | vars = []; 1338 | exprs = []; 1339 | _ref2 = this.params; 1340 | for (_i = 0, _len = _ref2.length; _i < _len; _i++) { 1341 | param = _ref2[_i]; 1342 | if (param.splat) { 1343 | if (param.name.value) { 1344 | o.scope.add(param.name.value, 'var'); 1345 | } 1346 | splats = new Assign(new Value(new Arr((function() { 1347 | var _j, _len2, _ref3, _results; 1348 | _ref3 = this.params; 1349 | _results = []; 1350 | for (_j = 0, _len2 = _ref3.length; _j < _len2; _j++) { 1351 | p = _ref3[_j]; 1352 | _results.push(p.asReference(o)); 1353 | } 1354 | return _results; 1355 | }).call(this))), new Value(new Literal('arguments'))); 1356 | break; 1357 | } 1358 | } 1359 | _ref3 = this.params; 1360 | for (_j = 0, _len2 = _ref3.length; _j < _len2; _j++) { 1361 | param = _ref3[_j]; 1362 | if (param.isComplex()) { 1363 | val = ref = param.asReference(o); 1364 | if (param.value) { 1365 | val = new Op('?', ref, param.value); 1366 | } 1367 | exprs.push(new Assign(new Value(param.name), val, '=', { 1368 | param: true 1369 | })); 1370 | } else { 1371 | ref = param; 1372 | if (param.value) { 1373 | lit = new Literal(ref.name.value + ' == null'); 1374 | val = new Assign(new Value(param.name), param.value, '='); 1375 | exprs.push(new If(lit, val)); 1376 | } 1377 | } 1378 | if (!splats) { 1379 | vars.push(ref); 1380 | } 1381 | } 1382 | wasEmpty = this.body.isEmpty(); 1383 | if (splats) { 1384 | exprs.unshift(splats); 1385 | } 1386 | if (exprs.length) { 1387 | (_ref4 = this.body.expressions).unshift.apply(_ref4, exprs); 1388 | } 1389 | if (!splats) { 1390 | for (i = 0, _len3 = vars.length; i < _len3; i++) { 1391 | v = vars[i]; 1392 | o.scope.parameter(vars[i] = v.compile(o)); 1393 | } 1394 | } 1395 | if (!(wasEmpty || this.noReturn)) { 1396 | this.body.makeReturn(); 1397 | } 1398 | idt = o.indent; 1399 | code = 'function'; 1400 | if (this.ctor) { 1401 | code += ' ' + this.name; 1402 | } 1403 | code += '(' + vars.join(', ') + ') {'; 1404 | if (!this.body.isEmpty()) { 1405 | code += "\n" + (this.body.compileWithDeclarations(o)) + "\n" + this.tab; 1406 | } 1407 | code += '}'; 1408 | if (this.ctor) { 1409 | return this.tab + code; 1410 | } 1411 | if (this.bound) { 1412 | return utility('bind') + ("(" + code + ", " + this.context + ")"); 1413 | } 1414 | if (this.front || (o.level >= LEVEL_ACCESS)) { 1415 | return "(" + code + ")"; 1416 | } else { 1417 | return code; 1418 | } 1419 | }; 1420 | Code.prototype.traverseChildren = function(crossScope, func) { 1421 | if (crossScope) { 1422 | return Code.__super__.traverseChildren.call(this, crossScope, func); 1423 | } 1424 | }; 1425 | return Code; 1426 | })(); 1427 | exports.Param = Param = (function() { 1428 | __extends(Param, Base); 1429 | function Param(name, value, splat) { 1430 | this.name = name; 1431 | this.value = value; 1432 | this.splat = splat; 1433 | } 1434 | Param.prototype.children = ['name', 'value']; 1435 | Param.prototype.compile = function(o) { 1436 | return this.name.compile(o, LEVEL_LIST); 1437 | }; 1438 | Param.prototype.asReference = function(o) { 1439 | var node; 1440 | if (this.reference) { 1441 | return this.reference; 1442 | } 1443 | node = this.name; 1444 | if (node["this"]) { 1445 | node = node.properties[0].name; 1446 | if (node.value.reserved) { 1447 | node = new Literal('_' + node.value); 1448 | } 1449 | } else if (node.isComplex()) { 1450 | node = new Literal(o.scope.freeVariable('arg')); 1451 | } 1452 | node = new Value(node); 1453 | if (this.splat) { 1454 | node = new Splat(node); 1455 | } 1456 | return this.reference = node; 1457 | }; 1458 | Param.prototype.isComplex = function() { 1459 | return this.name.isComplex(); 1460 | }; 1461 | return Param; 1462 | })(); 1463 | exports.Splat = Splat = (function() { 1464 | __extends(Splat, Base); 1465 | Splat.prototype.children = ['name']; 1466 | Splat.prototype.isAssignable = YES; 1467 | function Splat(name) { 1468 | this.name = name.compile ? name : new Literal(name); 1469 | } 1470 | Splat.prototype.assigns = function(name) { 1471 | return this.name.assigns(name); 1472 | }; 1473 | Splat.prototype.compile = function(o) { 1474 | if (this.index != null) { 1475 | return this.compileParam(o); 1476 | } else { 1477 | return this.name.compile(o); 1478 | } 1479 | }; 1480 | Splat.compileSplattedArray = function(o, list, apply) { 1481 | var args, base, code, i, index, node, _len; 1482 | index = -1; 1483 | while ((node = list[++index]) && !(node instanceof Splat)) { 1484 | continue; 1485 | } 1486 | if (index >= list.length) { 1487 | return ''; 1488 | } 1489 | if (list.length === 1) { 1490 | code = list[0].compile(o, LEVEL_LIST); 1491 | if (apply) { 1492 | return code; 1493 | } 1494 | return "" + (utility('slice')) + ".call(" + code + ")"; 1495 | } 1496 | args = list.slice(index); 1497 | for (i = 0, _len = args.length; i < _len; i++) { 1498 | node = args[i]; 1499 | code = node.compile(o, LEVEL_LIST); 1500 | args[i] = node instanceof Splat ? "" + (utility('slice')) + ".call(" + code + ")" : "[" + code + "]"; 1501 | } 1502 | if (index === 0) { 1503 | return args[0] + (".concat(" + (args.slice(1).join(', ')) + ")"); 1504 | } 1505 | base = (function() { 1506 | var _i, _len2, _ref2, _results; 1507 | _ref2 = list.slice(0, index); 1508 | _results = []; 1509 | for (_i = 0, _len2 = _ref2.length; _i < _len2; _i++) { 1510 | node = _ref2[_i]; 1511 | _results.push(node.compile(o, LEVEL_LIST)); 1512 | } 1513 | return _results; 1514 | })(); 1515 | return "[" + (base.join(', ')) + "].concat(" + (args.join(', ')) + ")"; 1516 | }; 1517 | return Splat; 1518 | })(); 1519 | exports.While = While = (function() { 1520 | __extends(While, Base); 1521 | function While(condition, options) { 1522 | this.condition = (options != null ? options.invert : void 0) ? condition.invert() : condition; 1523 | this.guard = options != null ? options.guard : void 0; 1524 | } 1525 | While.prototype.children = ['condition', 'guard', 'body']; 1526 | While.prototype.isStatement = YES; 1527 | While.prototype.makeReturn = function() { 1528 | this.returns = true; 1529 | return this; 1530 | }; 1531 | While.prototype.addBody = function(body) { 1532 | this.body = body; 1533 | return this; 1534 | }; 1535 | While.prototype.jumps = function() { 1536 | var expressions, node, _i, _len; 1537 | expressions = this.body.expressions; 1538 | if (!expressions.length) { 1539 | return false; 1540 | } 1541 | for (_i = 0, _len = expressions.length; _i < _len; _i++) { 1542 | node = expressions[_i]; 1543 | if (node.jumps({ 1544 | loop: true 1545 | })) { 1546 | return node; 1547 | } 1548 | } 1549 | return false; 1550 | }; 1551 | While.prototype.compileNode = function(o) { 1552 | var body, code, rvar, set; 1553 | o.indent += TAB; 1554 | set = ''; 1555 | body = this.body; 1556 | if (body.isEmpty()) { 1557 | body = ''; 1558 | } else { 1559 | if (o.level > LEVEL_TOP || this.returns) { 1560 | rvar = o.scope.freeVariable('results'); 1561 | set = "" + this.tab + rvar + " = [];\n"; 1562 | if (body) { 1563 | body = Push.wrap(rvar, body); 1564 | } 1565 | } 1566 | if (this.guard) { 1567 | body = Block.wrap([new If(this.guard, body)]); 1568 | } 1569 | body = "\n" + (body.compile(o, LEVEL_TOP)) + "\n" + this.tab; 1570 | } 1571 | code = set + this.tab + ("while (" + (this.condition.compile(o, LEVEL_PAREN)) + ") {" + body + "}"); 1572 | if (this.returns) { 1573 | code += "\n" + this.tab + "return " + rvar + ";"; 1574 | } 1575 | return code; 1576 | }; 1577 | return While; 1578 | })(); 1579 | exports.Op = Op = (function() { 1580 | var CONVERSIONS, INVERSIONS; 1581 | __extends(Op, Base); 1582 | function Op(op, first, second, flip) { 1583 | var call; 1584 | if (op === 'in') { 1585 | return new In(first, second); 1586 | } 1587 | if (op === 'do') { 1588 | call = new Call(first, first.params || []); 1589 | call["do"] = true; 1590 | return call; 1591 | } 1592 | if (op === 'new') { 1593 | if (first instanceof Call && !first["do"]) { 1594 | return first.newInstance(); 1595 | } 1596 | if (first instanceof Code && first.bound || first["do"]) { 1597 | first = new Parens(first); 1598 | } 1599 | } 1600 | this.operator = CONVERSIONS[op] || op; 1601 | this.first = first; 1602 | this.second = second; 1603 | this.flip = !!flip; 1604 | return this; 1605 | } 1606 | CONVERSIONS = { 1607 | '==': '===', 1608 | '!=': '!==', 1609 | 'of': 'in' 1610 | }; 1611 | INVERSIONS = { 1612 | '!==': '===', 1613 | '===': '!==' 1614 | }; 1615 | Op.prototype.children = ['first', 'second']; 1616 | Op.prototype.isSimpleNumber = NO; 1617 | Op.prototype.isUnary = function() { 1618 | return !this.second; 1619 | }; 1620 | Op.prototype.isChainable = function() { 1621 | var _ref2; 1622 | return (_ref2 = this.operator) === '<' || _ref2 === '>' || _ref2 === '>=' || _ref2 === '<=' || _ref2 === '===' || _ref2 === '!=='; 1623 | }; 1624 | Op.prototype.invert = function() { 1625 | var allInvertable, curr, fst, op, _ref2; 1626 | if (this.isChainable() && this.first.isChainable()) { 1627 | allInvertable = true; 1628 | curr = this; 1629 | while (curr && curr.operator) { 1630 | allInvertable && (allInvertable = curr.operator in INVERSIONS); 1631 | curr = curr.first; 1632 | } 1633 | if (!allInvertable) { 1634 | return new Parens(this).invert(); 1635 | } 1636 | curr = this; 1637 | while (curr && curr.operator) { 1638 | curr.invert = !curr.invert; 1639 | curr.operator = INVERSIONS[curr.operator]; 1640 | curr = curr.first; 1641 | } 1642 | return this; 1643 | } else if (op = INVERSIONS[this.operator]) { 1644 | this.operator = op; 1645 | if (this.first.unwrap() instanceof Op) { 1646 | this.first.invert(); 1647 | } 1648 | return this; 1649 | } else if (this.second) { 1650 | return new Parens(this).invert(); 1651 | } else if (this.operator === '!' && (fst = this.first.unwrap()) instanceof Op && ((_ref2 = fst.operator) === '!' || _ref2 === 'in' || _ref2 === 'instanceof')) { 1652 | return fst; 1653 | } else { 1654 | return new Op('!', this); 1655 | } 1656 | }; 1657 | Op.prototype.unfoldSoak = function(o) { 1658 | var _ref2; 1659 | return ((_ref2 = this.operator) === '++' || _ref2 === '--' || _ref2 === 'delete') && unfoldSoak(o, this, 'first'); 1660 | }; 1661 | Op.prototype.compileNode = function(o) { 1662 | var code; 1663 | if (this.isUnary()) { 1664 | return this.compileUnary(o); 1665 | } 1666 | if (this.isChainable() && this.first.isChainable()) { 1667 | return this.compileChain(o); 1668 | } 1669 | if (this.operator === '?') { 1670 | return this.compileExistence(o); 1671 | } 1672 | this.first.front = this.front; 1673 | code = this.first.compile(o, LEVEL_OP) + ' ' + this.operator + ' ' + this.second.compile(o, LEVEL_OP); 1674 | if (o.level <= LEVEL_OP) { 1675 | return code; 1676 | } else { 1677 | return "(" + code + ")"; 1678 | } 1679 | }; 1680 | Op.prototype.compileChain = function(o) { 1681 | var code, fst, shared, _ref2; 1682 | _ref2 = this.first.second.cache(o), this.first.second = _ref2[0], shared = _ref2[1]; 1683 | fst = this.first.compile(o, LEVEL_OP); 1684 | code = "" + fst + " " + (this.invert ? '&&' : '||') + " " + (shared.compile(o)) + " " + this.operator + " " + (this.second.compile(o, LEVEL_OP)); 1685 | return "(" + code + ")"; 1686 | }; 1687 | Op.prototype.compileExistence = function(o) { 1688 | var fst, ref; 1689 | if (this.first.isComplex()) { 1690 | ref = new Literal(o.scope.freeVariable('ref')); 1691 | fst = new Parens(new Assign(ref, this.first)); 1692 | } else { 1693 | fst = this.first; 1694 | ref = fst; 1695 | } 1696 | return new If(new Existence(fst), ref, { 1697 | type: 'if' 1698 | }).addElse(this.second).compile(o); 1699 | }; 1700 | Op.prototype.compileUnary = function(o) { 1701 | var op, parts; 1702 | parts = [op = this.operator]; 1703 | if ((op === 'new' || op === 'typeof' || op === 'delete') || (op === '+' || op === '-') && this.first instanceof Op && this.first.operator === op) { 1704 | parts.push(' '); 1705 | } 1706 | if (op === 'new' && this.first.isStatement(o)) { 1707 | this.first = new Parens(this.first); 1708 | } 1709 | parts.push(this.first.compile(o, LEVEL_OP)); 1710 | if (this.flip) { 1711 | parts.reverse(); 1712 | } 1713 | return parts.join(''); 1714 | }; 1715 | Op.prototype.toString = function(idt) { 1716 | return Op.__super__.toString.call(this, idt, this.constructor.name + ' ' + this.operator); 1717 | }; 1718 | return Op; 1719 | })(); 1720 | exports.In = In = (function() { 1721 | __extends(In, Base); 1722 | function In(object, array) { 1723 | this.object = object; 1724 | this.array = array; 1725 | } 1726 | In.prototype.children = ['object', 'array']; 1727 | In.prototype.invert = NEGATE; 1728 | In.prototype.compileNode = function(o) { 1729 | if (this.array instanceof Value && this.array.isArray()) { 1730 | return this.compileOrTest(o); 1731 | } else { 1732 | return this.compileLoopTest(o); 1733 | } 1734 | }; 1735 | In.prototype.compileOrTest = function(o) { 1736 | var cmp, cnj, i, item, ref, sub, tests, _ref2, _ref3; 1737 | _ref2 = this.object.cache(o, LEVEL_OP), sub = _ref2[0], ref = _ref2[1]; 1738 | _ref3 = this.negated ? [' !== ', ' && '] : [' === ', ' || '], cmp = _ref3[0], cnj = _ref3[1]; 1739 | tests = (function() { 1740 | var _len, _ref4, _results; 1741 | _ref4 = this.array.base.objects; 1742 | _results = []; 1743 | for (i = 0, _len = _ref4.length; i < _len; i++) { 1744 | item = _ref4[i]; 1745 | _results.push((i ? ref : sub) + cmp + item.compile(o, LEVEL_OP)); 1746 | } 1747 | return _results; 1748 | }).call(this); 1749 | if (tests.length === 0) { 1750 | return 'false'; 1751 | } 1752 | tests = tests.join(cnj); 1753 | if (o.level < LEVEL_OP) { 1754 | return tests; 1755 | } else { 1756 | return "(" + tests + ")"; 1757 | } 1758 | }; 1759 | In.prototype.compileLoopTest = function(o) { 1760 | var code, ref, sub, _ref2; 1761 | _ref2 = this.object.cache(o, LEVEL_LIST), sub = _ref2[0], ref = _ref2[1]; 1762 | code = utility('indexOf') + (".call(" + (this.array.compile(o, LEVEL_LIST)) + ", " + ref + ") ") + (this.negated ? '< 0' : '>= 0'); 1763 | if (sub === ref) { 1764 | return code; 1765 | } 1766 | code = sub + ', ' + code; 1767 | if (o.level < LEVEL_LIST) { 1768 | return code; 1769 | } else { 1770 | return "(" + code + ")"; 1771 | } 1772 | }; 1773 | In.prototype.toString = function(idt) { 1774 | return In.__super__.toString.call(this, idt, this.constructor.name + (this.negated ? '!' : '')); 1775 | }; 1776 | return In; 1777 | })(); 1778 | exports.Try = Try = (function() { 1779 | __extends(Try, Base); 1780 | function Try(attempt, error, recovery, ensure) { 1781 | this.attempt = attempt; 1782 | this.error = error; 1783 | this.recovery = recovery; 1784 | this.ensure = ensure; 1785 | } 1786 | Try.prototype.children = ['attempt', 'recovery', 'ensure']; 1787 | Try.prototype.isStatement = YES; 1788 | Try.prototype.jumps = function(o) { 1789 | var _ref2; 1790 | return this.attempt.jumps(o) || ((_ref2 = this.recovery) != null ? _ref2.jumps(o) : void 0); 1791 | }; 1792 | Try.prototype.makeReturn = function() { 1793 | if (this.attempt) { 1794 | this.attempt = this.attempt.makeReturn(); 1795 | } 1796 | if (this.recovery) { 1797 | this.recovery = this.recovery.makeReturn(); 1798 | } 1799 | return this; 1800 | }; 1801 | Try.prototype.compileNode = function(o) { 1802 | var catchPart, errorPart; 1803 | o.indent += TAB; 1804 | errorPart = this.error ? " (" + (this.error.compile(o)) + ") " : ' '; 1805 | catchPart = this.recovery ? " catch" + errorPart + "{\n" + (this.recovery.compile(o, LEVEL_TOP)) + "\n" + this.tab + "}" : !(this.ensure || this.recovery) ? ' catch (_e) {}' : void 0; 1806 | return ("" + this.tab + "try {\n" + (this.attempt.compile(o, LEVEL_TOP)) + "\n" + this.tab + "}" + (catchPart || '')) + (this.ensure ? " finally {\n" + (this.ensure.compile(o, LEVEL_TOP)) + "\n" + this.tab + "}" : ''); 1807 | }; 1808 | return Try; 1809 | })(); 1810 | exports.Throw = Throw = (function() { 1811 | __extends(Throw, Base); 1812 | function Throw(expression) { 1813 | this.expression = expression; 1814 | } 1815 | Throw.prototype.children = ['expression']; 1816 | Throw.prototype.isStatement = YES; 1817 | Throw.prototype.jumps = NO; 1818 | Throw.prototype.makeReturn = THIS; 1819 | Throw.prototype.compileNode = function(o) { 1820 | return this.tab + ("throw " + (this.expression.compile(o)) + ";"); 1821 | }; 1822 | return Throw; 1823 | })(); 1824 | exports.Existence = Existence = (function() { 1825 | __extends(Existence, Base); 1826 | function Existence(expression) { 1827 | this.expression = expression; 1828 | } 1829 | Existence.prototype.children = ['expression']; 1830 | Existence.prototype.invert = NEGATE; 1831 | Existence.prototype.compileNode = function(o) { 1832 | var code, sym; 1833 | code = this.expression.compile(o, LEVEL_OP); 1834 | code = IDENTIFIER.test(code) && !o.scope.check(code) ? this.negated ? "typeof " + code + " === \"undefined\" || " + code + " === null" : "typeof " + code + " !== \"undefined\" && " + code + " !== null" : (sym = this.negated ? '==' : '!=', "" + code + " " + sym + " null"); 1835 | if (o.level <= LEVEL_COND) { 1836 | return code; 1837 | } else { 1838 | return "(" + code + ")"; 1839 | } 1840 | }; 1841 | return Existence; 1842 | })(); 1843 | exports.Parens = Parens = (function() { 1844 | __extends(Parens, Base); 1845 | function Parens(body) { 1846 | this.body = body; 1847 | } 1848 | Parens.prototype.children = ['body']; 1849 | Parens.prototype.unwrap = function() { 1850 | return this.body; 1851 | }; 1852 | Parens.prototype.isComplex = function() { 1853 | return this.body.isComplex(); 1854 | }; 1855 | Parens.prototype.makeReturn = function() { 1856 | return this.body.makeReturn(); 1857 | }; 1858 | Parens.prototype.compileNode = function(o) { 1859 | var bare, code, expr; 1860 | expr = this.body.unwrap(); 1861 | if (expr instanceof Value && expr.isAtomic()) { 1862 | expr.front = this.front; 1863 | return expr.compile(o); 1864 | } 1865 | code = expr.compile(o, LEVEL_PAREN); 1866 | bare = o.level < LEVEL_OP && (expr instanceof Op || expr instanceof Call || (expr instanceof For && expr.returns)); 1867 | if (bare) { 1868 | return code; 1869 | } else { 1870 | return "(" + code + ")"; 1871 | } 1872 | }; 1873 | return Parens; 1874 | })(); 1875 | exports.For = For = (function() { 1876 | __extends(For, Base); 1877 | function For(body, source) { 1878 | var _ref2; 1879 | this.source = source.source, this.guard = source.guard, this.step = source.step, this.name = source.name, this.index = source.index; 1880 | this.body = Block.wrap([body]); 1881 | this.own = !!source.own; 1882 | this.object = !!source.object; 1883 | if (this.object) { 1884 | _ref2 = [this.index, this.name], this.name = _ref2[0], this.index = _ref2[1]; 1885 | } 1886 | if (this.index instanceof Value) { 1887 | throw SyntaxError('index cannot be a pattern matching expression'); 1888 | } 1889 | this.range = this.source instanceof Value && this.source.base instanceof Range && !this.source.properties.length; 1890 | this.pattern = this.name instanceof Value; 1891 | if (this.range && this.index) { 1892 | throw SyntaxError('indexes do not apply to range loops'); 1893 | } 1894 | if (this.range && this.pattern) { 1895 | throw SyntaxError('cannot pattern match over range loops'); 1896 | } 1897 | this.returns = false; 1898 | } 1899 | For.prototype.children = ['body', 'source', 'guard', 'step']; 1900 | For.prototype.isStatement = YES; 1901 | For.prototype.jumps = While.prototype.jumps; 1902 | For.prototype.makeReturn = function() { 1903 | this.returns = true; 1904 | return this; 1905 | }; 1906 | For.prototype.compileNode = function(o) { 1907 | var body, defPart, forPart, forVarPart, guardPart, idt1, index, ivar, lastJumps, lvar, name, namePart, ref, resultPart, returnResult, rvar, scope, source, stepPart, stepvar, svar, varPart, _ref2; 1908 | body = Block.wrap([this.body]); 1909 | lastJumps = (_ref2 = last(body.expressions)) != null ? _ref2.jumps() : void 0; 1910 | if (lastJumps && lastJumps instanceof Return) { 1911 | this.returns = false; 1912 | } 1913 | source = this.range ? this.source.base : this.source; 1914 | scope = o.scope; 1915 | name = this.name && this.name.compile(o, LEVEL_LIST); 1916 | index = this.index && this.index.compile(o, LEVEL_LIST); 1917 | if (name && !this.pattern) { 1918 | scope.find(name, { 1919 | immediate: true 1920 | }); 1921 | } 1922 | if (index) { 1923 | scope.find(index, { 1924 | immediate: true 1925 | }); 1926 | } 1927 | if (this.returns) { 1928 | rvar = scope.freeVariable('results'); 1929 | } 1930 | ivar = (this.range ? name : index) || scope.freeVariable('i'); 1931 | if (this.step && !this.range) { 1932 | stepvar = scope.freeVariable("step"); 1933 | } 1934 | if (this.pattern) { 1935 | name = ivar; 1936 | } 1937 | varPart = ''; 1938 | guardPart = ''; 1939 | defPart = ''; 1940 | idt1 = this.tab + TAB; 1941 | if (this.range) { 1942 | forPart = source.compile(merge(o, { 1943 | index: ivar, 1944 | step: this.step 1945 | })); 1946 | } else { 1947 | svar = this.source.compile(o, LEVEL_LIST); 1948 | if ((name || this.own) && !IDENTIFIER.test(svar)) { 1949 | defPart = "" + this.tab + (ref = scope.freeVariable('ref')) + " = " + svar + ";\n"; 1950 | svar = ref; 1951 | } 1952 | if (name && !this.pattern) { 1953 | namePart = "" + name + " = " + svar + "[" + ivar + "]"; 1954 | } 1955 | if (!this.object) { 1956 | lvar = scope.freeVariable('len'); 1957 | forVarPart = ("" + ivar + " = 0, " + lvar + " = " + svar + ".length") + (this.step ? ", " + stepvar + " = " + (this.step.compile(o, LEVEL_OP)) : ''); 1958 | stepPart = this.step ? "" + ivar + " += " + stepvar : "" + ivar + "++"; 1959 | forPart = "" + forVarPart + "; " + ivar + " < " + lvar + "; " + stepPart; 1960 | } 1961 | } 1962 | if (this.returns) { 1963 | resultPart = "" + this.tab + rvar + " = [];\n"; 1964 | returnResult = "\n" + this.tab + "return " + rvar + ";"; 1965 | body = Push.wrap(rvar, body); 1966 | } 1967 | if (this.guard) { 1968 | body = Block.wrap([new If(this.guard, body)]); 1969 | } 1970 | if (this.pattern) { 1971 | body.expressions.unshift(new Assign(this.name, new Literal("" + svar + "[" + ivar + "]"))); 1972 | } 1973 | defPart += this.pluckDirectCall(o, body); 1974 | if (namePart) { 1975 | varPart = "\n" + idt1 + namePart + ";"; 1976 | } 1977 | if (this.object) { 1978 | forPart = "" + ivar + " in " + svar; 1979 | if (this.own) { 1980 | guardPart = "\n" + idt1 + "if (!" + (utility('hasProp')) + ".call(" + svar + ", " + ivar + ")) continue;"; 1981 | } 1982 | } 1983 | body = body.compile(merge(o, { 1984 | indent: idt1 1985 | }), LEVEL_TOP); 1986 | if (body) { 1987 | body = '\n' + body + '\n'; 1988 | } 1989 | return "" + defPart + (resultPart || '') + this.tab + "for (" + forPart + ") {" + guardPart + varPart + body + this.tab + "}" + (returnResult || ''); 1990 | }; 1991 | For.prototype.pluckDirectCall = function(o, body) { 1992 | var base, defs, expr, fn, idx, ref, val, _len, _ref2, _ref3, _ref4, _ref5, _ref6, _ref7; 1993 | defs = ''; 1994 | _ref2 = body.expressions; 1995 | for (idx = 0, _len = _ref2.length; idx < _len; idx++) { 1996 | expr = _ref2[idx]; 1997 | expr = expr.unwrapAll(); 1998 | if (!(expr instanceof Call)) { 1999 | continue; 2000 | } 2001 | val = expr.variable.unwrapAll(); 2002 | if (!((val instanceof Code) || (val instanceof Value && ((_ref3 = val.base) != null ? _ref3.unwrapAll() : void 0) instanceof Code && val.properties.length === 1 && ((_ref4 = (_ref5 = val.properties[0].name) != null ? _ref5.value : void 0) === 'call' || _ref4 === 'apply')))) { 2003 | continue; 2004 | } 2005 | fn = ((_ref6 = val.base) != null ? _ref6.unwrapAll() : void 0) || val; 2006 | ref = new Literal(o.scope.freeVariable('fn')); 2007 | base = new Value(ref); 2008 | if (val.base) { 2009 | _ref7 = [base, val], val.base = _ref7[0], base = _ref7[1]; 2010 | args.unshift(new Literal('this')); 2011 | } 2012 | body.expressions[idx] = new Call(base, expr.args); 2013 | defs += this.tab + new Assign(ref, fn).compile(o, LEVEL_TOP) + ';\n'; 2014 | } 2015 | return defs; 2016 | }; 2017 | return For; 2018 | })(); 2019 | exports.Switch = Switch = (function() { 2020 | __extends(Switch, Base); 2021 | function Switch(subject, cases, otherwise) { 2022 | this.subject = subject; 2023 | this.cases = cases; 2024 | this.otherwise = otherwise; 2025 | } 2026 | Switch.prototype.children = ['subject', 'cases', 'otherwise']; 2027 | Switch.prototype.isStatement = YES; 2028 | Switch.prototype.jumps = function(o) { 2029 | var block, conds, _i, _len, _ref2, _ref3, _ref4; 2030 | if (o == null) { 2031 | o = { 2032 | block: true 2033 | }; 2034 | } 2035 | _ref2 = this.cases; 2036 | for (_i = 0, _len = _ref2.length; _i < _len; _i++) { 2037 | _ref3 = _ref2[_i], conds = _ref3[0], block = _ref3[1]; 2038 | if (block.jumps(o)) { 2039 | return block; 2040 | } 2041 | } 2042 | return (_ref4 = this.otherwise) != null ? _ref4.jumps(o) : void 0; 2043 | }; 2044 | Switch.prototype.makeReturn = function() { 2045 | var pair, _i, _len, _ref2, _ref3; 2046 | _ref2 = this.cases; 2047 | for (_i = 0, _len = _ref2.length; _i < _len; _i++) { 2048 | pair = _ref2[_i]; 2049 | pair[1].makeReturn(); 2050 | } 2051 | if ((_ref3 = this.otherwise) != null) { 2052 | _ref3.makeReturn(); 2053 | } 2054 | return this; 2055 | }; 2056 | Switch.prototype.compileNode = function(o) { 2057 | var block, body, code, cond, conditions, expr, i, idt1, idt2, _i, _len, _len2, _ref2, _ref3, _ref4, _ref5; 2058 | idt1 = o.indent + TAB; 2059 | idt2 = o.indent = idt1 + TAB; 2060 | code = this.tab + ("switch (" + (((_ref2 = this.subject) != null ? _ref2.compile(o, LEVEL_PAREN) : void 0) || false) + ") {\n"); 2061 | _ref3 = this.cases; 2062 | for (i = 0, _len = _ref3.length; i < _len; i++) { 2063 | _ref4 = _ref3[i], conditions = _ref4[0], block = _ref4[1]; 2064 | _ref5 = flatten([conditions]); 2065 | for (_i = 0, _len2 = _ref5.length; _i < _len2; _i++) { 2066 | cond = _ref5[_i]; 2067 | if (!this.subject) { 2068 | cond = cond.invert(); 2069 | } 2070 | code += idt1 + ("case " + (cond.compile(o, LEVEL_PAREN)) + ":\n"); 2071 | } 2072 | if (body = block.compile(o, LEVEL_TOP)) { 2073 | code += body + '\n'; 2074 | } 2075 | if (i === this.cases.length - 1 && !this.otherwise) { 2076 | break; 2077 | } 2078 | expr = this.lastNonComment(block.expressions); 2079 | if (expr instanceof Return || (expr instanceof Literal && expr.jumps() && expr.value !== 'debugger')) { 2080 | continue; 2081 | } 2082 | code += idt2 + 'break;\n'; 2083 | } 2084 | if (this.otherwise && this.otherwise.expressions.length) { 2085 | code += idt1 + ("default:\n" + (this.otherwise.compile(o, LEVEL_TOP)) + "\n"); 2086 | } 2087 | return code + this.tab + '}'; 2088 | }; 2089 | return Switch; 2090 | })(); 2091 | exports.If = If = (function() { 2092 | __extends(If, Base); 2093 | function If(condition, body, options) { 2094 | this.body = body; 2095 | if (options == null) { 2096 | options = {}; 2097 | } 2098 | this.condition = options.type === 'unless' ? condition.invert() : condition; 2099 | this.elseBody = null; 2100 | this.isChain = false; 2101 | this.soak = options.soak; 2102 | } 2103 | If.prototype.children = ['condition', 'body', 'elseBody']; 2104 | If.prototype.bodyNode = function() { 2105 | var _ref2; 2106 | return (_ref2 = this.body) != null ? _ref2.unwrap() : void 0; 2107 | }; 2108 | If.prototype.elseBodyNode = function() { 2109 | var _ref2; 2110 | return (_ref2 = this.elseBody) != null ? _ref2.unwrap() : void 0; 2111 | }; 2112 | If.prototype.addElse = function(elseBody) { 2113 | if (this.isChain) { 2114 | this.elseBodyNode().addElse(elseBody); 2115 | } else { 2116 | this.isChain = elseBody instanceof If; 2117 | this.elseBody = this.ensureBlock(elseBody); 2118 | } 2119 | return this; 2120 | }; 2121 | If.prototype.isStatement = function(o) { 2122 | var _ref2; 2123 | return (o != null ? o.level : void 0) === LEVEL_TOP || this.bodyNode().isStatement(o) || ((_ref2 = this.elseBodyNode()) != null ? _ref2.isStatement(o) : void 0); 2124 | }; 2125 | If.prototype.jumps = function(o) { 2126 | var _ref2; 2127 | return this.body.jumps(o) || ((_ref2 = this.elseBody) != null ? _ref2.jumps(o) : void 0); 2128 | }; 2129 | If.prototype.compileNode = function(o) { 2130 | if (this.isStatement(o)) { 2131 | return this.compileStatement(o); 2132 | } else { 2133 | return this.compileExpression(o); 2134 | } 2135 | }; 2136 | If.prototype.makeReturn = function() { 2137 | this.body && (this.body = new Block([this.body.makeReturn()])); 2138 | this.elseBody && (this.elseBody = new Block([this.elseBody.makeReturn()])); 2139 | return this; 2140 | }; 2141 | If.prototype.ensureBlock = function(node) { 2142 | if (node instanceof Block) { 2143 | return node; 2144 | } else { 2145 | return new Block([node]); 2146 | } 2147 | }; 2148 | If.prototype.compileStatement = function(o) { 2149 | var body, child, cond, ifPart; 2150 | child = del(o, 'chainChild'); 2151 | cond = this.condition.compile(o, LEVEL_PAREN); 2152 | o.indent += TAB; 2153 | body = this.ensureBlock(this.body).compile(o); 2154 | if (body) { 2155 | body = "\n" + body + "\n" + this.tab; 2156 | } 2157 | ifPart = "if (" + cond + ") {" + body + "}"; 2158 | if (!child) { 2159 | ifPart = this.tab + ifPart; 2160 | } 2161 | if (!this.elseBody) { 2162 | return ifPart; 2163 | } 2164 | return ifPart + ' else ' + (this.isChain ? (o.indent = this.tab, o.chainChild = true, this.elseBody.unwrap().compile(o, LEVEL_TOP)) : "{\n" + (this.elseBody.compile(o, LEVEL_TOP)) + "\n" + this.tab + "}"); 2165 | }; 2166 | If.prototype.compileExpression = function(o) { 2167 | var alt, body, code, cond; 2168 | cond = this.condition.compile(o, LEVEL_COND); 2169 | body = this.bodyNode().compile(o, LEVEL_LIST); 2170 | alt = this.elseBodyNode() ? this.elseBodyNode().compile(o, LEVEL_LIST) : 'void 0'; 2171 | code = "" + cond + " ? " + body + " : " + alt; 2172 | if (o.level >= LEVEL_COND) { 2173 | return "(" + code + ")"; 2174 | } else { 2175 | return code; 2176 | } 2177 | }; 2178 | If.prototype.unfoldSoak = function() { 2179 | return this.soak && this; 2180 | }; 2181 | return If; 2182 | })(); 2183 | Push = { 2184 | wrap: function(name, exps) { 2185 | if (exps.isEmpty() || last(exps.expressions).jumps()) { 2186 | return exps; 2187 | } 2188 | return exps.push(new Call(new Value(new Literal(name), [new Access(new Literal('push'))]), [exps.pop()])); 2189 | } 2190 | }; 2191 | Closure = { 2192 | wrap: function(expressions, statement, noReturn) { 2193 | var args, call, func, mentionsArgs, meth; 2194 | if (expressions.jumps()) { 2195 | return expressions; 2196 | } 2197 | func = new Code([], Block.wrap([expressions])); 2198 | args = []; 2199 | if ((mentionsArgs = expressions.contains(this.literalArgs)) || expressions.contains(this.literalThis)) { 2200 | meth = new Literal(mentionsArgs ? 'apply' : 'call'); 2201 | args = [new Literal('this')]; 2202 | if (mentionsArgs) { 2203 | args.push(new Literal('arguments')); 2204 | } 2205 | func = new Value(func, [new Access(meth)]); 2206 | } 2207 | func.noReturn = noReturn; 2208 | call = new Call(func, args); 2209 | if (statement) { 2210 | return Block.wrap([call]); 2211 | } else { 2212 | return call; 2213 | } 2214 | }, 2215 | literalArgs: function(node) { 2216 | return node instanceof Literal && node.value === 'arguments' && !node.asKey; 2217 | }, 2218 | literalThis: function(node) { 2219 | return (node instanceof Literal && node.value === 'this' && !node.asKey) || (node instanceof Code && node.bound); 2220 | } 2221 | }; 2222 | unfoldSoak = function(o, parent, name) { 2223 | var ifn; 2224 | if (!(ifn = parent[name].unfoldSoak(o))) { 2225 | return; 2226 | } 2227 | parent[name] = ifn.body; 2228 | ifn.body = new Value(parent); 2229 | return ifn; 2230 | }; 2231 | UTILITIES = { 2232 | "extends": 'function(child, parent) {\n for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; }\n function ctor() { this.constructor = child; }\n ctor.prototype = parent.prototype;\n child.prototype = new ctor;\n child.__super__ = parent.prototype;\n return child;\n}', 2233 | bind: 'function(fn, me){ return function(){ return fn.apply(me, arguments); }; }', 2234 | indexOf: 'Array.prototype.indexOf || function(item) {\n for (var i = 0, l = this.length; i < l; i++) {\n if (this[i] === item) return i;\n }\n return -1;\n}', 2235 | hasProp: 'Object.prototype.hasOwnProperty', 2236 | slice: 'Array.prototype.slice' 2237 | }; 2238 | LEVEL_TOP = 1; 2239 | LEVEL_PAREN = 2; 2240 | LEVEL_LIST = 3; 2241 | LEVEL_COND = 4; 2242 | LEVEL_OP = 5; 2243 | LEVEL_ACCESS = 6; 2244 | TAB = ' '; 2245 | IDENTIFIER = /^[$A-Za-z_\x7f-\uffff][$\w\x7f-\uffff]*$/; 2246 | SIMPLENUM = /^[+-]?\d+$/; 2247 | IS_STRING = /^['"]/; 2248 | utility = function(name) { 2249 | var ref; 2250 | ref = "__" + name; 2251 | Scope.root.assign(ref, UTILITIES[name]); 2252 | return ref; 2253 | }; 2254 | multident = function(code, tab) { 2255 | return code.replace(/\n/g, '$&' + tab); 2256 | }; 2257 | }).call(this); 2258 | -------------------------------------------------------------------------------- /node_modules/coffee-script/lib/optparse.js: -------------------------------------------------------------------------------- 1 | (function() { 2 | var LONG_FLAG, MULTI_FLAG, OPTIONAL, OptionParser, SHORT_FLAG, buildRule, buildRules, normalizeArguments; 3 | exports.OptionParser = OptionParser = (function() { 4 | function OptionParser(rules, banner) { 5 | this.banner = banner; 6 | this.rules = buildRules(rules); 7 | } 8 | OptionParser.prototype.parse = function(args) { 9 | var arg, i, isOption, matchedRule, options, rule, value, _i, _len, _len2, _ref; 10 | options = { 11 | arguments: [], 12 | literals: [] 13 | }; 14 | args = normalizeArguments(args); 15 | for (i = 0, _len = args.length; i < _len; i++) { 16 | arg = args[i]; 17 | if (arg === '--') { 18 | options.literals = args.slice(i + 1); 19 | break; 20 | } 21 | isOption = !!(arg.match(LONG_FLAG) || arg.match(SHORT_FLAG)); 22 | matchedRule = false; 23 | _ref = this.rules; 24 | for (_i = 0, _len2 = _ref.length; _i < _len2; _i++) { 25 | rule = _ref[_i]; 26 | if (rule.shortFlag === arg || rule.longFlag === arg) { 27 | value = rule.hasArgument ? args[i += 1] : true; 28 | options[rule.name] = rule.isList ? (options[rule.name] || []).concat(value) : value; 29 | matchedRule = true; 30 | break; 31 | } 32 | } 33 | if (isOption && !matchedRule) { 34 | throw new Error("unrecognized option: " + arg); 35 | } 36 | if (!isOption) { 37 | options.arguments = args.slice(i); 38 | break; 39 | } 40 | } 41 | return options; 42 | }; 43 | OptionParser.prototype.help = function() { 44 | var letPart, lines, rule, spaces, _i, _len, _ref; 45 | lines = []; 46 | if (this.banner) { 47 | lines.unshift("" + this.banner + "\n"); 48 | } 49 | _ref = this.rules; 50 | for (_i = 0, _len = _ref.length; _i < _len; _i++) { 51 | rule = _ref[_i]; 52 | spaces = 15 - rule.longFlag.length; 53 | spaces = spaces > 0 ? Array(spaces + 1).join(' ') : ''; 54 | letPart = rule.shortFlag ? rule.shortFlag + ', ' : ' '; 55 | lines.push(' ' + letPart + rule.longFlag + spaces + rule.description); 56 | } 57 | return "\n" + (lines.join('\n')) + "\n"; 58 | }; 59 | return OptionParser; 60 | })(); 61 | LONG_FLAG = /^(--\w[\w\-]+)/; 62 | SHORT_FLAG = /^(-\w)/; 63 | MULTI_FLAG = /^-(\w{2,})/; 64 | OPTIONAL = /\[(\w+(\*?))\]/; 65 | buildRules = function(rules) { 66 | var tuple, _i, _len, _results; 67 | _results = []; 68 | for (_i = 0, _len = rules.length; _i < _len; _i++) { 69 | tuple = rules[_i]; 70 | if (tuple.length < 3) { 71 | tuple.unshift(null); 72 | } 73 | _results.push(buildRule.apply(null, tuple)); 74 | } 75 | return _results; 76 | }; 77 | buildRule = function(shortFlag, longFlag, description, options) { 78 | var match; 79 | if (options == null) { 80 | options = {}; 81 | } 82 | match = longFlag.match(OPTIONAL); 83 | longFlag = longFlag.match(LONG_FLAG)[1]; 84 | return { 85 | name: longFlag.substr(2), 86 | shortFlag: shortFlag, 87 | longFlag: longFlag, 88 | description: description, 89 | hasArgument: !!(match && match[1]), 90 | isList: !!(match && match[2]) 91 | }; 92 | }; 93 | normalizeArguments = function(args) { 94 | var arg, l, match, result, _i, _j, _len, _len2, _ref; 95 | args = args.slice(0); 96 | result = []; 97 | for (_i = 0, _len = args.length; _i < _len; _i++) { 98 | arg = args[_i]; 99 | if (match = arg.match(MULTI_FLAG)) { 100 | _ref = match[1].split(''); 101 | for (_j = 0, _len2 = _ref.length; _j < _len2; _j++) { 102 | l = _ref[_j]; 103 | result.push('-' + l); 104 | } 105 | } else { 106 | result.push(arg); 107 | } 108 | } 109 | return result; 110 | }; 111 | }).call(this); 112 | -------------------------------------------------------------------------------- /node_modules/coffee-script/lib/repl.js: -------------------------------------------------------------------------------- 1 | (function() { 2 | var ACCESSOR, CoffeeScript, SIMPLEVAR, Script, autocomplete, backlog, completeAttribute, completeVariable, enableColours, error, getCompletions, getPropertyNames, inspect, readline, repl, run, stdin, stdout; 3 | var __hasProp = Object.prototype.hasOwnProperty; 4 | CoffeeScript = require('./coffee-script'); 5 | readline = require('readline'); 6 | inspect = require('util').inspect; 7 | Script = require('vm').Script; 8 | enableColours = false; 9 | if (process.platform !== 'win32') { 10 | enableColours = !process.env.NODE_DISABLE_COLORS; 11 | } 12 | stdin = process.openStdin(); 13 | stdout = process.stdout; 14 | error = function(err) { 15 | return stdout.write((err.stack || err.toString()) + '\n\n'); 16 | }; 17 | backlog = ''; 18 | run = (function() { 19 | var g, sandbox; 20 | sandbox = { 21 | require: require, 22 | module: { 23 | exports: {} 24 | } 25 | }; 26 | for (g in global) { 27 | sandbox[g] = global[g]; 28 | } 29 | sandbox.global = sandbox; 30 | sandbox.global.global = sandbox.global.root = sandbox.global.GLOBAL = sandbox; 31 | return function(buffer) { 32 | var code, val; 33 | code = backlog += '\n' + buffer.toString(); 34 | if (code[code.length - 1] === '\\') { 35 | return backlog = backlog.slice(0, backlog.length - 1); 36 | } 37 | backlog = ''; 38 | try { 39 | val = CoffeeScript.eval(code, { 40 | sandbox: sandbox, 41 | bare: true, 42 | filename: 'repl' 43 | }); 44 | if (val !== void 0) { 45 | process.stdout.write(inspect(val, false, 2, enableColours) + '\n'); 46 | } 47 | } catch (err) { 48 | error(err); 49 | } 50 | return repl.prompt(); 51 | }; 52 | })(); 53 | ACCESSOR = /\s*([\w\.]+)(?:\.(\w*))$/; 54 | SIMPLEVAR = /\s*(\w*)$/i; 55 | autocomplete = function(text) { 56 | return completeAttribute(text) || completeVariable(text) || [[], text]; 57 | }; 58 | completeAttribute = function(text) { 59 | var all, completions, match, obj, prefix, val; 60 | if (match = text.match(ACCESSOR)) { 61 | all = match[0], obj = match[1], prefix = match[2]; 62 | try { 63 | val = Script.runInThisContext(obj); 64 | } catch (error) { 65 | return [[], text]; 66 | } 67 | completions = getCompletions(prefix, getPropertyNames(val)); 68 | return [completions, prefix]; 69 | } 70 | }; 71 | completeVariable = function(text) { 72 | var completions, free, scope, _ref; 73 | if (free = (_ref = text.match(SIMPLEVAR)) != null ? _ref[1] : void 0) { 74 | scope = Script.runInThisContext('this'); 75 | completions = getCompletions(free, CoffeeScript.RESERVED.concat(getPropertyNames(scope))); 76 | return [completions, free]; 77 | } 78 | }; 79 | getCompletions = function(prefix, candidates) { 80 | var el, _i, _len, _results; 81 | _results = []; 82 | for (_i = 0, _len = candidates.length; _i < _len; _i++) { 83 | el = candidates[_i]; 84 | if (el.indexOf(prefix) === 0) { 85 | _results.push(el); 86 | } 87 | } 88 | return _results; 89 | }; 90 | getPropertyNames = function(obj) { 91 | var name, _results; 92 | _results = []; 93 | for (name in obj) { 94 | if (!__hasProp.call(obj, name)) continue; 95 | _results.push(name); 96 | } 97 | return _results; 98 | }; 99 | process.on('uncaughtException', error); 100 | if (readline.createInterface.length < 3) { 101 | repl = readline.createInterface(stdin, autocomplete); 102 | stdin.on('data', function(buffer) { 103 | return repl.write(buffer); 104 | }); 105 | } else { 106 | repl = readline.createInterface(stdin, stdout, autocomplete); 107 | } 108 | repl.setPrompt('coffee> '); 109 | repl.on('close', function() { 110 | return stdin.destroy(); 111 | }); 112 | repl.on('line', run); 113 | repl.prompt(); 114 | }).call(this); 115 | -------------------------------------------------------------------------------- /node_modules/coffee-script/lib/rewriter.js: -------------------------------------------------------------------------------- 1 | (function() { 2 | 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; 3 | var __indexOf = Array.prototype.indexOf || function(item) { 4 | for (var i = 0, l = this.length; i < l; i++) { 5 | if (this[i] === item) return i; 6 | } 7 | return -1; 8 | }, __slice = Array.prototype.slice; 9 | exports.Rewriter = (function() { 10 | function Rewriter() {} 11 | Rewriter.prototype.rewrite = function(tokens) { 12 | this.tokens = tokens; 13 | this.removeLeadingNewlines(); 14 | this.removeMidExpressionNewlines(); 15 | this.closeOpenCalls(); 16 | this.closeOpenIndexes(); 17 | this.addImplicitIndentation(); 18 | this.tagPostfixConditionals(); 19 | this.addImplicitBraces(); 20 | this.addImplicitParentheses(); 21 | this.ensureBalance(BALANCED_PAIRS); 22 | this.rewriteClosingParens(); 23 | return this.tokens; 24 | }; 25 | Rewriter.prototype.scanTokens = function(block) { 26 | var i, token, tokens; 27 | tokens = this.tokens; 28 | i = 0; 29 | while (token = tokens[i]) { 30 | i += block.call(this, token, i, tokens); 31 | } 32 | return true; 33 | }; 34 | Rewriter.prototype.detectEnd = function(i, condition, action) { 35 | var levels, token, tokens, _ref, _ref2; 36 | tokens = this.tokens; 37 | levels = 0; 38 | while (token = tokens[i]) { 39 | if (levels === 0 && condition.call(this, token, i)) { 40 | return action.call(this, token, i); 41 | } 42 | if (!token || levels < 0) { 43 | return action.call(this, token, i - 1); 44 | } 45 | if (_ref = token[0], __indexOf.call(EXPRESSION_START, _ref) >= 0) { 46 | levels += 1; 47 | } else if (_ref2 = token[0], __indexOf.call(EXPRESSION_END, _ref2) >= 0) { 48 | levels -= 1; 49 | } 50 | i += 1; 51 | } 52 | return i - 1; 53 | }; 54 | Rewriter.prototype.removeLeadingNewlines = function() { 55 | var i, tag, _len, _ref; 56 | _ref = this.tokens; 57 | for (i = 0, _len = _ref.length; i < _len; i++) { 58 | tag = _ref[i][0]; 59 | if (tag !== 'TERMINATOR') { 60 | break; 61 | } 62 | } 63 | if (i) { 64 | return this.tokens.splice(0, i); 65 | } 66 | }; 67 | Rewriter.prototype.removeMidExpressionNewlines = function() { 68 | return this.scanTokens(function(token, i, tokens) { 69 | var _ref; 70 | if (!(token[0] === 'TERMINATOR' && (_ref = this.tag(i + 1), __indexOf.call(EXPRESSION_CLOSE, _ref) >= 0))) { 71 | return 1; 72 | } 73 | tokens.splice(i, 1); 74 | return 0; 75 | }); 76 | }; 77 | Rewriter.prototype.closeOpenCalls = function() { 78 | var action, condition; 79 | condition = function(token, i) { 80 | var _ref; 81 | return ((_ref = token[0]) === ')' || _ref === 'CALL_END') || token[0] === 'OUTDENT' && this.tag(i - 1) === ')'; 82 | }; 83 | action = function(token, i) { 84 | return this.tokens[token[0] === 'OUTDENT' ? i - 1 : i][0] = 'CALL_END'; 85 | }; 86 | return this.scanTokens(function(token, i) { 87 | if (token[0] === 'CALL_START') { 88 | this.detectEnd(i + 1, condition, action); 89 | } 90 | return 1; 91 | }); 92 | }; 93 | Rewriter.prototype.closeOpenIndexes = function() { 94 | var action, condition; 95 | condition = function(token, i) { 96 | var _ref; 97 | return (_ref = token[0]) === ']' || _ref === 'INDEX_END'; 98 | }; 99 | action = function(token, i) { 100 | return token[0] = 'INDEX_END'; 101 | }; 102 | return this.scanTokens(function(token, i) { 103 | if (token[0] === 'INDEX_START') { 104 | this.detectEnd(i + 1, condition, action); 105 | } 106 | return 1; 107 | }); 108 | }; 109 | Rewriter.prototype.addImplicitBraces = function() { 110 | var action, condition, stack, start, startIndent; 111 | stack = []; 112 | start = null; 113 | startIndent = 0; 114 | condition = function(token, i) { 115 | var one, tag, three, two, _ref, _ref2; 116 | _ref = this.tokens.slice(i + 1, (i + 3 + 1) || 9e9), one = _ref[0], two = _ref[1], three = _ref[2]; 117 | if ('HERECOMMENT' === (one != null ? one[0] : void 0)) { 118 | return false; 119 | } 120 | tag = token[0]; 121 | return ((tag === 'TERMINATOR' || tag === 'OUTDENT') && !((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')); 122 | }; 123 | action = function(token, i) { 124 | var tok; 125 | tok = ['}', '}', token[2]]; 126 | tok.generated = true; 127 | return this.tokens.splice(i, 0, tok); 128 | }; 129 | return this.scanTokens(function(token, i, tokens) { 130 | var ago, idx, tag, tok, value, _ref, _ref2; 131 | if (_ref = (tag = token[0]), __indexOf.call(EXPRESSION_START, _ref) >= 0) { 132 | stack.push([(tag === 'INDENT' && this.tag(i - 1) === '{' ? '{' : tag), i]); 133 | return 1; 134 | } 135 | if (__indexOf.call(EXPRESSION_END, tag) >= 0) { 136 | start = stack.pop(); 137 | return 1; 138 | } 139 | if (!(tag === ':' && ((ago = this.tag(i - 2)) === ':' || ((_ref2 = stack[stack.length - 1]) != null ? _ref2[0] : void 0) !== '{'))) { 140 | return 1; 141 | } 142 | stack.push(['{']); 143 | idx = ago === '@' ? i - 2 : i - 1; 144 | while (this.tag(idx - 2) === 'HERECOMMENT') { 145 | idx -= 2; 146 | } 147 | value = new String('{'); 148 | value.generated = true; 149 | tok = ['{', value, token[2]]; 150 | tok.generated = true; 151 | tokens.splice(idx, 0, tok); 152 | this.detectEnd(i + 2, condition, action); 153 | return 2; 154 | }); 155 | }; 156 | Rewriter.prototype.addImplicitParentheses = function() { 157 | var action, noCall; 158 | noCall = false; 159 | action = function(token, i) { 160 | var idx; 161 | idx = token[0] === 'OUTDENT' ? i + 1 : i; 162 | return this.tokens.splice(idx, 0, ['CALL_END', ')', token[2]]); 163 | }; 164 | return this.scanTokens(function(token, i, tokens) { 165 | var callObject, current, next, prev, seenSingle, tag, _ref, _ref2, _ref3; 166 | tag = token[0]; 167 | if (tag === 'CLASS' || tag === 'IF') { 168 | noCall = true; 169 | } 170 | _ref = tokens.slice(i - 1, (i + 1 + 1) || 9e9), prev = _ref[0], current = _ref[1], next = _ref[2]; 171 | callObject = !noCall && tag === 'INDENT' && next && next.generated && next[0] === '{' && prev && (_ref2 = prev[0], __indexOf.call(IMPLICIT_FUNC, _ref2) >= 0); 172 | seenSingle = false; 173 | if (__indexOf.call(LINEBREAKS, tag) >= 0) { 174 | noCall = false; 175 | } 176 | if (prev && !prev.spaced && tag === '?') { 177 | token.call = true; 178 | } 179 | if (token.fromThen) { 180 | return 1; 181 | } 182 | 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))) { 183 | return 1; 184 | } 185 | tokens.splice(i, 0, ['CALL_START', '(', token[2]]); 186 | this.detectEnd(i + 1, function(token, i) { 187 | var post, _ref4; 188 | tag = token[0]; 189 | if (!seenSingle && token.fromThen) { 190 | return true; 191 | } 192 | if (tag === 'IF' || tag === 'ELSE' || tag === '->' || tag === '=>') { 193 | seenSingle = true; 194 | } 195 | if ((tag === '.' || tag === '?.' || tag === '::') && this.tag(i - 1) === 'OUTDENT') { 196 | return true; 197 | } 198 | return !token.generated && this.tag(i - 1) !== ',' && __indexOf.call(IMPLICIT_END, tag) >= 0 && (tag !== 'INDENT' || (this.tag(i - 2) !== 'CLASS' && (_ref4 = this.tag(i - 1), __indexOf.call(IMPLICIT_BLOCK, _ref4) < 0) && !((post = this.tokens[i + 1]) && post.generated && post[0] === '{'))); 199 | }, action); 200 | if (prev[0] === '?') { 201 | prev[0] = 'FUNC_EXIST'; 202 | } 203 | return 2; 204 | }); 205 | }; 206 | Rewriter.prototype.addImplicitIndentation = function() { 207 | return this.scanTokens(function(token, i, tokens) { 208 | var action, condition, indent, outdent, starter, tag, _ref, _ref2; 209 | tag = token[0]; 210 | if (tag === 'TERMINATOR' && this.tag(i + 1) === 'THEN') { 211 | tokens.splice(i, 1); 212 | return 0; 213 | } 214 | if (tag === 'ELSE' && this.tag(i - 1) !== 'OUTDENT') { 215 | tokens.splice.apply(tokens, [i, 0].concat(__slice.call(this.indentation(token)))); 216 | return 2; 217 | } 218 | if (tag === 'CATCH' && ((_ref = this.tag(i + 2)) === 'OUTDENT' || _ref === 'TERMINATOR' || _ref === 'FINALLY')) { 219 | tokens.splice.apply(tokens, [i + 2, 0].concat(__slice.call(this.indentation(token)))); 220 | return 4; 221 | } 222 | if (__indexOf.call(SINGLE_LINERS, tag) >= 0 && this.tag(i + 1) !== 'INDENT' && !(tag === 'ELSE' && this.tag(i + 1) === 'IF')) { 223 | starter = tag; 224 | _ref2 = this.indentation(token), indent = _ref2[0], outdent = _ref2[1]; 225 | if (starter === 'THEN') { 226 | indent.fromThen = true; 227 | } 228 | indent.generated = outdent.generated = true; 229 | tokens.splice(i + 1, 0, indent); 230 | condition = function(token, i) { 231 | var _ref3; 232 | return token[1] !== ';' && (_ref3 = token[0], __indexOf.call(SINGLE_CLOSERS, _ref3) >= 0) && !(token[0] === 'ELSE' && (starter !== 'IF' && starter !== 'THEN')); 233 | }; 234 | action = function(token, i) { 235 | return this.tokens.splice((this.tag(i - 1) === ',' ? i - 1 : i), 0, outdent); 236 | }; 237 | this.detectEnd(i + 2, condition, action); 238 | if (tag === 'THEN') { 239 | tokens.splice(i, 1); 240 | } 241 | return 1; 242 | } 243 | return 1; 244 | }); 245 | }; 246 | Rewriter.prototype.tagPostfixConditionals = function() { 247 | var condition; 248 | condition = function(token, i) { 249 | var _ref; 250 | return (_ref = token[0]) === 'TERMINATOR' || _ref === 'INDENT'; 251 | }; 252 | return this.scanTokens(function(token, i) { 253 | var original; 254 | if (token[0] !== 'IF') { 255 | return 1; 256 | } 257 | original = token; 258 | this.detectEnd(i + 1, condition, function(token, i) { 259 | if (token[0] !== 'INDENT') { 260 | return original[0] = 'POST_' + original[0]; 261 | } 262 | }); 263 | return 1; 264 | }); 265 | }; 266 | Rewriter.prototype.ensureBalance = function(pairs) { 267 | var close, level, levels, open, openLine, tag, token, _i, _j, _len, _len2, _ref, _ref2; 268 | levels = {}; 269 | openLine = {}; 270 | _ref = this.tokens; 271 | for (_i = 0, _len = _ref.length; _i < _len; _i++) { 272 | token = _ref[_i]; 273 | tag = token[0]; 274 | for (_j = 0, _len2 = pairs.length; _j < _len2; _j++) { 275 | _ref2 = pairs[_j], open = _ref2[0], close = _ref2[1]; 276 | levels[open] |= 0; 277 | if (tag === open) { 278 | if (levels[open]++ === 0) { 279 | openLine[open] = token[2]; 280 | } 281 | } else if (tag === close && --levels[open] < 0) { 282 | throw Error("too many " + token[1] + " on line " + (token[2] + 1)); 283 | } 284 | } 285 | } 286 | for (open in levels) { 287 | level = levels[open]; 288 | if (level > 0) { 289 | throw Error("unclosed " + open + " on line " + (openLine[open] + 1)); 290 | } 291 | } 292 | return this; 293 | }; 294 | Rewriter.prototype.rewriteClosingParens = function() { 295 | var debt, key, stack; 296 | stack = []; 297 | debt = {}; 298 | for (key in INVERSES) { 299 | debt[key] = 0; 300 | } 301 | return this.scanTokens(function(token, i, tokens) { 302 | var inv, match, mtag, oppos, tag, val, _ref; 303 | if (_ref = (tag = token[0]), __indexOf.call(EXPRESSION_START, _ref) >= 0) { 304 | stack.push(token); 305 | return 1; 306 | } 307 | if (__indexOf.call(EXPRESSION_END, tag) < 0) { 308 | return 1; 309 | } 310 | if (debt[inv = INVERSES[tag]] > 0) { 311 | debt[inv] -= 1; 312 | tokens.splice(i, 1); 313 | return 0; 314 | } 315 | match = stack.pop(); 316 | mtag = match[0]; 317 | oppos = INVERSES[mtag]; 318 | if (tag === oppos) { 319 | return 1; 320 | } 321 | debt[mtag] += 1; 322 | val = [oppos, mtag === 'INDENT' ? match[1] : oppos]; 323 | if (this.tag(i + 2) === mtag) { 324 | tokens.splice(i + 3, 0, val); 325 | stack.push(match); 326 | } else { 327 | tokens.splice(i, 0, val); 328 | } 329 | return 1; 330 | }); 331 | }; 332 | Rewriter.prototype.indentation = function(token) { 333 | return [['INDENT', 2, token[2]], ['OUTDENT', 2, token[2]]]; 334 | }; 335 | Rewriter.prototype.tag = function(i) { 336 | var _ref; 337 | return (_ref = this.tokens[i]) != null ? _ref[0] : void 0; 338 | }; 339 | return Rewriter; 340 | })(); 341 | BALANCED_PAIRS = [['(', ')'], ['[', ']'], ['{', '}'], ['INDENT', 'OUTDENT'], ['CALL_START', 'CALL_END'], ['PARAM_START', 'PARAM_END'], ['INDEX_START', 'INDEX_END']]; 342 | INVERSES = {}; 343 | EXPRESSION_START = []; 344 | EXPRESSION_END = []; 345 | for (_i = 0, _len = BALANCED_PAIRS.length; _i < _len; _i++) { 346 | _ref = BALANCED_PAIRS[_i], left = _ref[0], rite = _ref[1]; 347 | EXPRESSION_START.push(INVERSES[rite] = left); 348 | EXPRESSION_END.push(INVERSES[left] = rite); 349 | } 350 | EXPRESSION_CLOSE = ['CATCH', 'WHEN', 'ELSE', 'FINALLY'].concat(EXPRESSION_END); 351 | IMPLICIT_FUNC = ['IDENTIFIER', 'SUPER', ')', 'CALL_END', ']', 'INDEX_END', '@', 'THIS']; 352 | IMPLICIT_CALL = ['IDENTIFIER', 'NUMBER', 'STRING', 'JS', 'REGEX', 'NEW', 'PARAM_START', 'CLASS', 'IF', 'TRY', 'SWITCH', 'THIS', 'BOOL', 'UNARY', 'SUPER', '@', '->', '=>', '[', '(', '{', '--', '++']; 353 | IMPLICIT_UNSPACED_CALL = ['+', '-']; 354 | IMPLICIT_BLOCK = ['->', '=>', '{', '[', ',']; 355 | IMPLICIT_END = ['POST_IF', 'FOR', 'WHILE', 'UNTIL', 'WHEN', 'BY', 'LOOP', 'TERMINATOR', 'INDENT']; 356 | SINGLE_LINERS = ['ELSE', '->', '=>', 'TRY', 'FINALLY', 'THEN']; 357 | SINGLE_CLOSERS = ['TERMINATOR', 'CATCH', 'FINALLY', 'ELSE', 'OUTDENT', 'LEADING_WHEN']; 358 | LINEBREAKS = ['TERMINATOR', 'INDENT', 'OUTDENT']; 359 | }).call(this); 360 | -------------------------------------------------------------------------------- /node_modules/coffee-script/lib/scope.js: -------------------------------------------------------------------------------- 1 | (function() { 2 | var Scope, extend, last, _ref; 3 | _ref = require('./helpers'), extend = _ref.extend, last = _ref.last; 4 | exports.Scope = Scope = (function() { 5 | Scope.root = null; 6 | function Scope(parent, expressions, method) { 7 | this.parent = parent; 8 | this.expressions = expressions; 9 | this.method = method; 10 | this.variables = [ 11 | { 12 | name: 'arguments', 13 | type: 'arguments' 14 | } 15 | ]; 16 | this.positions = {}; 17 | if (!this.parent) { 18 | Scope.root = this; 19 | } 20 | } 21 | Scope.prototype.add = function(name, type, immediate) { 22 | var pos; 23 | if (this.shared && !immediate) { 24 | return this.parent.add(name, type, immediate); 25 | } 26 | if (typeof (pos = this.positions[name]) === 'number') { 27 | return this.variables[pos].type = type; 28 | } else { 29 | return this.positions[name] = this.variables.push({ 30 | name: name, 31 | type: type 32 | }) - 1; 33 | } 34 | }; 35 | Scope.prototype.find = function(name, options) { 36 | if (this.check(name, options)) { 37 | return true; 38 | } 39 | this.add(name, 'var'); 40 | return false; 41 | }; 42 | Scope.prototype.parameter = function(name) { 43 | if (this.shared && this.parent.check(name, true)) { 44 | return; 45 | } 46 | return this.add(name, 'param'); 47 | }; 48 | Scope.prototype.check = function(name, immediate) { 49 | var found, _ref2; 50 | found = !!this.type(name); 51 | if (found || immediate) { 52 | return found; 53 | } 54 | return !!((_ref2 = this.parent) != null ? _ref2.check(name) : void 0); 55 | }; 56 | Scope.prototype.temporary = function(name, index) { 57 | if (name.length > 1) { 58 | return '_' + name + (index > 1 ? index : ''); 59 | } else { 60 | return '_' + (index + parseInt(name, 36)).toString(36).replace(/\d/g, 'a'); 61 | } 62 | }; 63 | Scope.prototype.type = function(name) { 64 | var v, _i, _len, _ref2; 65 | _ref2 = this.variables; 66 | for (_i = 0, _len = _ref2.length; _i < _len; _i++) { 67 | v = _ref2[_i]; 68 | if (v.name === name) { 69 | return v.type; 70 | } 71 | } 72 | return null; 73 | }; 74 | Scope.prototype.freeVariable = function(type) { 75 | var index, temp; 76 | index = 0; 77 | while (this.check((temp = this.temporary(type, index)))) { 78 | index++; 79 | } 80 | this.add(temp, 'var', true); 81 | return temp; 82 | }; 83 | Scope.prototype.assign = function(name, value) { 84 | this.add(name, { 85 | value: value, 86 | assigned: true 87 | }); 88 | return this.hasAssignments = true; 89 | }; 90 | Scope.prototype.hasDeclarations = function() { 91 | return !!this.declaredVariables().length; 92 | }; 93 | Scope.prototype.declaredVariables = function() { 94 | var realVars, tempVars, v, _i, _len, _ref2; 95 | realVars = []; 96 | tempVars = []; 97 | _ref2 = this.variables; 98 | for (_i = 0, _len = _ref2.length; _i < _len; _i++) { 99 | v = _ref2[_i]; 100 | if (v.type === 'var') { 101 | (v.name.charAt(0) === '_' ? tempVars : realVars).push(v.name); 102 | } 103 | } 104 | return realVars.sort().concat(tempVars.sort()); 105 | }; 106 | Scope.prototype.assignedVariables = function() { 107 | var v, _i, _len, _ref2, _results; 108 | _ref2 = this.variables; 109 | _results = []; 110 | for (_i = 0, _len = _ref2.length; _i < _len; _i++) { 111 | v = _ref2[_i]; 112 | if (v.type.assigned) { 113 | _results.push("" + v.name + " = " + v.type.value); 114 | } 115 | } 116 | return _results; 117 | }; 118 | return Scope; 119 | })(); 120 | }).call(this); 121 | -------------------------------------------------------------------------------- /node_modules/coffee-script/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "coffee-script", 3 | "description": "Unfancy JavaScript", 4 | "keywords": ["javascript", "language", "coffeescript", "compiler"], 5 | "author": "Jeremy Ashkenas", 6 | "version": "1.1.1", 7 | "licenses": [{ 8 | "type": "MIT", 9 | "url": "http://github.com/jashkenas/coffee-script/raw/master/LICENSE" 10 | }], 11 | "engines": { 12 | "node": ">=0.2.5" 13 | }, 14 | "directories" : { 15 | "lib" : "./lib" 16 | }, 17 | "main" : "./lib/coffee-script", 18 | "bin": { 19 | "coffee": "./bin/coffee", 20 | "cake": "./bin/cake" 21 | }, 22 | "homepage": "http://coffeescript.org", 23 | "repository": { 24 | "type": "git", 25 | "url": "git://github.com/jashkenas/coffee-script.git" 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /node_modules/colors/MIT-LICENSE.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) 2010 Alexis Sellier (cloudhead) , Marak Squires 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | THE SOFTWARE. -------------------------------------------------------------------------------- /node_modules/colors/ReadMe.md: -------------------------------------------------------------------------------- 1 |