Merge branch 'master' of github.com:jashkenas/coffeescript

This commit is contained in:
Jeremy Ashkenas
2015-02-03 11:31:44 -05:00
20 changed files with 858 additions and 849 deletions

View File

@@ -1,7 +1,7 @@
// Generated by CoffeeScript 1.9.0
(function() {
var CoffeeScript, compile, runScripts,
_indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };
indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };
CoffeeScript = require('./coffee-script');
@@ -34,13 +34,13 @@
if ((typeof btoa !== "undefined" && btoa !== null) && (typeof JSON !== "undefined" && JSON !== null) && (typeof unescape !== "undefined" && unescape !== null) && (typeof encodeURIComponent !== "undefined" && encodeURIComponent !== null)) {
compile = function(code, options) {
var js, v3SourceMap, _ref;
var js, ref, v3SourceMap;
if (options == null) {
options = {};
}
options.sourceMap = true;
options.inline = true;
_ref = CoffeeScript.compile(code, options), js = _ref.js, v3SourceMap = _ref.v3SourceMap;
ref = CoffeeScript.compile(code, options), js = ref.js, v3SourceMap = ref.v3SourceMap;
return js + "\n//# sourceMappingURL=data:application/json;base64," + (btoa(unescape(encodeURIComponent(v3SourceMap)))) + "\n//# sourceURL=coffeescript";
};
}
@@ -60,9 +60,9 @@
xhr.overrideMimeType('text/plain');
}
xhr.onreadystatechange = function() {
var param, _ref;
var param, ref;
if (xhr.readyState === 4) {
if ((_ref = xhr.status) === 0 || _ref === 200) {
if ((ref = xhr.status) === 0 || ref === 200) {
param = [xhr.responseText, options];
if (!hold) {
CoffeeScript.run.apply(CoffeeScript, param);
@@ -79,19 +79,19 @@
};
runScripts = function() {
var coffees, coffeetypes, execute, i, index, s, script, scripts, _fn, _i, _len;
var coffees, coffeetypes, execute, fn, i, index, j, len, s, script, scripts;
scripts = window.document.getElementsByTagName('script');
coffeetypes = ['text/coffeescript', 'text/literate-coffeescript'];
coffees = (function() {
var _i, _len, _ref, _results;
_results = [];
for (_i = 0, _len = scripts.length; _i < _len; _i++) {
s = scripts[_i];
if (_ref = s.type, _indexOf.call(coffeetypes, _ref) >= 0) {
_results.push(s);
var j, len, ref, results;
results = [];
for (j = 0, len = scripts.length; j < len; j++) {
s = scripts[j];
if (ref = s.type, indexOf.call(coffeetypes, ref) >= 0) {
results.push(s);
}
}
return _results;
return results;
})();
index = 0;
execute = function() {
@@ -103,7 +103,7 @@
return execute();
}
};
_fn = function(script, i) {
fn = function(script, i) {
var options;
options = {
literate: script.type === coffeetypes[1]
@@ -118,9 +118,9 @@
return coffees[i] = [script.innerHTML, options];
}
};
for (i = _i = 0, _len = coffees.length; _i < _len; i = ++_i) {
for (i = j = 0, len = coffees.length; j < len; i = ++j) {
script = coffees[i];
_fn(script, i);
fn(script, i);
}
return execute();
};

View File

@@ -24,9 +24,9 @@
helpers.extend(global, {
task: function(name, description, action) {
var _ref;
var ref;
if (!action) {
_ref = [description, action], action = _ref[0], description = _ref[1];
ref = [description, action], action = ref[0], description = ref[1];
}
return tasks[name] = {
name: name,
@@ -46,7 +46,7 @@
});
exports.run = function() {
var arg, args, e, _i, _len, _ref, _results;
var arg, args, e, i, len, ref, results;
global.__originalDirname = fs.realpathSync('.');
process.chdir(cakefileDirectory(__originalDirname));
args = process.argv.slice(2);
@@ -63,13 +63,13 @@
e = _error;
return fatalError("" + e);
}
_ref = options["arguments"];
_results = [];
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
arg = _ref[_i];
_results.push(invoke(arg));
ref = options["arguments"];
results = [];
for (i = 0, len = ref.length; i < len; i++) {
arg = ref[i];
results.push(invoke(arg));
}
return _results;
return results;
};
printTasks = function() {

View File

@@ -1,8 +1,8 @@
// Generated by CoffeeScript 1.9.0
(function() {
var Lexer, SourceMap, compile, ext, formatSourcePosition, fs, getSourceMap, helpers, lexer, parser, path, sourceMaps, vm, withPrettyErrors, _base, _i, _len, _ref,
_hasProp = {}.hasOwnProperty,
_indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };
var Lexer, SourceMap, base, compile, ext, formatSourcePosition, fs, getSourceMap, helpers, i, len, lexer, parser, path, ref, sourceMaps, vm, withPrettyErrors,
hasProp = {}.hasOwnProperty,
indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };
fs = require('fs');
@@ -40,7 +40,7 @@
};
exports.compile = compile = withPrettyErrors(function(code, options) {
var answer, currentColumn, currentLine, extend, fragment, fragments, header, js, map, merge, newLines, token, tokens, _i, _len;
var answer, currentColumn, currentLine, extend, fragment, fragments, header, i, js, len, map, merge, newLines, token, tokens;
merge = helpers.merge, extend = helpers.extend;
options = extend({}, options);
if (options.sourceMap) {
@@ -48,15 +48,15 @@
}
tokens = lexer.tokenize(code, options);
options.referencedVars = (function() {
var _i, _len, _results;
_results = [];
for (_i = 0, _len = tokens.length; _i < _len; _i++) {
token = tokens[_i];
if (token.variable && token[1].charAt(0) === '_') {
_results.push(token[1]);
var i, len, results;
results = [];
for (i = 0, len = tokens.length; i < len; i++) {
token = tokens[i];
if (token.variable) {
results.push(token[1]);
}
}
return _results;
return results;
})();
fragments = parser.parse(tokens).compileToFragments(options);
currentLine = 0;
@@ -68,8 +68,8 @@
}
currentColumn = 0;
js = "";
for (_i = 0, _len = fragments.length; _i < _len; _i++) {
fragment = fragments[_i];
for (i = 0, len = fragments.length; i < len; i++) {
fragment = fragments[i];
if (options.sourceMap) {
if (fragment.locationData) {
map.add([fragment.locationData.first_line, fragment.locationData.first_column], [currentLine, currentColumn], {
@@ -115,7 +115,7 @@
});
exports.run = function(code, options) {
var answer, dir, mainModule, _ref;
var answer, dir, mainModule, ref;
if (options == null) {
options = {};
}
@@ -126,21 +126,21 @@
mainModule.paths = require('module')._nodeModulePaths(dir);
if (!helpers.isCoffee(mainModule.filename) || require.extensions) {
answer = compile(code, options);
code = (_ref = answer.js) != null ? _ref : answer;
code = (ref = answer.js) != null ? ref : answer;
}
return mainModule._compile(code, mainModule.filename);
};
exports["eval"] = function(code, options) {
var Module, createContext, isContext, js, k, o, r, sandbox, v, _i, _len, _module, _ref, _ref1, _ref2, _ref3, _require;
var Module, _module, _require, createContext, i, isContext, js, k, len, o, r, ref, ref1, ref2, ref3, sandbox, v;
if (options == null) {
options = {};
}
if (!(code = code.trim())) {
return;
}
createContext = (_ref = vm.Script.createContext) != null ? _ref : vm.createContext;
isContext = (_ref1 = vm.isContext) != null ? _ref1 : function(ctx) {
createContext = (ref = vm.Script.createContext) != null ? ref : vm.createContext;
isContext = (ref1 = vm.isContext) != null ? ref1 : function(ctx) {
return options.sandbox instanceof createContext().constructor;
};
if (createContext) {
@@ -149,10 +149,10 @@
sandbox = options.sandbox;
} else {
sandbox = createContext();
_ref2 = options.sandbox;
for (k in _ref2) {
if (!_hasProp.call(_ref2, k)) continue;
v = _ref2[k];
ref2 = options.sandbox;
for (k in ref2) {
if (!hasProp.call(ref2, k)) continue;
v = ref2[k];
sandbox[k] = v;
}
}
@@ -169,9 +169,9 @@
return Module._load(path, _module, true);
};
_module.filename = sandbox.__filename;
_ref3 = Object.getOwnPropertyNames(require);
for (_i = 0, _len = _ref3.length; _i < _len; _i++) {
r = _ref3[_i];
ref3 = Object.getOwnPropertyNames(require);
for (i = 0, len = ref3.length; i < len; i++) {
r = ref3[i];
if (r !== 'paths') {
_require[r] = require[r];
}
@@ -184,7 +184,7 @@
}
o = {};
for (k in options) {
if (!_hasProp.call(options, k)) continue;
if (!hasProp.call(options, k)) continue;
v = options[k];
o[k] = v;
}
@@ -202,11 +202,11 @@
};
if (require.extensions) {
_ref = this.FILE_EXTENSIONS;
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
ext = _ref[_i];
if ((_base = require.extensions)[ext] == null) {
_base[ext] = function() {
ref = this.FILE_EXTENSIONS;
for (i = 0, len = ref.length; i < len; i++) {
ext = ref[i];
if ((base = require.extensions)[ext] == null) {
base[ext] = function() {
throw new Error("Use CoffeeScript.register() or require the coffee-script/register module to require " + ext + " files.");
};
}
@@ -259,9 +259,9 @@
parser.yy = require('./nodes');
parser.yy.parseError = function(message, _arg) {
parser.yy.parseError = function(message, arg) {
var errorLoc, errorTag, errorText, errorToken, token, tokens;
token = _arg.token;
token = arg.token;
errorToken = parser.errorToken, tokens = parser.tokens;
errorTag = errorToken[0], errorText = errorToken[1], errorLoc = errorToken[2];
errorText = errorToken === tokens[tokens.length - 1] ? 'end of input' : errorTag === 'INDENT' || errorTag === 'OUTDENT' ? 'indentation' : helpers.nameWhitespaceCharacter(errorText);
@@ -319,11 +319,11 @@
sourceMaps = {};
getSourceMap = function(filename) {
var answer, _ref1;
var answer, ref1;
if (sourceMaps[filename]) {
return sourceMaps[filename];
}
if (_ref1 = path != null ? path.extname(filename) : void 0, _indexOf.call(exports.FILE_EXTENSIONS, _ref1) < 0) {
if (ref1 = path != null ? path.extname(filename) : void 0, indexOf.call(exports.FILE_EXTENSIONS, ref1) < 0) {
return;
}
answer = exports._compileFile(filename, true);
@@ -345,16 +345,16 @@
}
};
frames = (function() {
var _j, _len1, _results;
_results = [];
for (_j = 0, _len1 = stack.length; _j < _len1; _j++) {
frame = stack[_j];
var j, len1, results;
results = [];
for (j = 0, len1 = stack.length; j < len1; j++) {
frame = stack[j];
if (frame.getFunction() === exports.run) {
break;
}
_results.push(" at " + (formatSourcePosition(frame, getSourceMapping)));
results.push(" at " + (formatSourcePosition(frame, getSourceMapping)));
}
return _results;
return results;
})();
return (err.toString()) + "\n" + (frames.join('\n')) + "\n";
};

View File

@@ -1,7 +1,7 @@
// Generated by CoffeeScript 1.9.0
(function() {
var BANNER, CoffeeScript, EventEmitter, SWITCHES, compileJoin, compileOptions, compilePath, compileScript, compileStdio, exec, findDirectoryIndex, forkNode, fs, helpers, hidden, joinTimeout, mkdirp, notSources, optionParser, optparse, opts, outputPath, parseOptions, path, printLine, printTokens, printWarn, removeSource, removeSourceDir, silentUnlink, sourceCode, sources, spawn, timeLog, usage, useWinPathSep, version, wait, watch, watchDir, watchedDirs, writeJs, _ref,
_indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };
var BANNER, CoffeeScript, EventEmitter, SWITCHES, compileJoin, compileOptions, compilePath, compileScript, compileStdio, exec, findDirectoryIndex, forkNode, fs, helpers, hidden, joinTimeout, mkdirp, notSources, optionParser, optparse, opts, outputPath, parseOptions, path, printLine, printTokens, printWarn, ref, removeSource, removeSourceDir, silentUnlink, sourceCode, sources, spawn, timeLog, usage, useWinPathSep, version, wait, watch, watchDir, watchedDirs, writeJs,
indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };
fs = require('fs');
@@ -13,7 +13,7 @@
CoffeeScript = require('./coffee-script');
_ref = require('child_process'), spawn = _ref.spawn, exec = _ref.exec;
ref = require('child_process'), spawn = ref.spawn, exec = ref.exec;
EventEmitter = require('events').EventEmitter;
@@ -50,7 +50,7 @@
optionParser = null;
exports.run = function() {
var literals, replCliOpts, source, _i, _len, _ref1, _results;
var i, len, literals, ref1, replCliOpts, results, source;
parseOptions();
replCliOpts = {
useGlobal: true
@@ -86,19 +86,19 @@
opts.join = path.resolve(opts.join);
console.error('\nThe --join option is deprecated and will be removed in a future version.\n\nIf for some reason it\'s necessary to share local variables between files,\nreplace...\n\n $ coffee --compile --join bundle.js -- a.coffee b.coffee c.coffee\n\nwith...\n\n $ cat a.coffee b.coffee c.coffee | coffee --compile --stdio > bundle.js\n');
}
_ref1 = opts["arguments"];
_results = [];
for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
source = _ref1[_i];
ref1 = opts["arguments"];
results = [];
for (i = 0, len = ref1.length; i < len; i++) {
source = ref1[i];
source = path.resolve(source);
_results.push(compilePath(source, true, source));
results.push(compilePath(source, true, source));
}
return _results;
return results;
};
compilePath = function(source, topLevel, base) {
var code, err, file, files, stats, _i, _len, _results;
if (_indexOf.call(sources, source) >= 0 || watchedDirs[source] || !topLevel && (notSources[source] || hidden(source))) {
var code, err, file, files, i, len, results, stats;
if (indexOf.call(sources, source) >= 0 || watchedDirs[source] || !topLevel && (notSources[source] || hidden(source))) {
return;
}
try {
@@ -133,12 +133,12 @@
throw err;
}
}
_results = [];
for (_i = 0, _len = files.length; _i < _len; _i++) {
file = files[_i];
_results.push(compilePath(path.join(source, file), false, base));
results = [];
for (i = 0, len = files.length; i < len; i++) {
file = files[i];
results.push(compilePath(path.join(source, file), false, base));
}
return _results;
return results;
} else if (topLevel || helpers.isCoffee(source)) {
sources.push(source);
sourceCode.push(null);
@@ -163,10 +163,10 @@
};
findDirectoryIndex = function(source) {
var err, ext, index, _i, _len, _ref1;
_ref1 = CoffeeScript.FILE_EXTENSIONS;
for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
ext = _ref1[_i];
var err, ext, i, index, len, ref1;
ref1 = CoffeeScript.FILE_EXTENSIONS;
for (i = 0, len = ref1.length; i < len; i++) {
ext = ref1[i];
index = path.join(source, "index" + ext);
try {
if ((fs.statSync(index)).isFile()) {
@@ -279,7 +279,7 @@
if (err.code !== 'ENOENT') {
throw err;
}
if (_indexOf.call(sources, source) < 0) {
if (indexOf.call(sources, source) < 0) {
return;
}
try {
@@ -346,7 +346,7 @@
}).on('change', function() {
clearTimeout(readdirTimeout);
return readdirTimeout = wait(25, function() {
var err, file, files, _i, _len, _results;
var err, file, files, i, len, results;
try {
files = fs.readdirSync(source);
} catch (_error) {
@@ -356,12 +356,12 @@
}
return stopWatcher();
}
_results = [];
for (_i = 0, _len = files.length; _i < _len; _i++) {
file = files[_i];
_results.push(compilePath(path.join(source, file), false, base));
results = [];
for (i = 0, len = files.length; i < len; i++) {
file = files[i];
results.push(compilePath(path.join(source, file), false, base));
}
return _results;
return results;
});
});
};
@@ -381,11 +381,11 @@
};
removeSourceDir = function(source, base) {
var file, sourcesChanged, _i, _len;
var file, i, len, sourcesChanged;
delete watchedDirs[source];
sourcesChanged = false;
for (_i = 0, _len = sources.length; _i < _len; _i++) {
file = sources[_i];
for (i = 0, len = sources.length; i < len; i++) {
file = sources[i];
if (!(source === path.dirname(file))) {
continue;
}
@@ -410,12 +410,12 @@
};
silentUnlink = function(path) {
var err, _ref1;
var err, ref1;
try {
return fs.unlinkSync(path);
} catch (_error) {
err = _error;
if ((_ref1 = err.code) !== 'ENOENT' && _ref1 !== 'EPERM') {
if ((ref1 = err.code) !== 'ENOENT' && ref1 !== 'EPERM') {
throw err;
}
}
@@ -512,15 +512,15 @@
printTokens = function(tokens) {
var strings, tag, token, value;
strings = (function() {
var _i, _len, _results;
_results = [];
for (_i = 0, _len = tokens.length; _i < _len; _i++) {
token = tokens[_i];
var i, len, results;
results = [];
for (i = 0, len = tokens.length; i < len; i++) {
token = tokens[i];
tag = token[0];
value = token[1].toString().replace(/\n/, '\\n');
_results.push("[" + tag + " " + value + "]");
results.push("[" + tag + " " + value + "]");
}
return _results;
return results;
})();
return printLine(strings.join(' '));
};

View File

@@ -612,13 +612,13 @@
for (name in grammar) {
alternatives = grammar[name];
grammar[name] = (function() {
var _i, _j, _len, _len1, _ref, _results;
_results = [];
for (_i = 0, _len = alternatives.length; _i < _len; _i++) {
alt = alternatives[_i];
_ref = alt[0].split(' ');
for (_j = 0, _len1 = _ref.length; _j < _len1; _j++) {
token = _ref[_j];
var i, j, len, len1, ref, results;
results = [];
for (i = 0, len = alternatives.length; i < len; i++) {
alt = alternatives[i];
ref = alt[0].split(' ');
for (j = 0, len1 = ref.length; j < len1; j++) {
token = ref[j];
if (!grammar[token]) {
tokens.push(token);
}
@@ -626,9 +626,9 @@
if (name === 'Root') {
alt[1] = "return " + alt[1];
}
_results.push(alt);
results.push(alt);
}
return _results;
return results;
})();
}

View File

@@ -1,6 +1,6 @@
// Generated by CoffeeScript 1.9.0
(function() {
var buildLocationData, extend, flatten, last, repeat, syntaxErrorToString, _ref;
var buildLocationData, extend, flatten, last, ref, repeat, syntaxErrorToString;
exports.starts = function(string, literal, start) {
return literal === string.substr(start, literal.length);
@@ -26,15 +26,15 @@
};
exports.compact = function(array) {
var item, _i, _len, _results;
_results = [];
for (_i = 0, _len = array.length; _i < _len; _i++) {
item = array[_i];
var i, item, len1, results;
results = [];
for (i = 0, len1 = array.length; i < len1; i++) {
item = array[i];
if (item) {
_results.push(item);
results.push(item);
}
}
return _results;
return results;
};
exports.count = function(string, substr) {
@@ -63,10 +63,10 @@
};
exports.flatten = flatten = function(array) {
var element, flattened, _i, _len;
var element, flattened, i, len1;
flattened = [];
for (_i = 0, _len = array.length; _i < _len; _i++) {
element = array[_i];
for (i = 0, len1 = array.length; i < len1; i++) {
element = array[i];
if (element instanceof Array) {
flattened = flattened.concat(flatten(element));
} else {
@@ -87,10 +87,10 @@
return array[array.length - (back || 0) - 1];
};
exports.some = (_ref = Array.prototype.some) != null ? _ref : function(fn) {
var e, _i, _len;
for (_i = 0, _len = this.length; _i < _len; _i++) {
e = this[_i];
exports.some = (ref = Array.prototype.some) != null ? ref : function(fn) {
var e, i, len1;
for (i = 0, len1 = this.length; i < len1; i++) {
e = this[i];
if (fn(e)) {
return true;
}
@@ -102,20 +102,20 @@
var line, lines, maybe_code;
maybe_code = true;
lines = (function() {
var _i, _len, _ref1, _results;
_ref1 = code.split('\n');
_results = [];
for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
line = _ref1[_i];
var i, len1, ref1, results;
ref1 = code.split('\n');
results = [];
for (i = 0, len1 = ref1.length; i < len1; i++) {
line = ref1[i];
if (maybe_code && /^([ ]{4}|[ ]{0,3}\t)/.test(line)) {
_results.push(line);
results.push(line);
} else if (maybe_code = /^\s*$/.test(line)) {
_results.push(line);
results.push(line);
} else {
_results.push('# ' + line);
results.push('# ' + line);
}
}
return _results;
return results;
})();
return lines.join('\n');
};
@@ -205,11 +205,11 @@
};
syntaxErrorToString = function() {
var codeLine, colorize, colorsEnabled, end, filename, first_column, first_line, last_column, last_line, marker, start, _ref1, _ref2;
var codeLine, colorize, colorsEnabled, end, filename, first_column, first_line, last_column, last_line, marker, ref1, ref2, start;
if (!(this.code && this.location)) {
return Error.prototype.toString.call(this);
}
_ref1 = this.location, first_line = _ref1.first_line, first_column = _ref1.first_column, last_line = _ref1.last_line, last_column = _ref1.last_column;
ref1 = this.location, first_line = ref1.first_line, first_column = ref1.first_column, last_line = ref1.last_line, last_column = ref1.last_column;
if (last_line == null) {
last_line = first_line;
}
@@ -224,7 +224,7 @@
if (typeof process !== "undefined" && process !== null) {
colorsEnabled = process.stdout.isTTY && !process.env.NODE_DISABLE_COLORS;
}
if ((_ref2 = this.colorful) != null ? _ref2 : colorsEnabled) {
if ((ref2 = this.colorful) != null ? ref2 : colorsEnabled) {
colorize = function(str) {
return "\x1B[1;31m" + str + "\x1B[0m";
};

View File

@@ -1,10 +1,10 @@
// Generated by CoffeeScript 1.9.0
(function() {
var key, val, _ref;
var key, ref, val;
_ref = require('./coffee-script');
for (key in _ref) {
val = _ref[key];
ref = require('./coffee-script');
for (key in ref) {
val = ref[key];
exports[key] = val;
}

View File

@@ -1,17 +1,17 @@
// Generated by CoffeeScript 1.9.0
(function() {
var BOM, BOOL, CALLABLE, CODE, COFFEE_ALIASES, COFFEE_ALIAS_MAP, COFFEE_KEYWORDS, COMMENT, COMPARE, COMPOUND_ASSIGN, HERECOMMENT_ILLEGAL, HEREDOC_DOUBLE, HEREDOC_INDENT, HEREDOC_SINGLE, HEREGEX, HEREGEX_OMIT, IDENTIFIER, INDENTABLE_CLOSERS, INDEXABLE, INVERSES, JSTOKEN, JS_FORBIDDEN, JS_KEYWORDS, LEADING_BLANK_LINE, LINE_BREAK, LINE_CONTINUER, LOGIC, Lexer, MATH, MULTILINER, MULTI_DENT, NOT_REGEX, NUMBER, OCTAL_ESCAPE, OPERATOR, POSSIBLY_DIVISION, REGEX, REGEX_FLAGS, REGEX_ILLEGAL, RELATION, RESERVED, Rewriter, SHIFT, STRICT_PROSCRIBED, STRING_DOUBLE, STRING_OMIT, STRING_SINGLE, STRING_START, TRAILING_BLANK_LINE, TRAILING_SPACES, UNARY, UNARY_MATH, VALID_FLAGS, WHITESPACE, compact, count, invertLiterate, key, last, locationDataToString, repeat, starts, throwSyntaxError, _ref, _ref1,
_indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };
var BOM, BOOL, CALLABLE, CODE, COFFEE_ALIASES, COFFEE_ALIAS_MAP, COFFEE_KEYWORDS, COMMENT, COMPARE, COMPOUND_ASSIGN, HERECOMMENT_ILLEGAL, HEREDOC_DOUBLE, HEREDOC_INDENT, HEREDOC_SINGLE, HEREGEX, HEREGEX_OMIT, IDENTIFIER, INDENTABLE_CLOSERS, INDEXABLE, INVERSES, JSTOKEN, JS_FORBIDDEN, JS_KEYWORDS, LEADING_BLANK_LINE, LINE_BREAK, LINE_CONTINUER, LOGIC, Lexer, MATH, MULTILINER, MULTI_DENT, NOT_REGEX, NUMBER, OCTAL_ESCAPE, OPERATOR, POSSIBLY_DIVISION, REGEX, REGEX_FLAGS, REGEX_ILLEGAL, RELATION, RESERVED, Rewriter, SHIFT, STRICT_PROSCRIBED, STRING_DOUBLE, STRING_OMIT, STRING_SINGLE, STRING_START, TRAILING_BLANK_LINE, TRAILING_SPACES, UNARY, UNARY_MATH, VALID_FLAGS, WHITESPACE, compact, count, invertLiterate, key, last, locationDataToString, ref, ref1, repeat, starts, throwSyntaxError,
indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };
_ref = require('./rewriter'), Rewriter = _ref.Rewriter, INVERSES = _ref.INVERSES;
ref = require('./rewriter'), Rewriter = ref.Rewriter, INVERSES = ref.INVERSES;
_ref1 = require('./helpers'), count = _ref1.count, starts = _ref1.starts, compact = _ref1.compact, last = _ref1.last, repeat = _ref1.repeat, invertLiterate = _ref1.invertLiterate, locationDataToString = _ref1.locationDataToString, throwSyntaxError = _ref1.throwSyntaxError;
ref1 = require('./helpers'), count = ref1.count, starts = ref1.starts, compact = ref1.compact, last = ref1.last, repeat = ref1.repeat, invertLiterate = ref1.invertLiterate, locationDataToString = ref1.locationDataToString, throwSyntaxError = ref1.throwSyntaxError;
exports.Lexer = Lexer = (function() {
function Lexer() {}
Lexer.prototype.tokenize = function(code, opts) {
var consumed, end, i, _ref2;
var consumed, end, i, ref2;
if (opts == null) {
opts = {};
}
@@ -29,7 +29,7 @@
i = 0;
while (this.chunk = code.slice(i)) {
consumed = this.identifierToken() || this.commentToken() || this.whitespaceToken() || this.lineToken() || this.stringToken() || this.numberToken() || this.regexToken() || this.jsToken() || this.literalToken();
_ref2 = this.getLineAndColumnFromChunk(consumed), this.chunkLine = _ref2[0], this.chunkColumn = _ref2[1];
ref2 = this.getLineAndColumnFromChunk(consumed), this.chunkLine = ref2[0], this.chunkColumn = ref2[1];
i += consumed;
if (opts.untilBalanced && this.ends.length === 0) {
return {
@@ -64,7 +64,7 @@
};
Lexer.prototype.identifierToken = function() {
var colon, colonOffset, forcedIdentifier, id, idLength, input, match, poppedToken, prev, tag, tagToken, _ref2, _ref3, _ref4;
var colon, colonOffset, forcedIdentifier, id, idLength, input, match, poppedToken, prev, ref2, ref3, ref4, tag, tagToken;
if (!(match = IDENTIFIER.exec(this.chunk))) {
return 0;
}
@@ -79,19 +79,19 @@
this.token('FROM', id);
return id.length;
}
forcedIdentifier = colon || (prev = last(this.tokens)) && (((_ref2 = prev[0]) === '.' || _ref2 === '?.' || _ref2 === '::' || _ref2 === '?::') || !prev.spaced && prev[0] === '@');
forcedIdentifier = colon || (prev = last(this.tokens)) && (((ref2 = prev[0]) === '.' || ref2 === '?.' || ref2 === '::' || ref2 === '?::') || !prev.spaced && prev[0] === '@');
tag = 'IDENTIFIER';
if (!forcedIdentifier && (_indexOf.call(JS_KEYWORDS, id) >= 0 || _indexOf.call(COFFEE_KEYWORDS, id) >= 0)) {
if (!forcedIdentifier && (indexOf.call(JS_KEYWORDS, id) >= 0 || indexOf.call(COFFEE_KEYWORDS, id) >= 0)) {
tag = id.toUpperCase();
if (tag === 'WHEN' && (_ref3 = this.tag(), _indexOf.call(LINE_BREAK, _ref3) >= 0)) {
if (tag === 'WHEN' && (ref3 = this.tag(), indexOf.call(LINE_BREAK, ref3) >= 0)) {
tag = 'LEADING_WHEN';
} else if (tag === 'FOR') {
this.seenFor = true;
} else if (tag === 'UNLESS') {
tag = 'IF';
} else if (_indexOf.call(UNARY, tag) >= 0) {
} else if (indexOf.call(UNARY, tag) >= 0) {
tag = 'UNARY';
} else if (_indexOf.call(RELATION, tag) >= 0) {
} else if (indexOf.call(RELATION, tag) >= 0) {
if (tag !== 'INSTANCEOF' && this.seenFor) {
tag = 'FOR' + tag;
this.seenFor = false;
@@ -104,17 +104,17 @@
}
}
}
if (_indexOf.call(JS_FORBIDDEN, id) >= 0) {
if (indexOf.call(JS_FORBIDDEN, id) >= 0) {
if (forcedIdentifier) {
tag = 'IDENTIFIER';
id = new String(id);
id.reserved = true;
} else if (_indexOf.call(RESERVED, id) >= 0) {
} else if (indexOf.call(RESERVED, id) >= 0) {
this.error("reserved word \"" + id + "\"");
}
}
if (!forcedIdentifier) {
if (_indexOf.call(COFFEE_ALIASES, id) >= 0) {
if (indexOf.call(COFFEE_ALIASES, id) >= 0) {
id = COFFEE_ALIAS_MAP[id];
}
tag = (function() {
@@ -141,7 +141,7 @@
tagToken = this.token(tag, id, 0, idLength);
tagToken.variable = !forcedIdentifier;
if (poppedToken) {
_ref4 = [poppedToken[2].first_line, poppedToken[2].first_column], tagToken[2].first_line = _ref4[0], tagToken[2].first_column = _ref4[1];
ref4 = [poppedToken[2].first_line, poppedToken[2].first_column], tagToken[2].first_line = ref4[0], tagToken[2].first_column = ref4[1];
}
if (colon) {
colonOffset = input.lastIndexOf(':');
@@ -177,7 +177,7 @@
};
Lexer.prototype.stringToken = function() {
var $, attempt, doc, end, heredoc, i, indent, indentRegex, match, quote, regex, start, token, tokens, _ref2, _ref3;
var $, attempt, doc, end, heredoc, i, indent, indentRegex, match, quote, ref2, ref3, regex, start, token, tokens;
quote = (STRING_START.exec(this.chunk) || [])[0];
if (!quote) {
return 0;
@@ -196,24 +196,24 @@
})();
heredoc = quote.length === 3;
start = quote.length;
_ref2 = this.matchWithInterpolations(this.chunk.slice(start), regex, quote, start), tokens = _ref2.tokens, end = _ref2.index;
ref2 = this.matchWithInterpolations(this.chunk.slice(start), regex, quote, start), tokens = ref2.tokens, end = ref2.index;
$ = tokens.length - 1;
if (heredoc) {
indent = null;
doc = ((function() {
var _i, _len, _results;
_results = [];
for (i = _i = 0, _len = tokens.length; _i < _len; i = ++_i) {
var j, len, results;
results = [];
for (i = j = 0, len = tokens.length; j < len; i = ++j) {
token = tokens[i];
if (token[0] === 'NEOSTRING') {
_results.push(token[1]);
results.push(token[1]);
}
}
return _results;
return results;
})()).join('#{}');
while (match = HEREDOC_INDENT.exec(doc)) {
attempt = match[1];
if (indent === null || (0 < (_ref3 = attempt.length) && _ref3 < indent.length)) {
if (indent === null || (0 < (ref3 = attempt.length) && ref3 < indent.length)) {
indent = attempt;
}
}
@@ -288,24 +288,24 @@
};
Lexer.prototype.regexToken = function() {
var closed, end, flags, index, match, prev, re, regex, rparen, tokens, _ref2, _ref3, _ref4;
var closed, end, flags, index, match, prev, re, ref2, ref3, ref4, regex, rparen, tokens;
switch (false) {
case !(match = REGEX_ILLEGAL.exec(this.chunk)):
this.error("regular expressions cannot begin with " + match[2], match.index + match[1].length);
break;
case this.chunk.slice(0, 3) !== '///':
_ref2 = this.matchWithInterpolations(this.chunk.slice(3), HEREGEX, '///', 3), tokens = _ref2.tokens, index = _ref2.index;
ref2 = this.matchWithInterpolations(this.chunk.slice(3), HEREGEX, '///', 3), tokens = ref2.tokens, index = ref2.index;
break;
case !(match = REGEX.exec(this.chunk)):
regex = match[0], closed = match[1];
index = regex.length;
prev = last(this.tokens);
if (prev) {
if (prev.spaced && (_ref3 = prev[0], _indexOf.call(CALLABLE, _ref3) >= 0) && !prev.stringEnd && !prev.regexEnd) {
if (prev.spaced && (ref3 = prev[0], indexOf.call(CALLABLE, ref3) >= 0) && !prev.stringEnd && !prev.regexEnd) {
if (!closed || POSSIBLY_DIVISION.test(regex)) {
return 0;
}
} else if (_ref4 = prev[0], _indexOf.call(NOT_REGEX, _ref4) >= 0) {
} else if (ref4 = prev[0], indexOf.call(NOT_REGEX, ref4) >= 0) {
return 0;
}
}
@@ -396,7 +396,7 @@
};
Lexer.prototype.outdentToken = function(moveOut, noNewlines, outdentLength) {
var decreasedIndent, dent, lastIndent, _ref2;
var decreasedIndent, dent, lastIndent, ref2;
decreasedIndent = this.indent - moveOut;
while (moveOut > 0) {
lastIndent = this.indents[this.indents.length - 1];
@@ -410,7 +410,7 @@
moveOut -= lastIndent;
} else {
dent = this.indents.pop() + this.outdebt;
if (outdentLength && (_ref2 = this.chunk[outdentLength], _indexOf.call(INDENTABLE_CLOSERS, _ref2) >= 0)) {
if (outdentLength && (ref2 = this.chunk[outdentLength], indexOf.call(INDENTABLE_CLOSERS, ref2) >= 0)) {
decreasedIndent -= dent - moveOut;
moveOut = dent;
}
@@ -467,7 +467,7 @@
};
Lexer.prototype.literalToken = function() {
var match, prev, tag, token, value, _ref2, _ref3, _ref4, _ref5;
var match, prev, ref2, ref3, ref4, ref5, tag, token, value;
if (match = OPERATOR.exec(this.chunk)) {
value = match[0];
if (CODE.test(value)) {
@@ -479,10 +479,10 @@
tag = value;
prev = last(this.tokens);
if (value === '=' && prev) {
if (!prev[1].reserved && (_ref2 = prev[1], _indexOf.call(JS_FORBIDDEN, _ref2) >= 0)) {
if (!prev[1].reserved && (ref2 = prev[1], indexOf.call(JS_FORBIDDEN, ref2) >= 0)) {
this.error("reserved word \"" + (this.value()) + "\" can't be assigned");
}
if ((_ref3 = prev[1]) === '||' || _ref3 === '&&') {
if ((ref3 = prev[1]) === '||' || ref3 === '&&') {
prev[0] = 'COMPOUND_ASSIGN';
prev[1] += '=';
return value.length;
@@ -491,27 +491,27 @@
if (value === ';') {
this.seenFor = false;
tag = 'TERMINATOR';
} else if (_indexOf.call(MATH, value) >= 0) {
} else if (indexOf.call(MATH, value) >= 0) {
tag = 'MATH';
} else if (_indexOf.call(COMPARE, value) >= 0) {
} else if (indexOf.call(COMPARE, value) >= 0) {
tag = 'COMPARE';
} else if (_indexOf.call(COMPOUND_ASSIGN, value) >= 0) {
} else if (indexOf.call(COMPOUND_ASSIGN, value) >= 0) {
tag = 'COMPOUND_ASSIGN';
} else if (_indexOf.call(UNARY, value) >= 0) {
} else if (indexOf.call(UNARY, value) >= 0) {
tag = 'UNARY';
} else if (_indexOf.call(UNARY_MATH, value) >= 0) {
} else if (indexOf.call(UNARY_MATH, value) >= 0) {
tag = 'UNARY_MATH';
} else if (_indexOf.call(SHIFT, value) >= 0) {
} else if (indexOf.call(SHIFT, value) >= 0) {
tag = 'SHIFT';
} else if (_indexOf.call(LOGIC, value) >= 0 || value === '?' && (prev != null ? prev.spaced : void 0)) {
} else if (indexOf.call(LOGIC, value) >= 0 || value === '?' && (prev != null ? prev.spaced : void 0)) {
tag = 'LOGIC';
} else if (prev && !prev.spaced) {
if (value === '(' && (_ref4 = prev[0], _indexOf.call(CALLABLE, _ref4) >= 0) && !prev.stringEnd && !prev.regexEnd) {
if (value === '(' && (ref4 = prev[0], indexOf.call(CALLABLE, ref4) >= 0) && !prev.stringEnd && !prev.regexEnd) {
if (prev[0] === '?') {
prev[0] = 'FUNC_EXIST';
}
tag = 'CALL_START';
} else if (value === '[' && (_ref5 = prev[0], _indexOf.call(INDEXABLE, _ref5) >= 0)) {
} else if (value === '[' && (ref5 = prev[0], indexOf.call(INDEXABLE, ref5) >= 0)) {
tag = 'INDEX_START';
switch (prev[0]) {
case '?':
@@ -572,7 +572,7 @@
};
Lexer.prototype.matchWithInterpolations = function(str, regex, end, offsetInChunk) {
var close, column, index, line, nested, open, strPart, tokens, _ref2, _ref3, _ref4;
var close, column, index, line, nested, open, ref2, ref3, ref4, strPart, tokens;
tokens = [];
while (true) {
strPart = regex.exec(str)[0];
@@ -582,18 +582,18 @@
if (str.slice(0, 2) !== '#{') {
break;
}
_ref2 = this.getLineAndColumnFromChunk(offsetInChunk + 1), line = _ref2[0], column = _ref2[1];
_ref3 = new Lexer().tokenize(str.slice(1), {
ref2 = this.getLineAndColumnFromChunk(offsetInChunk + 1), line = ref2[0], column = ref2[1];
ref3 = new Lexer().tokenize(str.slice(1), {
line: line,
column: column,
untilBalanced: true
}), nested = _ref3.tokens, index = _ref3.index;
}), nested = ref3.tokens, index = ref3.index;
index += 1;
open = nested[0], close = nested[nested.length - 1];
open[0] = open[1] = '(';
close[0] = close[1] = ')';
close.origin = ['', 'end of interpolation', close[2]];
if (((_ref4 = nested[1]) != null ? _ref4[0] : void 0) === 'TERMINATOR') {
if (((ref4 = nested[1]) != null ? ref4[0] : void 0) === 'TERMINATOR') {
nested.splice(1, 1);
}
tokens.push(['TOKENS', nested]);
@@ -609,15 +609,15 @@
};
};
Lexer.prototype.mergeInterpolationTokens = function(tokens, _arg, fn) {
var converted, end, errorToken, firstEmptyStringIndex, firstIndex, i, interpolated, locationToken, plusToken, quote, rparen, start, tag, token, tokensToPush, value, _i, _len, _ref2;
quote = _arg.quote, start = _arg.start, end = _arg.end;
Lexer.prototype.mergeInterpolationTokens = function(tokens, arg, fn) {
var converted, end, errorToken, firstEmptyStringIndex, firstIndex, i, interpolated, j, len, locationToken, plusToken, quote, ref2, rparen, start, tag, token, tokensToPush, value;
quote = arg.quote, start = arg.start, end = arg.end;
if (interpolated = tokens.length > 1) {
errorToken = this.makeToken('', 'interpolation', start + tokens[0][1].length, 2);
this.token('(', '(', 0, 0, errorToken);
}
firstIndex = this.tokens.length;
for (i = _i = 0, _len = tokens.length; _i < _len; i = ++_i) {
for (i = j = 0, len = tokens.length; j < len; i = ++j) {
token = tokens[i];
tag = token[0], value = token[1];
switch (tag) {
@@ -654,7 +654,7 @@
last_column: locationToken[2].first_column
};
}
(_ref2 = this.tokens).push.apply(_ref2, tokensToPush);
(ref2 = this.tokens).push.apply(ref2, tokensToPush);
}
if (interpolated) {
rparen = this.token(')', ')', end, 0);
@@ -663,8 +663,8 @@
};
Lexer.prototype.pair = function(tag) {
var wanted, _ref2;
if (tag !== (wanted = (_ref2 = last(this.ends)) != null ? _ref2.tag : void 0)) {
var ref2, wanted;
if (tag !== (wanted = (ref2 = last(this.ends)) != null ? ref2.tag : void 0)) {
if ('OUTDENT' !== wanted) {
this.error("unmatched " + tag);
}
@@ -696,7 +696,7 @@
};
Lexer.prototype.makeToken = function(tag, value, offsetInChunk, length) {
var lastCharacter, locationData, token, _ref2, _ref3;
var lastCharacter, locationData, ref2, ref3, token;
if (offsetInChunk == null) {
offsetInChunk = 0;
}
@@ -704,9 +704,9 @@
length = value.length;
}
locationData = {};
_ref2 = this.getLineAndColumnFromChunk(offsetInChunk), locationData.first_line = _ref2[0], locationData.first_column = _ref2[1];
ref2 = this.getLineAndColumnFromChunk(offsetInChunk), locationData.first_line = ref2[0], locationData.first_column = ref2[1];
lastCharacter = Math.max(0, length - 1);
_ref3 = this.getLineAndColumnFromChunk(offsetInChunk + lastCharacter), locationData.last_line = _ref3[0], locationData.last_column = _ref3[1];
ref3 = this.getLineAndColumnFromChunk(offsetInChunk + lastCharacter), locationData.last_line = ref3[0], locationData.last_column = ref3[1];
token = [tag, value, locationData];
return token;
};
@@ -732,8 +732,8 @@
};
Lexer.prototype.unfinished = function() {
var _ref2;
return LINE_CONTINUER.test(this.chunk) || ((_ref2 = this.tag()) === '\\' || _ref2 === '.' || _ref2 === '?.' || _ref2 === '?::' || _ref2 === 'UNARY' || _ref2 === 'MATH' || _ref2 === 'UNARY_MATH' || _ref2 === '+' || _ref2 === '-' || _ref2 === 'YIELD' || _ref2 === '**' || _ref2 === 'SHIFT' || _ref2 === 'RELATION' || _ref2 === 'COMPARE' || _ref2 === 'LOGIC' || _ref2 === 'THROW' || _ref2 === 'EXTENDS');
var ref2;
return LINE_CONTINUER.test(this.chunk) || ((ref2 = this.tag()) === '\\' || ref2 === '.' || ref2 === '?.' || ref2 === '?::' || ref2 === 'UNARY' || ref2 === 'MATH' || ref2 === 'UNARY_MATH' || ref2 === '+' || ref2 === '-' || ref2 === 'YIELD' || ref2 === '**' || ref2 === 'SHIFT' || ref2 === 'RELATION' || ref2 === 'COMPARE' || ref2 === 'LOGIC' || ref2 === 'THROW' || ref2 === 'EXTENDS');
};
Lexer.prototype.formatString = function(str) {
@@ -770,11 +770,11 @@
};
Lexer.prototype.error = function(message, offset) {
var first_column, first_line, _ref2;
var first_column, first_line, ref2;
if (offset == null) {
offset = 0;
}
_ref2 = this.getLineAndColumnFromChunk(offset), first_line = _ref2[0], first_column = _ref2[1];
ref2 = this.getLineAndColumnFromChunk(offset), first_line = ref2[0], first_column = ref2[1];
return throwSyntaxError(message, {
first_line: first_line,
first_column: first_column
@@ -802,12 +802,12 @@
};
COFFEE_ALIASES = (function() {
var _results;
_results = [];
var results;
results = [];
for (key in COFFEE_ALIAS_MAP) {
_results.push(key);
results.push(key);
}
return _results;
return results;
})();
COFFEE_KEYWORDS = COFFEE_KEYWORDS.concat(COFFEE_ALIASES);

File diff suppressed because it is too large Load Diff

View File

@@ -5,20 +5,20 @@
repeat = require('./helpers').repeat;
exports.OptionParser = OptionParser = (function() {
function OptionParser(rules, _banner) {
this.banner = _banner;
function OptionParser(rules, banner) {
this.banner = banner;
this.rules = buildRules(rules);
}
OptionParser.prototype.parse = function(args) {
var arg, i, isOption, matchedRule, options, originalArgs, pos, rule, seenNonOptionArg, skippingArgument, value, _i, _j, _len, _len1, _ref;
var arg, i, isOption, j, k, len, len1, matchedRule, options, originalArgs, pos, ref, rule, seenNonOptionArg, skippingArgument, value;
options = {
"arguments": []
};
skippingArgument = false;
originalArgs = args;
args = normalizeArguments(args);
for (i = _i = 0, _len = args.length; _i < _len; i = ++_i) {
for (i = j = 0, len = args.length; j < len; i = ++j) {
arg = args[i];
if (skippingArgument) {
skippingArgument = false;
@@ -33,9 +33,9 @@
seenNonOptionArg = options["arguments"].length > 0;
if (!seenNonOptionArg) {
matchedRule = false;
_ref = this.rules;
for (_j = 0, _len1 = _ref.length; _j < _len1; _j++) {
rule = _ref[_j];
ref = this.rules;
for (k = 0, len1 = ref.length; k < len1; k++) {
rule = ref[k];
if (rule.shortFlag === arg || rule.longFlag === arg) {
value = true;
if (rule.hasArgument) {
@@ -59,14 +59,14 @@
};
OptionParser.prototype.help = function() {
var letPart, lines, rule, spaces, _i, _len, _ref;
var j, len, letPart, lines, ref, rule, spaces;
lines = [];
if (this.banner) {
lines.unshift(this.banner + "\n");
}
_ref = this.rules;
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
rule = _ref[_i];
ref = this.rules;
for (j = 0, len = ref.length; j < len; j++) {
rule = ref[j];
spaces = 15 - rule.longFlag.length;
spaces = spaces > 0 ? repeat(' ', spaces) : '';
letPart = rule.shortFlag ? rule.shortFlag + ', ' : ' ';
@@ -88,16 +88,16 @@
OPTIONAL = /\[(\w+(\*?))\]/;
buildRules = function(rules) {
var tuple, _i, _len, _results;
_results = [];
for (_i = 0, _len = rules.length; _i < _len; _i++) {
tuple = rules[_i];
var j, len, results, tuple;
results = [];
for (j = 0, len = rules.length; j < len; j++) {
tuple = rules[j];
if (tuple.length < 3) {
tuple.unshift(null);
}
_results.push(buildRule.apply(null, tuple));
results.push(buildRule.apply(null, tuple));
}
return _results;
return results;
};
buildRule = function(shortFlag, longFlag, description, options) {
@@ -118,15 +118,15 @@
};
normalizeArguments = function(args) {
var arg, l, match, result, _i, _j, _len, _len1, _ref;
var arg, j, k, l, len, len1, match, ref, result;
args = args.slice(0);
result = [];
for (_i = 0, _len = args.length; _i < _len; _i++) {
arg = args[_i];
for (j = 0, len = args.length; j < len; j++) {
arg = args[j];
if (match = arg.match(MULTI_FLAG)) {
_ref = match[1].split('');
for (_j = 0, _len1 = _ref.length; _j < _len1; _j++) {
l = _ref[_j];
ref = match[1].split('');
for (k = 0, len1 = ref.length; k < len1; k++) {
l = ref[k];
result.push('-' + l);
}
} else {

View File

@@ -1,6 +1,6 @@
// Generated by CoffeeScript 1.9.0
(function() {
var CoffeeScript, Module, binary, child_process, ext, findExtension, fork, helpers, loadFile, path, _i, _len, _ref;
var CoffeeScript, Module, binary, child_process, ext, findExtension, fork, helpers, i, len, loadFile, path, ref;
CoffeeScript = require('./coffee-script');
@@ -17,9 +17,9 @@
};
if (require.extensions) {
_ref = CoffeeScript.FILE_EXTENSIONS;
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
ext = _ref[_i];
ref = CoffeeScript.FILE_EXTENSIONS;
for (i = 0, len = ref.length; i < len; i++) {
ext = ref[i];
require.extensions[ext] = loadFile;
}
Module = require('module');

View File

@@ -1,6 +1,6 @@
// Generated by CoffeeScript 1.9.0
(function() {
var CoffeeScript, addHistory, addMultilineHandler, fs, getCommandId, merge, nodeREPL, path, replDefaults, updateSyntaxError, vm, _ref;
var CoffeeScript, addHistory, addMultilineHandler, fs, getCommandId, merge, nodeREPL, path, ref, replDefaults, updateSyntaxError, vm;
fs = require('fs');
@@ -12,29 +12,29 @@
CoffeeScript = require('./coffee-script');
_ref = require('./helpers'), merge = _ref.merge, updateSyntaxError = _ref.updateSyntaxError;
ref = require('./helpers'), merge = ref.merge, updateSyntaxError = ref.updateSyntaxError;
replDefaults = {
prompt: 'coffee> ',
historyFile: process.env.HOME ? path.join(process.env.HOME, '.coffee_history') : void 0,
historyMaxInputSize: 10240,
"eval": function(input, context, filename, cb) {
var Assign, Block, Literal, Value, ast, err, js, referencedVars, result, token, tokens, _ref1;
var Assign, Block, Literal, Value, ast, err, js, ref1, referencedVars, result, token, tokens;
input = input.replace(/\uFF00/g, '\n');
input = input.replace(/^\(([\s\S]*)\n\)$/m, '$1');
_ref1 = require('./nodes'), Block = _ref1.Block, Assign = _ref1.Assign, Value = _ref1.Value, Literal = _ref1.Literal;
ref1 = require('./nodes'), Block = ref1.Block, Assign = ref1.Assign, Value = ref1.Value, Literal = ref1.Literal;
try {
tokens = CoffeeScript.tokens(input);
referencedVars = (function() {
var _i, _len, _results;
_results = [];
for (_i = 0, _len = tokens.length; _i < _len; _i++) {
token = tokens[_i];
if (token.variable && token[1].charAt(0) === '_') {
_results.push(token[1]);
var i, len, results;
results = [];
for (i = 0, len = tokens.length; i < len; i++) {
token = tokens[i];
if (token.variable) {
results.push(token[1]);
}
}
return _results;
return results;
})();
ast = CoffeeScript.nodes(tokens);
ast = new Block([new Assign(new Value(new Literal('_')), ast, '=')]);
@@ -54,9 +54,9 @@
};
addMultilineHandler = function(repl) {
var inputStream, multiline, nodeLineListener, origPrompt, outputStream, rli, _ref1;
var inputStream, multiline, nodeLineListener, origPrompt, outputStream, ref1, rli;
rli = repl.rli, inputStream = repl.inputStream, outputStream = repl.outputStream;
origPrompt = (_ref1 = repl._prompt) != null ? _ref1 : repl.prompt;
origPrompt = (ref1 = repl._prompt) != null ? ref1 : repl.prompt;
multiline = {
enabled: false,
initialPrompt: origPrompt.replace(/^[^> ]*/, function(x) {
@@ -159,13 +159,13 @@
module.exports = {
start: function(opts) {
var build, major, minor, repl, _ref1;
var build, major, minor, ref1, repl;
if (opts == null) {
opts = {};
}
_ref1 = process.versions.node.split('.').map(function(n) {
ref1 = process.versions.node.split('.').map(function(n) {
return parseInt(n);
}), major = _ref1[0], minor = _ref1[1], build = _ref1[2];
}), major = ref1[0], minor = ref1[1], build = ref1[2];
if (major === 0 && minor < 8) {
console.warn("Node 0.8.0+ required for CoffeeScript REPL");
process.exit(1);

View File

@@ -1,8 +1,8 @@
// Generated by CoffeeScript 1.9.0
(function() {
var BALANCED_PAIRS, CALL_CLOSERS, EXPRESSION_CLOSE, EXPRESSION_END, EXPRESSION_START, IMPLICIT_CALL, IMPLICIT_END, IMPLICIT_FUNC, IMPLICIT_UNSPACED_CALL, INVERSES, LINEBREAKS, SINGLE_CLOSERS, SINGLE_LINERS, generate, left, rite, _i, _len, _ref,
_indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; },
_slice = [].slice;
var BALANCED_PAIRS, CALL_CLOSERS, EXPRESSION_CLOSE, EXPRESSION_END, EXPRESSION_START, IMPLICIT_CALL, IMPLICIT_END, IMPLICIT_FUNC, IMPLICIT_UNSPACED_CALL, INVERSES, LINEBREAKS, SINGLE_CLOSERS, SINGLE_LINERS, generate, k, left, len, ref, rite,
indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; },
slice = [].slice;
generate = function(tag, value, origin) {
var tok;
@@ -17,8 +17,8 @@
exports.Rewriter = (function() {
function Rewriter() {}
Rewriter.prototype.rewrite = function(_tokens) {
this.tokens = _tokens;
Rewriter.prototype.rewrite = function(tokens1) {
this.tokens = tokens1;
this.removeLeadingNewlines();
this.closeOpenCalls();
this.closeOpenIndexes();
@@ -40,7 +40,7 @@
};
Rewriter.prototype.detectEnd = function(i, condition, action) {
var levels, token, tokens, _ref, _ref1;
var levels, ref, ref1, token, tokens;
tokens = this.tokens;
levels = 0;
while (token = tokens[i]) {
@@ -50,9 +50,9 @@
if (!token || levels < 0) {
return action.call(this, token, i - 1);
}
if (_ref = token[0], _indexOf.call(EXPRESSION_START, _ref) >= 0) {
if (ref = token[0], indexOf.call(EXPRESSION_START, ref) >= 0) {
levels += 1;
} else if (_ref1 = token[0], _indexOf.call(EXPRESSION_END, _ref1) >= 0) {
} else if (ref1 = token[0], indexOf.call(EXPRESSION_END, ref1) >= 0) {
levels -= 1;
}
i += 1;
@@ -61,10 +61,10 @@
};
Rewriter.prototype.removeLeadingNewlines = function() {
var i, tag, _i, _len, _ref;
_ref = this.tokens;
for (i = _i = 0, _len = _ref.length; _i < _len; i = ++_i) {
tag = _ref[i][0];
var i, k, len, ref, tag;
ref = this.tokens;
for (i = k = 0, len = ref.length; k < len; i = ++k) {
tag = ref[i][0];
if (tag !== 'TERMINATOR') {
break;
}
@@ -77,8 +77,8 @@
Rewriter.prototype.closeOpenCalls = function() {
var action, condition;
condition = function(token, i) {
var _ref;
return ((_ref = token[0]) === ')' || _ref === 'CALL_END') || token[0] === 'OUTDENT' && this.tag(i - 1) === ')';
var ref;
return ((ref = token[0]) === ')' || ref === 'CALL_END') || token[0] === 'OUTDENT' && this.tag(i - 1) === ')';
};
action = function(token, i) {
return this.tokens[token[0] === 'OUTDENT' ? i - 1 : i][0] = 'CALL_END';
@@ -94,8 +94,8 @@
Rewriter.prototype.closeOpenIndexes = function() {
var action, condition;
condition = function(token, i) {
var _ref;
return (_ref = token[0]) === ']' || _ref === 'INDEX_END';
var ref;
return (ref = token[0]) === ']' || ref === 'INDEX_END';
};
action = function(token, i) {
return token[0] = 'INDEX_END';
@@ -109,10 +109,10 @@
};
Rewriter.prototype.matchTags = function() {
var fuzz, i, j, pattern, _i, _ref, _ref1;
i = arguments[0], pattern = 2 <= arguments.length ? _slice.call(arguments, 1) : [];
var fuzz, i, j, k, pattern, ref, ref1;
i = arguments[0], pattern = 2 <= arguments.length ? slice.call(arguments, 1) : [];
fuzz = 0;
for (j = _i = 0, _ref = pattern.length; 0 <= _ref ? _i < _ref : _i > _ref; j = 0 <= _ref ? ++_i : --_i) {
for (j = k = 0, ref = pattern.length; 0 <= ref ? k < ref : k > ref; j = 0 <= ref ? ++k : --k) {
while (this.tag(i + j + fuzz) === 'HERECOMMENT') {
fuzz += 2;
}
@@ -122,7 +122,7 @@
if (typeof pattern[j] === 'string') {
pattern[j] = [pattern[j]];
}
if (_ref1 = this.tag(i + j + fuzz), _indexOf.call(pattern[j], _ref1) < 0) {
if (ref1 = this.tag(i + j + fuzz), indexOf.call(pattern[j], ref1) < 0) {
return false;
}
}
@@ -134,25 +134,25 @@
};
Rewriter.prototype.findTagsBackwards = function(i, tags) {
var backStack, _ref, _ref1, _ref2, _ref3, _ref4, _ref5;
var backStack, ref, ref1, ref2, ref3, ref4, ref5;
backStack = [];
while (i >= 0 && (backStack.length || (_ref2 = this.tag(i), _indexOf.call(tags, _ref2) < 0) && ((_ref3 = this.tag(i), _indexOf.call(EXPRESSION_START, _ref3) < 0) || this.tokens[i].generated) && (_ref4 = this.tag(i), _indexOf.call(LINEBREAKS, _ref4) < 0))) {
if (_ref = this.tag(i), _indexOf.call(EXPRESSION_END, _ref) >= 0) {
while (i >= 0 && (backStack.length || (ref2 = this.tag(i), indexOf.call(tags, ref2) < 0) && ((ref3 = this.tag(i), indexOf.call(EXPRESSION_START, ref3) < 0) || this.tokens[i].generated) && (ref4 = this.tag(i), indexOf.call(LINEBREAKS, ref4) < 0))) {
if (ref = this.tag(i), indexOf.call(EXPRESSION_END, ref) >= 0) {
backStack.push(this.tag(i));
}
if ((_ref1 = this.tag(i), _indexOf.call(EXPRESSION_START, _ref1) >= 0) && backStack.length) {
if ((ref1 = this.tag(i), indexOf.call(EXPRESSION_START, ref1) >= 0) && backStack.length) {
backStack.pop();
}
i -= 1;
}
return _ref5 = this.tag(i), _indexOf.call(tags, _ref5) >= 0;
return ref5 = this.tag(i), indexOf.call(tags, ref5) >= 0;
};
Rewriter.prototype.addImplicitBracesAndParens = function() {
var stack;
stack = [];
return this.scanTokens(function(token, i, tokens) {
var endImplicitCall, endImplicitObject, forward, inImplicit, inImplicitCall, inImplicitControl, inImplicitObject, newLine, nextTag, offset, prevTag, prevToken, s, sameLine, stackIdx, stackTag, stackTop, startIdx, startImplicitCall, startImplicitObject, startsLine, tag, _ref, _ref1, _ref2, _ref3, _ref4, _ref5;
var endImplicitCall, endImplicitObject, forward, inImplicit, inImplicitCall, inImplicitControl, inImplicitObject, newLine, nextTag, offset, prevTag, prevToken, ref, ref1, ref2, ref3, ref4, ref5, s, sameLine, stackIdx, stackTag, stackTop, startIdx, startImplicitCall, startImplicitObject, startsLine, tag;
tag = token[0];
prevTag = (prevToken = i > 0 ? tokens[i - 1] : [])[0];
nextTag = (i < tokens.length - 1 ? tokens[i + 1] : [])[0];
@@ -164,20 +164,20 @@
return i - startIdx + n;
};
inImplicit = function() {
var _ref, _ref1;
return (_ref = stackTop()) != null ? (_ref1 = _ref[2]) != null ? _ref1.ours : void 0 : void 0;
var ref, ref1;
return (ref = stackTop()) != null ? (ref1 = ref[2]) != null ? ref1.ours : void 0 : void 0;
};
inImplicitCall = function() {
var _ref;
return inImplicit() && ((_ref = stackTop()) != null ? _ref[0] : void 0) === '(';
var ref;
return inImplicit() && ((ref = stackTop()) != null ? ref[0] : void 0) === '(';
};
inImplicitObject = function() {
var _ref;
return inImplicit() && ((_ref = stackTop()) != null ? _ref[0] : void 0) === '{';
var ref;
return inImplicit() && ((ref = stackTop()) != null ? ref[0] : void 0) === '{';
};
inImplicitControl = function() {
var _ref;
return inImplicit && ((_ref = stackTop()) != null ? _ref[0] : void 0) === 'CONTROL';
var ref;
return inImplicit && ((ref = stackTop()) != null ? ref[0] : void 0) === 'CONTROL';
};
startImplicitCall = function(j) {
var idx;
@@ -241,11 +241,11 @@
stack.push([tag, i]);
return forward(1);
}
if (_indexOf.call(EXPRESSION_START, tag) >= 0) {
if (indexOf.call(EXPRESSION_START, tag) >= 0) {
stack.push([tag, i]);
return forward(1);
}
if (_indexOf.call(EXPRESSION_END, tag) >= 0) {
if (indexOf.call(EXPRESSION_END, tag) >= 0) {
while (inImplicit()) {
if (inImplicitCall()) {
endImplicitCall();
@@ -257,14 +257,14 @@
}
stack.pop();
}
if ((_indexOf.call(IMPLICIT_FUNC, tag) >= 0 && token.spaced && !token.stringEnd && !token.regexEnd || tag === '?' && i > 0 && !tokens[i - 1].spaced) && (_indexOf.call(IMPLICIT_CALL, nextTag) >= 0 || _indexOf.call(IMPLICIT_UNSPACED_CALL, nextTag) >= 0 && !((_ref = tokens[i + 1]) != null ? _ref.spaced : void 0) && !((_ref1 = tokens[i + 1]) != null ? _ref1.newLine : void 0))) {
if ((indexOf.call(IMPLICIT_FUNC, tag) >= 0 && token.spaced && !token.stringEnd && !token.regexEnd || tag === '?' && i > 0 && !tokens[i - 1].spaced) && (indexOf.call(IMPLICIT_CALL, nextTag) >= 0 || indexOf.call(IMPLICIT_UNSPACED_CALL, nextTag) >= 0 && !((ref = tokens[i + 1]) != null ? ref.spaced : void 0) && !((ref1 = tokens[i + 1]) != null ? ref1.newLine : void 0))) {
if (tag === '?') {
tag = token[0] = 'FUNC_EXIST';
}
startImplicitCall(i + 1);
return forward(2);
}
if (_indexOf.call(IMPLICIT_FUNC, tag) >= 0 && !token.stringEnd && !token.regexEnd && this.matchTags(i + 1, 'INDENT', null, ':') && !this.findTagsBackwards(i, ['CLASS', 'EXTENDS', 'IF', 'CATCH', 'SWITCH', 'LEADING_WHEN', 'FOR', 'WHILE', 'UNTIL'])) {
if (indexOf.call(IMPLICIT_FUNC, tag) >= 0 && !token.stringEnd && !token.regexEnd && this.matchTags(i + 1, 'INDENT', null, ':') && !this.findTagsBackwards(i, ['CLASS', 'EXTENDS', 'IF', 'CATCH', 'SWITCH', 'LEADING_WHEN', 'FOR', 'WHILE', 'UNTIL'])) {
startImplicitCall(i + 1);
stack.push(['INDENT', i + 2]);
return forward(3);
@@ -279,9 +279,9 @@
s -= 2;
}
this.insideForDeclaration = nextTag === 'FOR';
startsLine = s === 0 || (_ref2 = this.tag(s - 1), _indexOf.call(LINEBREAKS, _ref2) >= 0) || tokens[s - 1].newLine;
startsLine = s === 0 || (ref2 = this.tag(s - 1), indexOf.call(LINEBREAKS, ref2) >= 0) || tokens[s - 1].newLine;
if (stackTop()) {
_ref3 = stackTop(), stackTag = _ref3[0], stackIdx = _ref3[1];
ref3 = stackTop(), stackTag = ref3[0], stackIdx = ref3[1];
if ((stackTag === '{' || stackTag === 'INDENT' && this.tag(stackIdx - 1) === '{') && (startsLine || this.tag(s - 1) === ',' || this.tag(s - 1) === '{')) {
return forward(1);
}
@@ -289,13 +289,13 @@
startImplicitObject(s, !!startsLine);
return forward(2);
}
if (inImplicitObject() && _indexOf.call(LINEBREAKS, tag) >= 0) {
if (inImplicitObject() && indexOf.call(LINEBREAKS, tag) >= 0) {
stackTop()[2].sameLine = false;
}
newLine = prevTag === 'OUTDENT' || prevToken.newLine;
if (_indexOf.call(IMPLICIT_END, tag) >= 0 || _indexOf.call(CALL_CLOSERS, tag) >= 0 && newLine) {
if (indexOf.call(IMPLICIT_END, tag) >= 0 || indexOf.call(CALL_CLOSERS, tag) >= 0 && newLine) {
while (inImplicit()) {
_ref4 = stackTop(), stackTag = _ref4[0], stackIdx = _ref4[1], (_ref5 = _ref4[2], sameLine = _ref5.sameLine, startsLine = _ref5.startsLine);
ref4 = stackTop(), stackTag = ref4[0], stackIdx = ref4[1], (ref5 = ref4[2], sameLine = ref5.sameLine, startsLine = ref5.startsLine);
if (inImplicitCall() && prevTag !== ',') {
endImplicitCall();
} else if (inImplicitObject() && !this.insideForDeclaration && sameLine && tag !== 'TERMINATOR' && prevTag !== ':' && endImplicitObject()) {
@@ -319,16 +319,16 @@
Rewriter.prototype.addLocationDataToGeneratedTokens = function() {
return this.scanTokens(function(token, i, tokens) {
var column, line, nextLocation, prevLocation, _ref, _ref1;
var column, line, nextLocation, prevLocation, ref, ref1;
if (token[2]) {
return 1;
}
if (!(token.generated || token.explicit)) {
return 1;
}
if (token[0] === '{' && (nextLocation = (_ref = tokens[i + 1]) != null ? _ref[2] : void 0)) {
if (token[0] === '{' && (nextLocation = (ref = tokens[i + 1]) != null ? ref[2] : void 0)) {
line = nextLocation.first_line, column = nextLocation.first_column;
} else if (prevLocation = (_ref1 = tokens[i - 1]) != null ? _ref1[2] : void 0) {
} else if (prevLocation = (ref1 = tokens[i - 1]) != null ? ref1[2] : void 0) {
line = prevLocation.last_line, column = prevLocation.last_column;
} else {
line = column = 0;
@@ -347,37 +347,37 @@
var action, condition, indent, outdent, starter;
starter = indent = outdent = null;
condition = function(token, i) {
var _ref, _ref1, _ref2, _ref3;
return token[1] !== ';' && (_ref = token[0], _indexOf.call(SINGLE_CLOSERS, _ref) >= 0) && !(token[0] === 'TERMINATOR' && (_ref1 = this.tag(i + 1), _indexOf.call(EXPRESSION_CLOSE, _ref1) >= 0)) && !(token[0] === 'ELSE' && starter !== 'THEN') && !(((_ref2 = token[0]) === 'CATCH' || _ref2 === 'FINALLY') && (starter === '->' || starter === '=>')) || (_ref3 = token[0], _indexOf.call(CALL_CLOSERS, _ref3) >= 0) && this.tokens[i - 1].newLine;
var ref, ref1, ref2, ref3;
return token[1] !== ';' && (ref = token[0], indexOf.call(SINGLE_CLOSERS, ref) >= 0) && !(token[0] === 'TERMINATOR' && (ref1 = this.tag(i + 1), indexOf.call(EXPRESSION_CLOSE, ref1) >= 0)) && !(token[0] === 'ELSE' && starter !== 'THEN') && !(((ref2 = token[0]) === 'CATCH' || ref2 === 'FINALLY') && (starter === '->' || starter === '=>')) || (ref3 = token[0], indexOf.call(CALL_CLOSERS, ref3) >= 0) && this.tokens[i - 1].newLine;
};
action = function(token, i) {
return this.tokens.splice((this.tag(i - 1) === ',' ? i - 1 : i), 0, outdent);
};
return this.scanTokens(function(token, i, tokens) {
var j, tag, _i, _ref, _ref1, _ref2;
var j, k, ref, ref1, ref2, tag;
tag = token[0];
if (tag === 'TERMINATOR') {
if (this.tag(i + 1) === 'ELSE' && this.tag(i - 1) !== 'OUTDENT') {
tokens.splice.apply(tokens, [i, 1].concat(_slice.call(this.indentation())));
tokens.splice.apply(tokens, [i, 1].concat(slice.call(this.indentation())));
return 1;
}
if (_ref = this.tag(i + 1), _indexOf.call(EXPRESSION_CLOSE, _ref) >= 0) {
if (ref = this.tag(i + 1), indexOf.call(EXPRESSION_CLOSE, ref) >= 0) {
tokens.splice(i, 1);
return 0;
}
}
if (tag === 'CATCH') {
for (j = _i = 1; _i <= 2; j = ++_i) {
if (!((_ref1 = this.tag(i + j)) === 'OUTDENT' || _ref1 === 'TERMINATOR' || _ref1 === 'FINALLY')) {
for (j = k = 1; k <= 2; j = ++k) {
if (!((ref1 = this.tag(i + j)) === 'OUTDENT' || ref1 === 'TERMINATOR' || ref1 === 'FINALLY')) {
continue;
}
tokens.splice.apply(tokens, [i + j, 0].concat(_slice.call(this.indentation())));
tokens.splice.apply(tokens, [i + j, 0].concat(slice.call(this.indentation())));
return 2 + j;
}
}
if (_indexOf.call(SINGLE_LINERS, tag) >= 0 && this.tag(i + 1) !== 'INDENT' && !(tag === 'ELSE' && this.tag(i + 1) === 'IF')) {
if (indexOf.call(SINGLE_LINERS, tag) >= 0 && this.tag(i + 1) !== 'INDENT' && !(tag === 'ELSE' && this.tag(i + 1) === 'IF')) {
starter = tag;
_ref2 = this.indentation(tokens[i]), indent = _ref2[0], outdent = _ref2[1];
ref2 = this.indentation(tokens[i]), indent = ref2[0], outdent = ref2[1];
if (starter === 'THEN') {
indent.fromThen = true;
}
@@ -399,7 +399,7 @@
var prevTag, tag;
tag = token[0];
prevTag = this.tokens[i - 1][0];
return tag === 'TERMINATOR' || (tag === 'INDENT' && _indexOf.call(SINGLE_LINERS, prevTag) < 0);
return tag === 'TERMINATOR' || (tag === 'INDENT' && indexOf.call(SINGLE_LINERS, prevTag) < 0);
};
action = function(token, i) {
if (token[0] !== 'INDENT' || (token.generated && !token.fromThen)) {
@@ -432,8 +432,8 @@
Rewriter.prototype.generate = generate;
Rewriter.prototype.tag = function(i) {
var _ref;
return (_ref = this.tokens[i]) != null ? _ref[0] : void 0;
var ref;
return (ref = this.tokens[i]) != null ? ref[0] : void 0;
};
return Rewriter;
@@ -448,8 +448,8 @@
EXPRESSION_END = [];
for (_i = 0, _len = BALANCED_PAIRS.length; _i < _len; _i++) {
_ref = BALANCED_PAIRS[_i], left = _ref[0], rite = _ref[1];
for (k = 0, len = BALANCED_PAIRS.length; k < len; k++) {
ref = BALANCED_PAIRS[k], left = ref[0], rite = ref[1];
EXPRESSION_START.push(INVERSES[rite] = left);
EXPRESSION_END.push(INVERSES[left] = rite);
}

View File

@@ -1,17 +1,17 @@
// Generated by CoffeeScript 1.9.0
(function() {
var Scope, extend, last, _ref,
_indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };
var Scope, extend, last, ref,
indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };
_ref = require('./helpers'), extend = _ref.extend, last = _ref.last;
ref = require('./helpers'), extend = ref.extend, last = ref.last;
exports.Scope = Scope = (function() {
function Scope(_parent, _expressions, _method, _referencedVars) {
var _ref1, _ref2;
this.parent = _parent;
this.expressions = _expressions;
this.method = _method;
this.referencedVars = _referencedVars;
function Scope(parent, expressions, method, referencedVars) {
var ref1, ref2;
this.parent = parent;
this.expressions = expressions;
this.method = method;
this.referencedVars = referencedVars;
this.variables = [
{
name: 'arguments',
@@ -22,7 +22,7 @@
if (!this.parent) {
this.utilities = {};
}
this.root = (_ref1 = (_ref2 = this.parent) != null ? _ref2.root : void 0) != null ? _ref1 : this;
this.root = (ref1 = (ref2 = this.parent) != null ? ref2.root : void 0) != null ? ref1 : this;
}
Scope.prototype.add = function(name, type, immediate) {
@@ -40,8 +40,8 @@
};
Scope.prototype.namedMethod = function() {
var _ref1;
if (((_ref1 = this.method) != null ? _ref1.name : void 0) || !this.parent) {
var ref1;
if (((ref1 = this.method) != null ? ref1.name : void 0) || !this.parent) {
return this.method;
}
return this.parent.namedMethod();
@@ -63,25 +63,26 @@
};
Scope.prototype.check = function(name) {
var _ref1;
return !!(this.type(name) || ((_ref1 = this.parent) != null ? _ref1.check(name) : void 0));
var ref1;
return !!(this.type(name) || ((ref1 = this.parent) != null ? ref1.check(name) : void 0));
};
Scope.prototype.temporary = function(name, index) {
if (name.charAt(0) === '_') {
return name + (index || '');
} else if (name.length === 1) {
return '_' + (index + parseInt(name, 36)).toString(36).replace(/\d/g, 'a');
Scope.prototype.temporary = function(name, index, single) {
if (single == null) {
single = false;
}
if (single) {
return (index + parseInt(name, 36)).toString(36).replace(/\d/g, 'a');
} else {
return "_" + name + (index || '');
return name + (index || '');
}
};
Scope.prototype.type = function(name) {
var v, _i, _len, _ref1;
_ref1 = this.variables;
for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
v = _ref1[_i];
var i, len, ref1, v;
ref1 = this.variables;
for (i = 0, len = ref1.length; i < len; i++) {
v = ref1[i];
if (v.name === name) {
return v.type;
}
@@ -89,20 +90,20 @@
return null;
};
Scope.prototype.freeVariable = function(name, reserve) {
var index, temp;
if (reserve == null) {
reserve = true;
Scope.prototype.freeVariable = function(name, options) {
var index, ref1, temp;
if (options == null) {
options = {};
}
index = 0;
while (true) {
temp = this.temporary(name, index);
if (!(this.check(temp) || _indexOf.call(this.root.referencedVars, temp) >= 0)) {
temp = this.temporary(name, index, options.single);
if (!(this.check(temp) || indexOf.call(this.root.referencedVars, temp) >= 0)) {
break;
}
index++;
}
if (reserve) {
if ((ref1 = options.reserve) != null ? ref1 : true) {
this.add(temp, 'var', true);
}
return temp;
@@ -121,30 +122,32 @@
};
Scope.prototype.declaredVariables = function() {
var realVars, tempVars, v, _i, _len, _ref1;
realVars = [];
tempVars = [];
_ref1 = this.variables;
for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
v = _ref1[_i];
if (v.type === 'var') {
(v.name.charAt(0) === '_' ? tempVars : realVars).push(v.name);
var v;
return ((function() {
var i, len, ref1, results;
ref1 = this.variables;
results = [];
for (i = 0, len = ref1.length; i < len; i++) {
v = ref1[i];
if (v.type === 'var') {
results.push(v.name);
}
}
}
return realVars.sort().concat(tempVars.sort());
return results;
}).call(this)).sort();
};
Scope.prototype.assignedVariables = function() {
var v, _i, _len, _ref1, _results;
_ref1 = this.variables;
_results = [];
for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
v = _ref1[_i];
var i, len, ref1, results, v;
ref1 = this.variables;
results = [];
for (i = 0, len = ref1.length; i < len; i++) {
v = ref1[i];
if (v.type.assigned) {
_results.push(v.name + " = " + v.type.value);
results.push(v.name + " = " + v.type.value);
}
}
return _results;
return results;
};
return Scope;

View File

@@ -3,14 +3,14 @@
var LineMap, SourceMap;
LineMap = (function() {
function LineMap(_line) {
this.line = _line;
function LineMap(line1) {
this.line = line1;
this.columns = [];
}
LineMap.prototype.add = function(column, _arg, options) {
LineMap.prototype.add = function(column, arg, options) {
var sourceColumn, sourceLine;
sourceLine = _arg[0], sourceColumn = _arg[1];
sourceLine = arg[0], sourceColumn = arg[1];
if (options == null) {
options = {};
}
@@ -45,18 +45,18 @@
}
SourceMap.prototype.add = function(sourceLocation, generatedLocation, options) {
var column, line, lineMap, _base;
var base, column, line, lineMap;
if (options == null) {
options = {};
}
line = generatedLocation[0], column = generatedLocation[1];
lineMap = ((_base = this.lines)[line] || (_base[line] = new LineMap(line)));
lineMap = ((base = this.lines)[line] || (base[line] = new LineMap(line)));
return lineMap.add(column, sourceLocation, options);
};
SourceMap.prototype.sourceLocation = function(_arg) {
SourceMap.prototype.sourceLocation = function(arg) {
var column, line, lineMap;
line = _arg[0], column = _arg[1];
line = arg[0], column = arg[1];
while (!((lineMap = this.lines[line]) || (line <= 0))) {
line--;
}
@@ -64,7 +64,7 @@
};
SourceMap.prototype.generate = function(options, code) {
var buffer, lastColumn, lastSourceColumn, lastSourceLine, lineMap, lineNumber, mapping, needComma, v3, writingline, _i, _j, _len, _len1, _ref, _ref1;
var buffer, i, j, lastColumn, lastSourceColumn, lastSourceLine, len, len1, lineMap, lineNumber, mapping, needComma, ref, ref1, v3, writingline;
if (options == null) {
options = {};
}
@@ -77,13 +77,13 @@
lastSourceColumn = 0;
needComma = false;
buffer = "";
_ref = this.lines;
for (lineNumber = _i = 0, _len = _ref.length; _i < _len; lineNumber = ++_i) {
lineMap = _ref[lineNumber];
ref = this.lines;
for (lineNumber = i = 0, len = ref.length; i < len; lineNumber = ++i) {
lineMap = ref[lineNumber];
if (lineMap) {
_ref1 = lineMap.columns;
for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) {
mapping = _ref1[_j];
ref1 = lineMap.columns;
for (j = 0, len1 = ref1.length; j < len1; j++) {
mapping = ref1[j];
if (!(mapping)) {
continue;
}

View File

@@ -47,11 +47,9 @@ exports.compile = compile = withPrettyErrors (code, options) ->
tokens = lexer.tokenize code, options
# Pass a list of referenced variables, so that generated variables won't get
# the same name. Since all generated variables start with an underscore only
# referenced variables also starting with an underscore are passed, as an
# optimization.
# the same name.
options.referencedVars = (
token[1] for token in tokens when token.variable and token[1].charAt(0) is '_'
token[1] for token in tokens when token.variable
)
fragments = parser.parse(tokens).compileToFragments options

View File

@@ -736,7 +736,7 @@ exports.Extends = class Extends extends Base
# Hooks one constructor into another's prototype chain.
compileToFragments: (o) ->
new Call(new Value(new Literal utility 'extends', o), [@child, @parent]).compileToFragments o
new Call(new Value(new Literal utility 'extend', o), [@child, @parent]).compileToFragments o
#### Access
@@ -853,7 +853,7 @@ exports.Range = class Range extends Base
range.pop() if @exclusive
return [@makeCode "[#{ range.join(', ') }]"]
idt = @tab + TAB
i = o.scope.freeVariable 'i'
i = o.scope.freeVariable 'i', single: true
result = o.scope.freeVariable 'results'
pre = "\n#{idt}#{result} = [];"
if @fromNum and @toNum
@@ -1116,7 +1116,7 @@ exports.Class = class Class extends Base
@body.expressions.push lname
if @parent
superClass = new Literal o.classScope.freeVariable 'super', no
superClass = new Literal o.classScope.freeVariable 'superClass', reserve: no
@body.expressions.unshift new Extends lname, superClass
func.params.push new Param superClass
args.push @parent
@@ -1233,7 +1233,7 @@ exports.Assign = class Assign extends Base
obj = obj.unwrap()
val = "#{olen} <= #{vvarText}.length ? #{ utility 'slice', o }.call(#{vvarText}, #{i}"
if rest = olen - i - 1
ivar = o.scope.freeVariable 'i'
ivar = o.scope.freeVariable 'i', single: true
val += ", #{ivar} = #{vvarText}.length - #{rest}) : (#{ivar} = #{i}, [])"
else
val += ") : []"
@@ -1244,7 +1244,7 @@ exports.Assign = class Assign extends Base
if rest is 1
expandedIdx = "#{vvarText}.length - 1"
else
ivar = o.scope.freeVariable 'i'
ivar = o.scope.freeVariable 'i', single: true
val = new Literal "#{ivar} = #{vvarText}.length - #{rest}"
expandedIdx = "#{ivar}++"
assigns.push val.compileToFragments o, LEVEL_LIST
@@ -1431,6 +1431,7 @@ exports.Param = class Param extends Base
node = @name
if node.this
name = node.properties[0].name.value
name = "_#{name}" if name.reserved
node = new Literal o.scope.freeVariable name
else if node.isComplex()
node = new Literal o.scope.freeVariable 'arg'
@@ -1966,7 +1967,7 @@ exports.For = class For extends While
scope.find(name) if name and not @pattern
scope.find(index) if index
rvar = scope.freeVariable 'results' if @returns
ivar = (@object and index) or scope.freeVariable 'i'
ivar = (@object and index) or scope.freeVariable 'i', single: true
kvar = (@range and name) or index or ivar
kvarAssign = if kvar isnt ivar then "#{kvar} = " else ""
if @step and not @range
@@ -2179,7 +2180,7 @@ UTILITIES =
# Correctly set up a prototype chain for inheritance, including a reference
# to the superclass for `super()` calls, and copies of any static properties.
extends: (o) -> "
extend: (o) -> "
function(child, parent) {
for (var key in parent) {
if (#{utility 'hasProp', o}.call(parent, key)) child[key] = parent[key];
@@ -2264,7 +2265,7 @@ utility = (name, o) ->
if name of root.utilities
root.utilities[name]
else
ref = root.freeVariable "_#{name}"
ref = root.freeVariable name
root.assign ref, UTILITIES[name] o
root.utilities[name] = ref

View File

@@ -24,7 +24,7 @@ replDefaults =
tokens = CoffeeScript.tokens input
# Collect referenced variable names just like in `CoffeeScript.compile`.
referencedVars = (
token[1] for token in tokens when token.variable and token[1].charAt(0) is '_'
token[1] for token in tokens when token.variable
)
# Generate the AST of the tokens.
ast = CoffeeScript.nodes tokens

View File

@@ -68,13 +68,11 @@ walks up to the root scope.
Generate a temporary variable name at the given index.
temporary: (name, index) ->
if name.charAt(0) is '_'
temporary: (name, index, single=false) ->
if single
(index + parseInt name, 36).toString(36).replace /\d/g, 'a'
else
name + (index or '')
else if name.length is 1
'_' + (index + parseInt name, 36).toString(36).replace /\d/g, 'a'
else
"_#{name}#{index or ''}"
Gets the type of a variable.
@@ -85,13 +83,13 @@ Gets the type of a variable.
If we need to store an intermediate result, find an available name for a
compiler-generated variable. `_var`, `_var2`, and so on...
freeVariable: (name, reserve=true) ->
freeVariable: (name, options={}) ->
index = 0
loop
temp = @temporary name, index
temp = @temporary name, index, options.single
break unless @check(temp) or temp in @root.referencedVars
index++
@add temp, 'var', yes if reserve
@add temp, 'var', yes if options.reserve ? true
temp
Ensure that an assignment is made at the top of this scope
@@ -109,11 +107,7 @@ Does this scope have any declared variables?
Return the list of variables first declared in this scope.
declaredVariables: ->
realVars = []
tempVars = []
for v in @variables when v.type is 'var'
(if v.name.charAt(0) is '_' then tempVars else realVars).push v.name
realVars.sort().concat tempVars.sort()
(v.name for v in @variables when v.type is 'var').sort()
Return the list of assignments that are supposed to be made at the top
of this scope.

View File

@@ -408,52 +408,52 @@ test "#2181: conditional assignment as a subexpression", ->
eq false, not a or= true
test "#1500: Assignment to variables similar to generated variables", ->
_len = 0
x = ((_results = null; i) for i in [1, 2, 3])
len = 0
x = ((results = null; n) for n in [1, 2, 3])
arrayEq [1, 2, 3], x
eq 0, _len
eq 0, len
for x in [1, 2, 3]
f = ->
_i = 0
i = 0
f()
eq 'undefined', typeof _i
eq 'undefined', typeof i
_ref = 2
x = _ref * 2 ? 1
ref = 2
x = ref * 2 ? 1
eq x, 4
eq 'undefined', typeof _ref1
eq 'undefined', typeof ref1
x = {}
_base = -> x
_name = -1
_base()[-_name] ?= 2
base = -> x
name = -1
base()[-name] ?= 2
eq x[1], 2
eq _base(), x
eq _name, -1
eq base(), x
eq name, -1
f = (@a, _at_a, a) -> [@a, _at_a, a]
arrayEq [1, 2, 3], f.call scope = {}, 1, 2, 3
f = (@a, a) -> [@a, a]
arrayEq [1, 2], f.call scope = {}, 1, 2
eq 1, scope.a
doesNotThrow -> CoffeeScript.compile '(@_slice...) ->'
doesNotThrow -> CoffeeScript.compile '(@slice...) ->'
test "Assignment to variables similar to helper functions", ->
f = (__slice...) -> __slice
f = (slice...) -> slice
arrayEq [1, 2, 3], f 1, 2, 3
eq 'undefined', typeof __slice1
eq 'undefined', typeof slice1
class A
class B extends A
__extends = 3
__hasProp = 4
extend = 3
hasProp = 4
value: 5
method: (__bind, __bind1) => [__bind, __bind1, __extends, __hasProp, @value]
method: (bind, bind1) => [bind, bind1, extend, hasProp, @value]
{method} = new B
arrayEq [1, 2, 3, 4, 5], method 1, 2
__modulo = -1 %% 3
eq 2, __modulo
modulo = -1 %% 3
eq 2, modulo
__indexOf = [1, 2, 3]
ok 2 in __indexOf
indexOf = [1, 2, 3]
ok 2 in indexOf