mirror of
https://github.com/jashkenas/coffeescript.git
synced 2026-02-17 19:11:22 -05:00
fixin up narwhal factory and adding more implicit blocks to the lexer
This commit is contained in:
@@ -20,7 +20,9 @@ checkForErrors: coffeeProcess =>
|
||||
# Run a simple REPL, round-tripping to the CoffeeScript compiler for every
|
||||
# command.
|
||||
exports.run: args =>
|
||||
return true if args.length
|
||||
if args.length
|
||||
exports.evalCS(File.read(path)) for path in args
|
||||
return true
|
||||
|
||||
while true
|
||||
try
|
||||
@@ -46,13 +48,3 @@ exports.compile: source =>
|
||||
# Evaluating a string of CoffeeScript first compiles it externally.
|
||||
exports.evalCS: source =>
|
||||
eval(exports.compile(source))
|
||||
|
||||
# Make a factory for the CoffeeScript environment.
|
||||
exports.makeNarwhalFactory: path =>
|
||||
code: exports.compileFile(path)
|
||||
factoryText: "function(require,exports,module,system,print){" + code + "/**/\n}"
|
||||
if system.engine is "rhino"
|
||||
Packages.org.mozilla.javascript.Context.getCurrentContext().compileFunction(global, factoryText, path, 0, null)
|
||||
else
|
||||
# eval requires parentheses, but parentheses break compileFunction.
|
||||
eval("(" + factoryText + ")")
|
||||
|
||||
@@ -18,8 +18,15 @@
|
||||
// Run a simple REPL, round-tripping to the CoffeeScript compiler for every
|
||||
// command.
|
||||
exports.run = function(args) {
|
||||
var result;
|
||||
var __a, __b, __c, __d, path, result;
|
||||
if (args.length) {
|
||||
__a = args;
|
||||
__d = [];
|
||||
for (__b=0, __c=__a.length; __b<__c; __b++) {
|
||||
path = __a[__b];
|
||||
__d[__b] = exports.evalCS(File.read(path));
|
||||
}
|
||||
__d;
|
||||
return true;
|
||||
}
|
||||
while (true) {
|
||||
@@ -53,16 +60,4 @@
|
||||
exports.evalCS = function(source) {
|
||||
return eval(exports.compile(source));
|
||||
};
|
||||
// Make a factory for the CoffeeScript environment.
|
||||
exports.makeNarwhalFactory = function(path) {
|
||||
var code, factoryText;
|
||||
code = exports.compileFile(path);
|
||||
factoryText = "function(require,exports,module,system,print){" + code + "/**/\n}";
|
||||
if (system.engine === "rhino") {
|
||||
return Packages.org.mozilla.javascript.Context.getCurrentContext().compileFunction(global, factoryText, path, 0, null);
|
||||
} else {
|
||||
// eval requires parentheses, but parentheses break compileFunction.
|
||||
return eval("(" + factoryText + ")");
|
||||
}
|
||||
};
|
||||
})();
|
||||
@@ -6,13 +6,15 @@
|
||||
};
|
||||
loader = {
|
||||
// Reload the coffee-script environment from source.
|
||||
reload: function(topId, path) {
|
||||
reload: function(topId) {
|
||||
coffeescript = coffeescript || require('coffee-script');
|
||||
return (factories[topId] = coffeescript.makeNarwhalFactory(path));
|
||||
return (factories[topId] = function() {
|
||||
return coffeescript;
|
||||
});
|
||||
},
|
||||
// Ensure that the coffee-script environment is loaded.
|
||||
load: function(topId, path) {
|
||||
return factories[topId] = factories[topId] || this.reload(topId, path);
|
||||
load: function(topId) {
|
||||
return factories[topId] = factories[topId] || this.reload(topId);
|
||||
}
|
||||
};
|
||||
require.loader.loaders.unshift([".coffee", loader]);
|
||||
|
||||
@@ -6,13 +6,13 @@ factories: {}
|
||||
loader: {
|
||||
|
||||
# Reload the coffee-script environment from source.
|
||||
reload: topId, path =>
|
||||
reload: topId =>
|
||||
coffeescript ||= require('coffee-script')
|
||||
factories[topId]: coffeescript.makeNarwhalFactory(path)
|
||||
factories[topId]: => coffeescript
|
||||
|
||||
# Ensure that the coffee-script environment is loaded.
|
||||
load: topId, path =>
|
||||
factories[topId] ||= this.reload(topId, path)
|
||||
load: topId =>
|
||||
factories[topId] ||= this.reload(topId)
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user