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

Whoops, mergefail; corrected

This commit is contained in:
Trevor Burnham 2011-10-23 22:45:32 -04:00
parent cf32ba0149
commit 3f4daaf2ad
2 changed files with 25 additions and 33 deletions

View file

@ -1,5 +1,5 @@
(function() {
var ACCESSOR, CoffeeScript, Module, REPL_PROMPT, REPL_PROMPT_CONTINUATION, SIMPLEVAR, Script, autocomplete, backlog, completeAttribute, completeVariable, enableColours, error, g, getCompletions, inspect, nonContextGlobals, readline, repl, run, sandbox, stdin, stdout, _i, _len;
var ACCESSOR, CoffeeScript, Module, REPL_PROMPT, REPL_PROMPT_CONTINUATION, SIMPLEVAR, Script, autocomplete, backlog, completeAttribute, completeVariable, enableColours, error, getCompletions, inspect, readline, repl, run, stdin, stdout;
CoffeeScript = require('./coffee-script');
@ -31,17 +31,6 @@
backlog = '';
sandbox = Script.createContext();
nonContextGlobals = ['Buffer', 'console', 'process', 'setInterval', 'clearInterval', 'setTimeout', 'clearTimeout'];
for (_i = 0, _len = nonContextGlobals.length; _i < _len; _i++) {
g = nonContextGlobals[_i];
sandbox[g] = global[g];
}
sandbox.global = sandbox.root = sandbox.GLOBAL = sandbox;
run = function(buffer) {
var code, returnValue, _;
if (!buffer.toString().trim() && !backlog) {
@ -58,14 +47,13 @@
repl.setPrompt(REPL_PROMPT);
backlog = '';
try {
_ = sandbox._;
_ = global._;
returnValue = CoffeeScript.eval("_=(" + code + "\n)", {
sandbox: sandbox,
filename: 'repl',
modulename: 'repl'
});
if (returnValue === void 0) {
sandbox._ = _;
global._ = _;
} else {
process.stdout.write(inspect(returnValue, false, 2, enableColours) + '\n');
}
@ -88,7 +76,7 @@
if (match = text.match(ACCESSOR)) {
all = match[0], obj = match[1], prefix = match[2];
try {
val = Script.runInContext(obj, sandbox);
val = Script.runInThisContext(obj);
} catch (error) {
return;
}
@ -101,13 +89,13 @@
var completions, free, keywords, possibilities, r, vars, _ref;
free = (_ref = text.match(SIMPLEVAR)) != null ? _ref[1] : void 0;
if (free != null) {
vars = Script.runInContext('Object.getOwnPropertyNames(this)', sandbox);
vars = Script.runInThisContext('Object.getOwnPropertyNames(this)');
keywords = (function() {
var _j, _len2, _ref2, _results;
var _i, _len, _ref2, _results;
_ref2 = CoffeeScript.RESERVED;
_results = [];
for (_j = 0, _len2 = _ref2.length; _j < _len2; _j++) {
r = _ref2[_j];
for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
r = _ref2[_i];
if (r.slice(0, 2) !== '__') _results.push(r);
}
return _results;
@ -119,10 +107,10 @@
};
getCompletions = function(prefix, candidates) {
var el, _j, _len2, _results;
var el, _i, _len, _results;
_results = [];
for (_j = 0, _len2 = candidates.length; _j < _len2; _j++) {
el = candidates[_j];
for (_i = 0, _len = candidates.length; _i < _len; _i++) {
el = candidates[_i];
if (el.indexOf(prefix) === 0) _results.push(el);
}
return _results;