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

rebuilding narwhal uncovered a bug with named functions

This commit is contained in:
Jeremy Ashkenas 2010-01-01 22:00:34 -05:00
parent c3d0e50e8f
commit 38520bfece
4 changed files with 26 additions and 27 deletions

View file

@ -21,8 +21,9 @@ checkForErrors: coffeeProcess =>
# command.
exports.run: args =>
if args.length
exports.evalCS(File.read(path)) for path in args
delete args[i] for path, i in args
for path, i in args
exports.evalCS(File.read(path))
delete args[i]
return true
while true

View file

@ -1,14 +1,16 @@
(function(){
var File, OS, Readline, checkForErrors, coffeePath;
// This (javascript) file is generated from lib/coffee_script/narwhal/coffee-script.coffee Executes the `coffee` Ruby program to convert from CoffeeScript
// to Javascript. Eventually this will hopefully happen entirely within JS. Require external dependencies.
// This (javascript) file is generated from lib/coffee_script/narwhal/coffee-script.coffee
// Executes the `coffee` Ruby program to convert from CoffeeScript
// to Javascript. Eventually this will hopefully happen entirely within JS.
// Require external dependencies.
OS = require('os');
File = require('file');
Readline = require('readline');
// The path to the CoffeeScript Compiler.
coffeePath = File.path(module.path).dirname().dirname().dirname().dirname().dirname().join('bin', 'coffee');
// Our general-purpose error handler.
checkForErrors = function(coffeeProcess) {
checkForErrors = function checkForErrors(coffeeProcess) {
if (coffeeProcess.wait() === 0) {
return true;
}
@ -17,24 +19,20 @@
};
// Run a simple REPL, round-tripping to the CoffeeScript compiler for every
// command.
exports.run = function(args) {
var __a, __b, __c, __d, __e, __f, __g, __h, i, path, result;
exports.run = function run(args) {
var __a, __b, __c, i, 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));
__b = [];
for (i in __a) {
if (__a.hasOwnProperty(i)) {
path = __a[i];
exports.evalCS(File.read(path));
__c = delete args[i];
__b.push(__c);
}
__d;
__e = args;
__h = [];
for (__f=0, __g=__e.length; __f<__g; __f++) {
path = __e[__f];
i = __f;
__h[__f] = delete args[i];
}
__h;
__b;
return true;
}
while (true) {
@ -50,14 +48,14 @@
}
};
// Compile a given CoffeeScript file into JavaScript.
exports.compileFile = function(path) {
exports.compileFile = function compileFile(path) {
var coffee;
coffee = OS.popen([coffeePath, "--print", "--no-wrap", path]);
checkForErrors(coffee);
return coffee.stdout.read();
};
// Compile a string of CoffeeScript into JavaScript.
exports.compile = function(source) {
exports.compile = function compile(source) {
var coffee;
coffee = OS.popen([coffeePath, "--eval", "--no-wrap"]);
coffee.stdin.write(source).flush().close();
@ -65,11 +63,11 @@
return coffee.stdout.read();
};
// Evaluating a string of CoffeeScript first compiles it externally.
exports.evalCS = function(source) {
exports.evalCS = function evalCS(source) {
return eval(exports.compile(source));
};
// Make a factory for the CoffeeScript environment.
exports.makeNarwhalFactory = function(path) {
exports.makeNarwhalFactory = function makeNarwhalFactory(path) {
var code, factoryText;
code = exports.compileFile(path);
factoryText = "function(require,exports,module,system,print){" + code + "/**/\n}";

View file

@ -6,14 +6,14 @@
};
loader = {
// Reload the coffee-script environment from source.
reload: function(topId, path) {
reload: function reload(topId, path) {
coffeescript = coffeescript || require('coffee-script');
return (factories[topId] = function() {
return coffeescript.makeNarwhalFactory(path);
});
},
// Ensure that the coffee-script environment is loaded.
load: function(topId, path) {
load: function load(topId, path) {
return factories[topId] = factories[topId] || this.reload(topId, path);
}
};

View file

@ -417,7 +417,7 @@ module CoffeeScript
last = @variable.last.to_s.sub(LEADING_DOT, '')
proto = name[PROTO_ASSIGN, 1]
o = o.merge(:assign => @variable, :last_assign => last, :proto_assign => proto)
o[:immediate_assign] = last if @value.is_a?(CodeNode)
o[:immediate_assign] = last if @value.is_a?(CodeNode) && last.match(Lexer::IDENTIFIER)
return write("#{name}: #{@value.compile(o)}") if @context == :object
o[:scope].find(name) unless @variable.properties?
return write(@value.compile(o)) if @value.custom_assign?